JAVA GIS 方法未按预期运行
JAVA GIS method not behaving as expected
我正在使用方法调用将一个空间参考中的点转换为另一个空间参考(基本上是一个坐标平面到另一个坐标平面)并且调用在第一个示例中工作正常,然后在第二个示例中我使用相同的方法在相同的对象类型上,该方法对 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());
正常工作点的输出System.outs:
OLD POINT coords: 1860356.9240645461 1698342.0271777364
NEW POINT coords: -87.85965314497173 34.6678477163251
折线的输出System.outs(非常接近上面的点坐标):
OLD LINE coords: 1860490.636483086 1698315.1646775191
NEW LINE coords: 1860490.636483086 1698315.1646775191
如您所见,这似乎在第一种情况下可以正常工作,但在第二种情况下却不行。有什么想法吗?
documentation 表示 "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"
您的第二个点可能没有空间参考集。设置它应该可以解决它。
我正在使用方法调用将一个空间参考中的点转换为另一个空间参考(基本上是一个坐标平面到另一个坐标平面)并且调用在第一个示例中工作正常,然后在第二个示例中我使用相同的方法在相同的对象类型上,该方法对 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());
正常工作点的输出System.outs:
OLD POINT coords: 1860356.9240645461 1698342.0271777364
NEW POINT coords: -87.85965314497173 34.6678477163251
折线的输出System.outs(非常接近上面的点坐标):
OLD LINE coords: 1860490.636483086 1698315.1646775191
NEW LINE coords: 1860490.636483086 1698315.1646775191
如您所见,这似乎在第一种情况下可以正常工作,但在第二种情况下却不行。有什么想法吗?
documentation 表示 "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"
您的第二个点可能没有空间参考集。设置它应该可以解决它。