Projecting points from one coordinate system to another

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 = trans.MathTransform.Inverse();
double[] point = inversedTransform.Transform(toPoint);


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

Last edited Oct 4, 2007 at 7:02 AM by SharpGIS, version 2

Comments

charga Nov 24, 2010 at 8:25 PM 
I'm trying a transaformation tha implies datum transformation. "*Note that no datum transformation is applied if the coordinate systems doesn't have a ToWGS84 parameter defined" exactly what this mean?

Seiti Jun 10, 2010 at 2:53 AM 
I think that this information is incorrect: "primary axis (X/East/Latitude) and the second the secondary (Y/North/Longitude)".

Did a transformation from GCS WGS84 to a PCS WGS84 (22S) and noted that the input must be the usual lng/lat (not lat/lng) to get the correct X/Y values.