4

如何使用 geotools 或其他 java 库将我的 lat lon 转换为 EPSG 3857 投影?我很难找到合适的方法来使用。我知道 OpenLayers (javascript) 可以很容易地做到这一点,但我看不到转换这些坐标的清晰路径。

I would like to see this transformation
source lon, lat: -71.017942,  42.366662    
destination lon, lat: -71 1.25820, 42 22.0932

所以我创建了我的 CRS

final CoordinateReferenceSystem source = CRS.decode( "EPSG:4236" );
final CoordinateReferenceSystem dest = CRS.decode("EPSG:3857");

final MathTransform transform = CRS.findMathTransform(source, dest);

但是创建几何图形似乎并不直接,因为它们需要几何工厂或其他东西。

我是地理工具和地理空间数据的新手,感谢您的指导。

4

1 回答 1

3

这里有一个解决方案:

CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4236");
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:3857");
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, false);
GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4326);
Point point = geometryFactory.createPoint(new Coordinate(lon, lat));
Point targetPoint = (Point) JTS.transform(point, transform);
于 2013-10-11T21:15:17.637 回答