This sample demonstrates how to use the TransformPointsFF method to transform an array of geographical points (latitude/longitude) from OSGB1936 to WGS1984. The ISpatialReferenceFactory is used to create a suitable geographic transformation object that implements the IGeocentricTranslation interface. One of the methods on this interface is TransformPointsFF.

Points to note:

(1) In Visual Basic, by default, the Option Base setting for a module is 0. You can set it to 1 by entering Option Base 1 in the Declarations section of the module. Therefore, by default, Dim pArray(2, 2) as Double allocates a 3 x 3 matrix, whilst Dim pArray(1, 1) as Double allocates a 2 x 2 matrix.

(2) A two-dimensional VB array cannot be used with TransformPointsFF. VB stores elements in column-major order whilst the implementation of TransformPointsFF assumes row-major order. The workaround is to use a single dimensioned array and interleave the x and y coordinates.

(3) The geographic transformation implementations of the ITransform methods assume 2D coordinates. (x, y, z) coordinates cannot be passed to TransformPointsFF. Future releases of Arc8 technology will provide support for various kinds of vertical datums.

(4) You may never need to use the TransformPointsFF method! Polylines, polygons, points and multipoints support the ITransform2D interface. One method on that interface is Transform. This method can take a geotransformation object as its parameter. This is simpler than using TransformPointsFF directly, especially if you already have access to a feature's points collection. Please see the Transform sample for details.

How to use:
  1. Start ArcMap.

  2. Add a new ArcMap Macro called Geotransformation and in the VBA editor, paste the following code into it.
  3. Run the Macro. You will see in the VBA Immediate window the results of the geotransformation.
Sub Geotransformation()
' Create a spatial reference factory
Dim pSpatRefFact As ISpatialReferenceFactory2
Set pSpatRefFact = New SpatialReferenceEnvironment

' Create a GeocentricTranslation object for OSGB1936_to_WGS1984 using the factory.
Dim pGT As IGeocentricTranslation
Set pGT = pSpatRefFact.CreateGeoTransformation(esriSRGeoTransformation_OSGB1936_To_WGS1984_1)

' How to get the parameters from the Geotransformation object
Dim dx As Double
Dim dy As Double
Dim dz As Double
pGT.GetParameters dx, dy, dz
Debug.Print dx, dy, dz

' How to get the from/to SpatialReferences that are supported by this geotransformation.
Dim pFromGCS As IGeographicCoordinateSystem
Dim pToGCS As IGeographicCoordinateSystem
pGT.GetSpatialReferences pFromGCS, pToGCS
Debug.Print pFromGCS.Name, pToGCS.Name

' Now create single dimensioned arrays for the inPoints and outPoints
Dim inPoints(3) As Double
Dim outPoints(3) As Double

' Interleave the logitude and latitude values for two points: 1E 55N, 2E 56N
inPoints(0) = 1' Longitude point 1
inPoints(1) = 55' Latitude point 1
inPoints(2) = 2' Longitude point 2
inPoints(3) = 56' Latitude point 2

' Make the call to TransformPointsFF - note the direction and number of points.
' Note also to pass the first element of the array.
pGT.TransformPointsFF esriTransformForward, 2, inPoints(0), outPoints(0)

' Print out the results
Debug.Print "Results using TransformPointsFF..."
Debug.Print "LON " & outPoints(0)& " LAT " & outPoints(1) 'transformed point 1
Debug.Print "LON " & outPoints(2)& " LAT " & outPoints(3) 'transformed point 2

End Sub