Skip to content

Projecting points from one coordinate system to another

FObermaier edited this page Jul 10, 2018 · 1 revision

Performing a transformation from one coordinate system to another requires you to create two coordinate systems: A 'from' and a 'to' coordinate system. See the FAQ on how to create a coordinate system.

First create a CoordinateTransformationFactory:

CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();

Then create the transformation instance:

ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(fromCS, toCS);

All transformations are done on double arrays, where the first value is primary axis (X/East/Latitude) and the second the secondary (Y/North/Longitude). You can provide an optional third value (Z/Height), which can change if a datum transformation occurs* during the transform. Example:

double[] fromPoint = new double[] { 120, -3 };
double[] toPoint = trans.MathTransform.Transform(fromPoint);

If you want to transform back again, create an inversed transformation:

IMathTransform inversedTransform = ctfac.CreateFromCoordinateSystems(toCS, fromCS).MathTransform;
double[] point = inversedTransform.Transform(toPoint);

*Note that no datum transformation is applied if the coordinate systems doesn't have a ToWGS84 parameter defined.