import org.geotools.geometry.jts.JTS; import org.geotools.referencing.CRS; import org.geotools.referencing.GeodeticCalculator; import org.opengis.referencing.crs.CoordinateReferenceSystem; import com.vividsolutions.jts.geom.Coordinate; public class GeoDistanceTest { private CoordinateReferenceSystem sourceCRS; private String sourceX; private String sourceY; public GeoDistanceTest(String sourceCRS, String sourceX, String sourceY) throws Exception { this.sourceCRS = CRS.decode(sourceCRS); this.sourceX = sourceX; this.sourceY = sourceY; } public void distanceCalculator(String x, String y) throws Exception { GeodeticCalculator gc = new GeodeticCalculator(sourceCRS); gc.setStartingPosition(JTS.toDirectPosition(new Coordinate(Double.parseDouble(sourceX), Double.parseDouble(sourceY)),sourceCRS)); gc.setDestinationPosition(JTS.toDirectPosition(new Coordinate(Double.parseDouble(x), Double.parseDouble(y)),sourceCRS)); double distance = gc.getOrthodromicDistance(); System.out.println("distance (m) : "+ distance); } public static void main(String[] args) throws Exception { GeoDistanceTest g = new GeoDistanceTest("EPSG:4326", "37.5639686", "126.9794393"); g.distanceCalculator("37.5639686", "126.9794393"); } }
Post List
2019년 1월 24일 목요일
자바 geotools 15.1 좌표간 거리계산
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기