4

geotools または別の Java ライブラリを使用して、緯度経度を 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 に答える