1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import org.geotools.geometry.jts.JTS; import org.geotools.geometry.jts.JTSFactoryFinder; import org.geotools.referencing.CRS; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.opengis.referencing.operation.MathTransform; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.Point; public class GeoTransTest { private CoordinateReferenceSystem sourceCRS; private CoordinateReferenceSystem targetCRS; public GeoTransTest(String sourceCRS, String targetCRS) throws Exception { this .sourceCRS = CRS.decode(sourceCRS); this .targetCRS = CRS.decode(targetCRS); } public void transform(String x, String y) throws Exception { GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); Coordinate coord = new Coordinate(Double.parseDouble(x), Double.parseDouble(y)); Geometry sourceGeometry = geometryFactory.createPoint(coord); MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS); Geometry targetGeomery = JTS.transform(sourceGeometry, transform); Point targetPoint = targetGeomery.getCentroid(); System.out.println( "변환전 EPSG:4326(WGS84) X : " +x + "\t EPSG:4326(WGS84) Y : " +y); System.out.println( "변환후 EPSG:3857 X : " +targetPoint.getX() + "\t EPSG:3857 Y : " +targetPoint.getY()); } public static void main(String[] args) throws Exception { GeoTransTest g = new GeoTransTest( "EPSG:4326" , "EPSG:3857" ); g.transform( "37.5639686" , "126.9794393" ); } } |
Post List
2019년 1월 24일 목요일
자바 geotools 15.1 좌표 변환
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기