This sample shows how to project a point using the ProjectEx method on IGeometry2. If the input and output spatial references use different geographic coordinate systems, a geographic (datum) transformation must be defined. The Project method on IGeometry does not support geographic transformations.
How to use
- Add the code to your project.
- Modify with your coordinate systems, geometries, and transformation.
Private Sub using_projectex()
Dim pPoint As IPoint
Set pPoint = New Point
Dim dLonDecimalDegrees As Double
Dim dLatDecimalDegrees As Double
dLonDecimalDegrees = -100#
dLatDecimalDegrees = 40#
Dim pGeoCoordSystem As ISpatialReference
Dim pProjCoordSystem As ISpatialReference
Dim pGeoTrans As IGeoTransformation
Dim pSpatRefFact As ISpatialReferenceFactory
Set pSpatRefFact = New SpatialReferenceEnvironment
Set pGeoCoordSystem = pSpatRefFact.CreateGeographicCoordinateSystem(esriSRGeoCS_NAD1927)
Set pPoint.SpatialReference = pGeoCoordSystem
pPoint.PutCoords dLonDecimalDegrees, dLatDecimalDegrees
' Create the output coordinate system.
Set pProjCoordSystem = pSpatRefFact.CreateProjectedCoordinateSystem(esriSRProjCS_NAD1983UTM_13N)
' Create a geographic transformation between the input and output
' geographic coordinate systems are different.
Set pGeoTrans = pSpatRefFact.creategeotransformation(esriSRGeoTransformation_NAD_1927_TO_NAD_1983_NADCON)
' Create a geometry object and project it.
Dim pGeo As IGeometry2
Set pGeo = pPoint
Set pGeo.SpatialReference = pGeoCoordSystem
pGeo.ProjectEx pProjCoordSystem, esriTransformForward, pGeoTrans, 0, 0, 0
End Sub