ArcObjects Library Reference  (Geometry)    

esriGeometry_IGeoTransformationOperationSet_Example

[Visual Basic 6.0]

Sub Project_UsingDefaultDatumShift()
Dim psprefenv As ISpatialReferenceFactory2, psprefOri As ISpatialReference
Dim psprefOut As ISpatialReference
Dim pGeometry As IGeometry, pEnv As IEnvelope
On Error GoTo errhand
'Create source spatial reference
Set psprefenv = New SpatialReferenceEnvironment
Set psprefOri = psprefenv.CreateGeographicCoordinateSystem(esriSRGeoCS_WGS1984)
psprefOri.SetFalseOriginAndUnits -80.0000000232831, 39.9999999767169, 42949672.9
'Create envelope and define its spatial reference
Set pEnv = New Envelope
pEnv.PutCoords -68.6076204314651, 49.6186709634653, -68.5531907607304, 49.6530789785679
Set pEnv.SpatialReference = psprefOri
'Destination spatial reference
Set psprefOut = psprefenv.CreateProjectedCoordinateSystem(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
Set 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()
 
  '1)Create our factory and environment
  Dim pSpatRefFact As ISpatialReferenceFactory2
  Set pSpatRefFact = New SpatialReferenceEnvironment
  Dim pGeotrans As IGeoTransformation
 
  '2)And get the IGeoTransformationOperationSet
  Dim pGeoTransOperationSet As IGeoTransformationOperationSet
  'Get a referen to the current operation set. This is a singleton object
  'that live with the SpatialReferenceEnvironment singleton object
  Set pGeoTransOperationSet = pSpatRefFact.GeoTransformationDefaults
  'You can as many Geotransformation to the GeoTransformationOperationSet
  Set pGeotrans = _
    pSpatRefFact.CreateGeoTransformation(esriSRGeoTransformation_NAD1927_To_WGS1984_12) 'NAD 1927 to WGS 1984 30
  pGeoTransOperationSet.Set esriTransformForward, pGeotrans
  pGeoTransOperationSet.Set esriTransformReverse, pGeotrans
  Set pGeotrans = Nothing
  Set pGeotrans = _
    pSpatRefFact.CreateGeoTransformation(8012) 'Amersfoort to WGS 1984
  pGeoTransOperationSet.Set esriTransformForward, pGeotrans
  pGeoTransOperationSet.Set esriTransformReverse, pGeotrans
  Set pGeotrans = Nothing
End Sub


[C#]
public void ChangeCoordinateSystem()
{
  //Create source spatial reference
  ISpatialReferenceFactory2 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
  ISpatialReference spatialReference = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
  spatialReference.SetFalseOriginAndUnits(-80.0000000232831, 39.9999999767169, 42949672.9);

  //Create 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()
{
  //1)Create our factory and environment
  ISpatialReferenceFactory2 spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
  //2)And get the IGeoTransformationOperationSet
  //Get a referen to the current operation set. This is a singleton object
  //that live with the SpatialReferenceEnvironment singleton object
  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);

}

[Visual Basic .NET, C++]
No example is available for Visual Basic .NET or C++. To view a Visual Basic 6.0 or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.