Skip to content

CoordinatesTransformation

Christian Gendreau edited this page Nov 25, 2013 · 26 revisions

This feature should be used with cautious

The accuracy of processed coordinates depends on the precision of the provided coordinates and the transformation needed. Accuracy can differ from one CRS to another. You should always test the result to ensure the accuracy is suitable for you.

The transformations are accomplished using GeoTools 10 [JTS API] (http://docs.geotools.org/latest/userguide/library/api/jts.html).

CoordinatesToWGS84 Processor

In order to use this processor, you need to include some GeoTools 10 dependencies to your project:

<dependency>
	<groupId>org.geotools</groupId>
	<artifactId>gt-epsg-hsql</artifactId>
	<version>10.0</version>
</dependency>
<dependency>
	<groupId>org.geotools</groupId>
	<artifactId>gt-main</artifactId>
	<version>10.0</version>
</dependency>
CoordinatesToWGS84Processor ctwProcessor = new CoordinatesToWGS84Processor();
CoordinateReferenceSystem crs;
try {
	crs = CRS.decode("EPSG:26912"); //NAD83 / UTM zone 12N
	ProcessingResult pr = new ProcessingResult();
	Double[] coordinates = ctwProcessor.process(548566d,4935158d, crs, pr);
	
	System.out.println("lat:"+coordinates[LatLongProcessorHelper.LATITUDE_IDX] + " , long:" + coordinates[LatLongProcessorHelper.LONGITUDE_IDX]);
			
} catch (NoSuchAuthorityCodeException e) {
	e.printStackTrace();
} catch (FactoryException e) {
	e.printStackTrace();
}
//prints: lat:44.56812235120222 , long:-110.38837721812456

WKT - Well Known Text representation

You can also provide the exact WTK using GeoTools CRS.parseWKT(String wtk) function.

Clone this wiki locally