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:
- Create a spatial reference factory.
- Use the created spatial reference factory to create the spatial reference as a geographic coordinate system (GCS).
- Set up the false origin and units of the spatial reference.
- Create an envelope and set it with the spatial reference.
- Create a projected coordinate system (PCS) using the spatial reference factory.
- Query interface (QI) the envelope to IGeometry.
- Call IGeometry.Project to project the envelope to the PCS.
Using the IGeoTransformationOperationSet methods
Do the following steps to use the IGeoTransformationOperationSet methods:
- Create a spatial reference factory and environment.
- Get a reference to IGeoTransformationOperationSet. This is a singleton object that lives with the SpatialReferenceEnvironment singleton object.
- Create an instance of geotransformation.
- 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 |