Geotools 를 이용한 좌표 변환

2010. 2. 1. 21:42프로그래밍/GIS

반응형
Geotools를 이용하여 GIS 데이터를 원하는 좌표계로 변경할 때는 다음과 같이 진행합니다.

우선 좌표계에 대한 CRS 선언을 해야합니다.

EPSG (European Petroleum Survey Group) 코드로 정의된 코드라면 다음과 같이 CRS (Coordinate Reference System) 를 정의한다. 흔히 사용되는 WGS84의 경우 아래와 같다.

CoordianteReferenceSystem
sourceCRS = CRS.decode("EPSG:4326");

Geotools에서는 이와 같이 EPSG 코드로 정의되지 않는 좌표계 같은 경우에는 WKT (Well Known Text)로 구성된 좌표계 정의를 CRS로 만들어낼 수 있는 방법을 제공한다. 아래의 예는 GRS80 중부원점 TM에 대한 정의이다.

 String targetWKT = "PROJCS[\"ITRF_2000_TM_Korea_Central_Belt\","
        + " GEOGCS[\"GCS_ITRF_2000\","
        + "  DATUM[\"D_ITRF_2000\", SPHEROID[\"GRS_1980\", 6378137.0, 298.257222101]],"
        + "  PRIMEM[\"Greenwich\",0.0],"
        + "  UNIT[\"Degree\",0.017453292519943295]"
        + " ],"
        + " PROJECTION[\"Transverse_Mercator\"],"
        + " PARAMETER[\"False_Easting\", 200000.0],"
        + " PARAMETER[\"False_Northing\", 500000.0],"
        + " PARAMETER[\"Central_Meridian\", 127.0],"
        + " PARAMETER[\"Scale_Factor\", 1.0],"
        + " PARAMETER[\"Latitude_Of_Origin\", 38.0],"
        + " UNIT[\"Meter\", 1.0]]";

이와 같이 정의된 좌표계간에 변환은 다음과 같이 변환할 수 있다.

      CRSFactory crsFactory = ReferencingFactoryFinder.getCRSFactory(null);
      CoordinateReferenceSystem targetCRS = null;
      targetCRS = crsFactory.createFromWKT(targetWKT); // WKT를 CRS로 만들어냄

      CoordianteReferenceSystem sourceCRS = CRS.decode("EPSG:4326");

      MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
      Geometry transCoordGeometry = JTS.transform(orgGeometry, transform);


짜잔~~~ orgGeometry 를 좌표계 변환하여 transCoordGeometry로 변환에 성공했다.



반응형

'프로그래밍 > GIS' 카테고리의 다른 글

IP Geolocation 정보 다운 받기  (0) 2013.09.03
Ellipsoid Specifications  (0) 2010.02.11
GRS80 Korea TM  (0) 2010.01.18
자바스크립트 Spatial Query 소개  (0) 2009.01.29
Geometry Study...  (0) 2009.01.09