Skip to content

4. Apply a coordinate transformation

Bocher edited this page Sep 23, 2016 · 1 revision

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 = CoordinateOperationFactory.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);
    }
}

Note : The createCoordinateOperations cannot take VerticalCRS in its arguments. To perform a transformation between two VerticalCRS, you must use CompoundCRS and three-dimensional coordinate. Anyway, transformation between VerticalCRS often uses grids that need planimetric coordinates and thus required CompoundCRS.

Clone this wiki locally