2013-03-24 172 views
2

如何使用geotools或其他java庫將我的緯度轉換爲EPSG 3857投影?我無法找到正確的方法來使用。我知道OpenLayers(javascript)可以很容易地做到這一點,但我沒有看到明確的路徑來獲得這些座標轉換。Java:將經緯度從EPSG:4236轉換爲EPSG:3857

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

但是創建幾何形狀似乎沒有直接的同分,因爲他們需要一個幾何工廠或東西..

我m新的地理工​​具和地理空間數據,感謝任何方向。

回答

2

這裏是你的解決方案:

CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326"); 
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); 
+0

有點晚了,但你的sourceCRS是錯誤的(4326 - > 4236) – dwana 2017-01-25 12:53:10

相關問題