Skip to content

Coordinate transformations

ebocher edited this page Mar 28, 2013 · 3 revisions

To transform a coordinate from one CoordinateReferenceSystem to another you must used the CoordinateTransformationFactory.

Below the method :

Give crs1, crs2 be two different CoordinateReferenceSystems.

Set a coordinate as a double[] array representing a geoposition in crs1.

Get the CoordinateOperation methods to transform the input coordinate from crs1 to crs2.

Pseudo-code

List<CoordinateOperation> coordOps = CoordinateTransformationFactory.createCoordinateOperations(crs1,crs2);

// Note that we get a List and not a single CoordinateTransformation, because several methods may exist to
// transform a position from crs1 to crs2

if (coordOps.size() != 0) {
    // Test each transformation method (generally, only one method is available)
    for (CoordinateOperation op : coordOps) {
        // Transform coord using the op CoordinateOperation from crs1 to crs2
        double dd  = op.transform(coord);
    }
}
Clone this wiki locally