Skip to content

CoordinatesTransformation

Christian Gendreau edited this page Aug 18, 2015 · 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 in 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 possible low-precision results, we do not use lenient transformation. This would also be a major cause of a "transformation not found" error.

NTv2 Grid Shift

It is also possible to use a grid shift file (e.g. .gsb file) to convert coordinates where a datum shift is required. In most cases, a grid shift file will produce more accurate results. Grid shift files are not available in this project but are available from government agencies (more information).

Canada National Transformation v2.0(NTv2) binary Grid Shift File is available under Open Government Licence on GeoGratis.

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"));

//Then, regular usage:	
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