简体   繁体   English

JAVA GIS方法表现不正常

[英]JAVA GIS method not behaving as expected

I am using a method call to transform a Point in one spatial reference to another (one coordinate plane to another basically) and the call works fine in the first example, then in the second example I am using the same method on the same object type and the method has no effect on the Point... code and an example below: (the midpoint.project(GeometryUtil.getLatLongCoordSystem)) is the method call I am having issues with) 我正在使用方法调用将一个空间参考中的Point转换为另一个空间参考(基本上是将一个坐标平面转换为另一个坐标平面),并且该调用在第一个示例中运行良好,然后在第二个示例中,我对相同的对象类型使用相同的方法并且该方法对Point ...代码和下面的示例没有影响:(midpoint.project(GeometryUtil.getLatLongCoordSystem))是我遇到问题的方法调用)

//works fine...

if (closestStationOrSpanFw != null) {
                IGeometry shape = closestStationOrSpanFw.getIFeature().getShapeCopy();
                Point point = null;
                if (shape instanceof Point) {
                    point = (Point) shape;
                    System.out.println("OLD POINT coords: " + point.getX() + "        " + point.getY());
                    point.project(GeometryUtil.getLatLongCoordSystem());
                    System.out.println("NEW POINT coords: " + point.getX() + "        " + point.getY());


//Problem code:

else if (shape instanceof Polyline){
                    Polyline line = (Polyline) shape;
                    Point lowerLeft = (Point) line.getEnvelope().getLowerLeft();
                    Point upperRight = (Point) line.getEnvelope().getUpperRight();
                    Point midpoint = GeometryUtil.getMidpoint(lowerLeft, upperRight);
                    System.out.println("OLD LINE coords: " + midpoint.getX() + "        " + midpoint.getY());
                    midpoint.project(GeometryUtil.getLatLongCoordSystem());
                    System.out.println("NEW LINE coords: " + midpoint.getX() + "        " + midpoint.getY());

output of the properly working Point System.outs: 正常工作的Point System.outs的输出:

OLD POINT coords: 1860356.9240645461        1698342.0271777364
NEW POINT coords: -87.85965314497173        34.6678477163251

output of the broken Polyline System.outs (very close to point coordinate above): 折断的Polyline System.outs的输出(非常接近上面的点坐标):

OLD LINE coords: 1860490.636483086        1698315.1646775191
NEW LINE coords: 1860490.636483086        1698315.1646775191

As you can see, this seems to work properly in the first case but not in the second. 如您所见,这在第一种情况下似乎可以正常工作,但在第二种情况下却无法正常工作。 Any ideas? 有任何想法吗?

The documentation states that "to Project, the geometry needs to have a Spatial Reference set, and not have an UnknownCoordinateSystem. The new spatial reference system passed to the method defines the output coordinate system. If either spatial reference is Unknown, the coordinates are not changed. The Z and measure values are not changed by the Project method" 文档指出“对于Project,几何体需要具有空间参考集,而没有UnknownCoordinateSystem。传递给该方法的新空间参考系定义了输出坐标系。如果任何一个空间参考为Unknown,则坐标都不会Z和度量值不会通过Project方法更改”

Your second point probably doesn't have a spatial reference set. 您的第二点可能没有空间参考集。 Setting it should fix it. 设置它应该修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM