Create a composite geographic transformation



Description:

This sample shows how to create a composite geographic (datum) transformation. A composite geographic transformation is a combination of two or more transformations that create a path between two geographic coordinate systems. You might need to create a composite transformation if a predefined transformation does not exist for your source and target geographic coordinate systems. This sample create a transformation that converts between NAD 1927 and NAD 1983 (HARN) in Arizona.

The sample can run in ArcEngine, ArcServer or ArcGIS. It has commented out lines which describes how to adapt the code for use ArcMap and add the new composite geographic transformation to ArcMap GeoTransformationOperationSet. Please see the Creating a custom geographic transformation sample for information on adding a transformation to a GeoTransformationOperationSet.

Products:
Engine: VB6
ArcView: VBA, VB6

Platforms: Windows,UNIX,Linux

Minimum ArcGIS Release: 9.0

How to use:
[VB6]
  1. Paste the code into your VB application.
  2. Run the routine.

Private Sub twoGT()
  ' The six commented out lines of code below are for use in ArcMap.
  '  Dim pActiveView As IActiveView
  '  Dim pMxDoc As IMxDocument
  '  Dim pMap As IMap
  
  '  Set pMxDoc = ThisDocument
  '  Set pMap = pMxDoc.FocusMap
  '  Set pActiveView = pMxDoc.ActiveView
  
  '1) Create the factory
  Dim pSpatRefFact As ISpatialReferenceFactory2
  Set pSpatRefFact = New SpatialReferenceEnvironment
  Dim pGeoTrans_A As IGeoTransformation
  Dim pGeoTrans_B As IGeoTransformation
  
  '2) Use the factory to create the geotransformation objects
  Set pGeoTrans_A = _
    pSpatRefFact.CreateGeoTransformation(esriSRGeoTransformation_NAD_1927_TO_NAD_1983_NADCON)
  Set pGeoTrans_B = _
    pSpatRefFact.CreateGeoTransformation(esriSRGeoTransformation_NAD_1983_TO_HARN_AZ)
  
  '3) Create a composite geotransformation object
  Dim pGeoTransComposite As ICompositeGeoTransformation
  Set pGeoTransComposite = New CompositeGeoTransformation
  
  '4) Add the two separate geotransformations to the composite
  pGeoTransComposite.Add esriTransformForward, pGeoTrans_A
  pGeoTransComposite.Add esriTransformForward, pGeoTrans_B

  '5) Give the new transformation a name.
  Dim pNewGeoTrans As IGeoTransformation
  Set pNewGeoTrans = pGeoTransComposite
  pNewGeoTrans.Name = "NAD_1927_To_NAD_1983_HARN_Arizona"
  
  '6) Get the IGeoTransformationOperationSet
  Dim pGeoTransOperationSet As IGeoTransformationOperationSet
  Set pGTSet = pSpatRefFact.GeoTransformationDefaults    

  ' Use the [ArcMap] version of the code when using in ArcMap.
  '6 [ArcMap])QI for the IMapGeographicTransformations
  '  Dim pMapGeotrans As IMapGeographicTransformations
  '  Set pMapGeotrans = pMap
  
  '7 [ArcMap])And get the IGeoTransformationOperationSet
  '  Dim pGeoTransOperationSet As IGeoTransformationOperationSet
  '  Set pGeoTransOperationSet = pMapGeotrans.GeographicTransformations
  
  '8 [ArcMap])Add the composite to the set
  ' The two lines add the transformation for both directions (NAD27 to HARN
  ' and HARN to NAD27).
  '  pGeoTransOperationSet.Set esriTransformForward, pGeoTransComposite
  '  pGeoTransOperationSet.Set esriTransformReverse, pGeoTransComposite

  '9 And one final ArcMap-specific line of code
  '  pActiveView.Refresh

End Sub