This document is archived and information here might be outdated.  Recommended version.


Creating a predefined geotransformation (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with spatial references > Creating a predefined geotransformation (ArcObjects .NET 10.6 SDK)

Creating a predefined geotransformation


About creating a predefined geotransformation

To access the hundreds of predefined geographic (datum) transformations, ISpatialReferenceFactory has the CreateGeoTransformation method. The predefined geographic transformations are listed in the esriSRGeoTransformationType, esriSRGeoTransformation2Type, and esriSRGeoTransformation3Type enumerations.
The following code example shows how to create a geotransformation using the spatial reference factory. The GetSpatialReferences method is then used to return the source and target spatial references of the geotransformation.
[C#]
private void Transform()
{

    // Set up the SpatialReferenceEnvironment.
    // SpatialReferenceEnvironment is a singleton object and needs to use the Activator class.

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

    // Mean for Great Britain. Converts between Ordnance Survey Great Britain 1936 
    // (OSGB 1936) and World Geodetic System 1984 (WGS 1984).
    IGeoTransformation geoTransformation =
        spatialReferenceFactory2.CreateGeoTransformation((int)
        esriSRGeoTransformationType.esriSRGeoTransformation_OSGB1936_To_WGS1984_1)as
        IGeoTransformation;

    ISpatialReference fromSpatialReference;
    ISpatialReference toSpatialReference;
    geoTransformation.GetSpatialReferences(out fromSpatialReference, out
        toSpatialReference);

    System.Windows.Forms.MessageBox.Show(geoTransformation.Name);
    System.Windows.Forms.MessageBox.Show(fromSpatialReference.Name + ", " +
        toSpatialReference.Name);

}
[VB.NET]
Private Sub Transform()
    
    
    ' Set up the SpatialReferenceEnvironment.
    ' SpatialReferenceEnvironment is a singleton object and needs to use the Activator class.
    
    Dim factoryType As Type=Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment")
    Dim spatialReferenceFactory As ISpatialReferenceFactory3=CType(Activator.CreateInstance(factoryType), ISpatialReferenceFactory3)
    
    ' Mean for Great Britain. Converts between Ordnance Survey Great Britain 1936
    ' (OSGB 1936) and World Geodetic System 1984 (WGS 1984).
    Dim geoTransformation As IGeoTransformation=CType(spatialReferenceFactory.CreateGeoTransformation _
                                                  (esriSRGeoTransformationType.esriSRGeoTransformation_OSGB1936_To_WGS1984_1), IGeoTransformation)
    
    'spatialReferenceFactory.CreateGeoTransformation _.
    '(esriSRGeoTransformationType.esriSRGeoTransformation_OSGB1936_To_WGS1984_1).
    
    Dim fromSpatialReference As ISpatialReference
    Dim toSpatialReference As ISpatialReference
    geoTransformation.GetSpatialReferences(fromSpatialReference, toSpatialReference)
    
    System.Windows.Forms.MessageBox.Show(geoTransformation.Name)
    System.Windows.Forms.MessageBox.Show(fromSpatialReference.Name & ", " & toSpatialReference.Name)
    
End Sub


See Also:

Understanding geotransformations




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