C#: Project geometry with user defined transformation

692
0
07-16-2019 09:03 AM
RalphElsaesser
New Contributor

I have routines which project geometries from the projectedCS DHDN_GK_3 to projectedCS ETRS89_32N using the available predefined ESRI Transformation esriSRGeoTransformationType.esriSRGeoTransformation_DHDN_To_ETRS_1989_8_NTv2 and this works well:

private void ProjectPoint(ESRI.ArcGIS.Geometry.Point pt)
{
    ISpatialReference pSourceCoordSystem;
    ISpatialReference pTargetCoordSystem;
    IGeoTransformation pGeoTrans;
    ISpatialReferenceFactory pSpatRefFact;
     pSpatRefFact = new SpatialReferenceEnvironment();
    // Create the source coordinate system.
    pSourceCoordSystem = pSpatRefFact.CreateProjectedCoordinateSystem( (int)esriSRProjCS4Type.esriSRProjCS_DHDN_3_Degree_Gauss_Zone_3);
    // Create the output coordinate system.    pTargetCoordSystem = pSpatRefFact.CreateProjectedCoordinateSystem( (int)esriSRProjCS4Type.esriSRProjCS_ETRS1989_UTM_Zone_32N);
     // Create a geographic transformation between the input and output     // geographic coordinate systems are different.
    pGeoTrans = (IGeoTransformation)pSpatRefFact.CreateGeoTransformation((int) esriSRGeoTransformationType.esriSRGeoTransformation_DHDN_To_ETRS_1989_8_NTv2 );
     // Create a geometry object and project it.
    pt.SpatialReference = pSourceCoordSystem;
    IGeometry2 pGeometry = (IGeometry2)pt;
    pGeometry.ProjectEx( pTargetCoordSystem, esriTransformDirection.esriTransformForward, pGeoTrans, false, 0.0, 0.0);
    MessageBox.Show( pt.X.ToString() + " / " + pt.Y.ToString());
}

Now I would like to use my own user-defined transformation method which I created and saved in ArcMap. So I would have to replace the line

pGeoTrans = (IGeoTransformation)pSpatRefFact.CreateGeoTransformation((int)esriSRGeoTransformationType.esriSRGeoTransformation_DHDN_To_ETRS_1989_8_NTv2 );

with something like

pGeoTrans = (IGeoTransformation)pSpatRefFact.LoadGeoTransformation("myTransformation" );

This Load function is nonexisting. Any ideas how to do it?

0 Kudos
0 Replies