Project a point from one coordinate system to another

Discussion created by rogernordstrom on Apr 7, 2011
Latest reply on Apr 11, 2011 by MKennedy-esristaff

I have to convert a point from one coordinate system to another.
I wrote this code (VB .NET) but it doesn't work that well.

The result of IsEmpty for geo and pnt, in TransPoint, is always true.

Public Function TransPoint(ByVal x As Double, ByVal y As Double) As IPoint
    Dim cooIn As IProjectedCoordinateSystem = LoadCoordinateSystem(...)
    Dim cooOut As IProjectedCoordinateSystem = LoadCoordinateSystem(...)
    ' --
    Dim pnt As IPoint = New PointClass()
    pnt.PutCoords(x, y)
    ' --
    Dim geo As IGeometry = pnt
    geo.SpatialReference = cooIn
    ' --
      Dim xx As Double = pnt.X
      Dim yy As Double = pnt.Y
      MsgBox("pnt: " & xx & ", " & yy)
    Catch ex As Exception
      MsgBox( _
        "geo.isEmpty: " & geo.IsEmpty & vbNewLine & _
        "pnt.isEmpty: " & pnt.IsEmpty & vbNewLine & _
      Return Nothing
    End Try
    Return pnt
End Function
Private Function LoadCoordinateSystem(ByVal src As String) As IProjectedCoordinateSystem
    Dim srf As ISpatialReferenceFactory = New SpatialReferenceEnvironmentClass()
    Dim pcs As IProjectedCoordinateSystem = srf.CreateESRISpatialReferenceFromPRJFile(src)
    Return pcs
End Function