Skip to content

CoordinatesTransformation

Christian Gendreau edited this page Dec 9, 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

To avoid a possible low-precision result, we do not use lenient transformation. This would also be the major cause of "transformation not found" error.

NTv2 Grid Shift

It's also possible to use a grid shift file (e.g. .gsb file) to convert coordinates where a datum shift is required. In most of the cases, a grid shift file will give more accurate results.

Example:

Content of the file "transform_overrides.properties" to go from EPSG:4609(NAD27(cgq77)) to EPSG:4326 (WSG84). 4609,4326=PARAM_MT["NTv2", PARAMETER["Latitude and longitude difference file", "CGQ77-98.gsb"]]

// Register the transform overrides
ReferencingFactoryFinder.addAuthorityFactory(new WKTOperationFactory("/transform_overrides.properties"));
		
CoordinatesToWGS84Processor ctwProcessor = new CoordinatesToWGS84Processor();
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:2032"); //NAD27 / UTM zone 12N
Double coordinates[] = ctwProcessor.process(612678d,5045656d,sourceCRS, null);
System.out.println("lat:"+coordinates[LatLongProcessorHelper.LATITUDE_IDX] + " , long:" + coordinates[LatLongProcessorHelper.LONGITUDE_IDX]);
//prints: lat:45.557317296158374 , long:-73.5559174799771

WKT - Well Known Text representation

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

##EPSG related resources

Clone this wiki locally