Java:从EPSG转换lat / lon:4236到EPSG:3857

时间:2013-03-24 23:11:47

标签: java projection geotools

如何使用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);

但是创建几何图形看起来并不简单,因为它们需要几何工厂或其他东西。

我是地理工具和地理空间数据的新手,感谢任何方向。

1 个答案:

答案 0 :(得分:2)

以下是您的解决方案:

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);