5 Replies Latest reply on Apr 11, 2011 4:43 PM by MKennedy-esristaff

    Project a point from one coordinate system to another


      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