How to use the IGeoTransformationOperationSet methods (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with spatial references > How to use the IGeoTransformationOperationSet methods (ArcObjects .NET 10.6 SDK)

How to use the IGeoTransformationOperationSet methods


In this topic


About using the IGeoTransformationOperationSet methods

This topic shows the different usage for the IGeometry.Project method and the IGeoTransformationOperationSet methods.

Using the IGeometry.Project method

Do the following steps to use the IGeometry.Project method:
  1. Create a spatial reference factory.
  2. Use the created spatial reference factory to create the spatial reference as a geographic coordinate system (GCS).
  3. Set up the false origin and units of the spatial reference.
  4. Create an envelope and set it with the spatial reference.
  5. Create a projected coordinate system (PCS) using the spatial reference factory.
  6. Query interface (QI) the envelope to IGeometry.
  7. Call IGeometry.Project to project the envelope to the PCS.

Using the IGeoTransformationOperationSet methods

Do the following steps to use the IGeoTransformationOperationSet methods:
  1. Create a spatial reference factory and environment.
  2. Get a reference to IGeoTransformationOperationSet. This is a singleton object that lives with the SpatialReferenceEnvironment singleton object.
  3. Create an instance of geotransformation.
  4. Call IGeoTransformationOperationSet.Set using the geotransformation.
See the following code example:
[C#]
public void Test()
{
    //Create source spatial reference.

    Type factoryType=Type.GetTypeFromProgID(
        "esriGeometry.SpatialReferenceEnvironment");
    System.Object obj=Activator.CreateInstance(factoryType);
    ISpatialReferenceFactory3 spatialReferenceFactory=obj as
        ISpatialReferenceFactory3;

    ISpatialReference spatialReference =
        spatialReferenceFactory.CreateGeographicCoordinateSystem((int)
        esriSRGeoCSType.esriSRGeoCS_WGS1984);
    spatialReference.SetFalseOriginAndUnits( - 80.0000000232831, 39.9999999767169,
        42949672.9);
    //Create an envelope and define its spatial reference.
    IEnvelope envelope=new EnvelopeClass();
    envelope.PutCoords( - 68.6076204314651, 49.6186709634653,  - 68.5531907607304,
        49.6530789785679);
    envelope.SpatialReference=spatialReference;
    //Destination spatial reference.
    ISpatialReference projectedCoordinateSystem =
        spatialReferenceFactory.CreateProjectedCoordinateSystem((int)
        esriSRProjCSType.esriSRProjCS_NAD1927UTM_19N);
    //Define the XYDomain equivalent to SetFalseOriginAndUnits.
    projectedCoordinateSystem.SetDomain(500000, 600000, 5300000, 5600000);
    String report="Print envelope coordinates before projection:\n" +
        envelope.XMin + " , " + envelope.YMin + " , " + envelope.XMax + " , " +
        envelope.YMax + "\n\n\n";
    //Project envelope.
    IGeometry geometry=envelope as IGeometry2;
    geometry.Project(projectedCoordinateSystem as ISpatialReference);
    report=report + "Print envelope coordinates after projection:\n" +
        envelope.XMin + " , " + envelope.YMin + " , " + envelope.XMax + " , " +
        envelope.YMax;
    System.Windows.Forms.MessageBox.Show(report);
}

//This example demonstrates how to use the IGeoTransformationOperationSet methods.
//Set up a few GeoTransformations.
public void ChangeCoordinateSystem1()
{
    ISpatialReferenceFactory2 spatialReferenceFactory=new
        SpatialReferenceEnvironmentClass();
    IGeoTransformationOperationSet geoTransformationOperationSet =
        spatialReferenceFactory.GeoTransformationDefaults;
    //NAD 1927 to WGS 1984 30.
    IGeoTransformation geoTransformation =
        spatialReferenceFactory.CreateGeoTransformation((int)
        esriSRGeoTransformationType.esriSRGeoTransformation_NAD1927_To_WGS1984_12)as
        IGeoTransformation;
    geoTransformationOperationSet.Set(esriTransformDirection.esriTransformForward,
        geoTransformation);
    geoTransformationOperationSet.Set(esriTransformDirection.esriTransformReverse,
        geoTransformation);
    //Amersfoort to WGS 1984.
    geoTransformation=spatialReferenceFactory.CreateGeoTransformation(8012)as
        IGeoTransformation;
    geoTransformationOperationSet.Set(esriTransformDirection.esriTransformForward,
        geoTransformation);
    geoTransformationOperationSet.Set(esriTransformDirection.esriTransformReverse,
        geoTransformation);
}
[VB.NET]
Sub Test()
    
    Dim t As Type=Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment")
    Dim obj As System.Object=Activator.CreateInstance(t)
    Dim psprefenv As ESRI.ArcGIS.Geometry.ISpatialReferenceFactory3=obj
    
    psprefOri=psprefenv.CreateGeographicCoordinateSystem(esriSRGeoCSType.esriSRGeoCS_WGS1984)
    psprefOri.SetFalseOriginAndUnits( -80.0000000232831, 39.9999999767169, 42949672.9)
    'Create an envelope and define its spatial reference.
    pEnv=New Envelope
    pEnv.PutCoords( -68.6076204314651, 49.6186709634653, -68.5531907607304, 49.6530789785679)
    pEnv.SpatialReference=psprefOri
    'Destination spatial reference.
    psprefOut=psprefenv.CreateProjectedCoordinateSystem(esriSRProjCSType.esriSRProjCS_NAD1927UTM_19N)
    'Define the XYDomain equivalent to SetFalseOriginAndUnits.
    psprefOut.SetDomain(500000, 600000, 5300000, 5600000)
    Debug.Print("*******************************************")
    Debug.Print("* Print envelope coordinates before projection")
    Debug.Print(pEnv.XMin & " , " & pEnv.YMin & " , " & pEnv.XMax & " , " & pEnv.YMax)
    Debug.Print("*******************************************")
    'Run the Example_IGeoTransformationOperationSet sub.
    Example_IGeoTransformationOperationSet()
    'Project envelope.
    pGeometry=pEnv
    pGeometry.Project(psprefOut)
    Debug.Print("*******************************************")
    Debug.Print("* Print envelope coordinates after projection")
    Debug.Print(pEnv.XMin & " , " & pEnv.YMin & " , " & pEnv.XMax & " , " & pEnv.YMax)
    Debug.Print("*******************************************")
    Exit Sub
errhand:
    Debug.Print(Err.Description)
End Sub

'This example demonstrates how to use the IGeoTransformationOperationSet methods.
'Set up a few GeoTransformations.

Public Sub Example_IGeoTransformationOperationSet()
    Dim pSpatRefFact As ISpatialReferenceFactory2
    pSpatRefFact=New SpatialReferenceEnvironment
    Dim pGeotrans As IGeoTransformation
    Dim pGeoTransOperationSet As IGeoTransformationOperationSet
    pGeoTransOperationSet=pSpatRefFact.GeoTransformationDefaults
    pGeotrans=_
                pSpatRefFact.CreateGeoTransformation(esriSRGeoTransformationType.esriSRGeoTransformation_NAD1927_To_WGS1984_12) 'NAD 1927 to WGS 1984 30.
    pGeoTransOperationSet.Set(esriTransformDirection.esriTransformForward, pGeotrans)
    pGeoTransOperationSet.Set(esriTransformDirection.esriTransformReverse, pGeotrans)
    pGeotrans=Nothing
    pGeotrans=_
                pSpatRefFact.CreateGeoTransformation(8012) 'Amersfoort to WGS 1984.
    pGeoTransOperationSet.Set(esriTransformDirection.esriTransformForward, pGeotrans)
    pGeoTransOperationSet.Set(esriTransformDirection.esriTransformReverse, pGeotrans)
    pGeotrans=Nothing
End Sub






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):

Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine