+ Reply to Thread
Results 1 to 6 of 6

Thread: Project a point from one coordinate system to another

  1. #1
    Roger Nordström
    Join Date
    Apr 2011
    Posts
    3
    Points
    0
    Answers Provided
    0


    0

    Default Project a point from one coordinate system to another

    Hi!

    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.
    Why?

    Code:
    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
        geo.Project(cooOut)
        ' --
        Try
          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 & _
            ex.Message)
          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
    Last edited by rogernordstrom; 04-07-2011 at 10:44 AM.

  2. #2
    Melita Kennedy

    Join Date
    Nov 2009
    Posts
    1,803
    Points
    513
    Answers Provided
    74


    0

    Default Re: Project a point from one coordinate system to another

    The code looks okay to me.

    Are both spatial references valid? What are they and what's a sample input point? What version are you using?

    Melita
    Melita Kennedy
    Sr. Esri Product Engineer

  3. #3
    Roger Nordström
    Join Date
    Apr 2011
    Posts
    3
    Points
    0
    Answers Provided
    0


    0

    Default Re: Project a point from one coordinate system to another

    Thank you for your time.

    I have used the prj-files successfully in other scenarios, thats my reason to believe they work.
    As cooIn I use the file "SWEREF99 TM.prj" and for cooOut "RT90 25 gon V.prj". I found them under (App-Folder)\"Coordinate Systems\Projected Coordinate Systems\National Grids\Sweden\"

    My test coordinates is:
    x = 7454204.638
    y = 761811.242

    The result (in RT90 25 gon V) should be:
    pnt.X = 7453389.762
    pnt.Y = 1727060.905

    I'm using ArcView 9.3.1 and ArcGIS Desktop SDK .NET 9.3.3000.

  4. #4
    Melita Kennedy

    Join Date
    Nov 2009
    Posts
    1,803
    Points
    513
    Answers Provided
    74


    0

    Default Re: Project a point from one coordinate system to another

    Quote Originally Posted by rogernordstrom View Post
    Thank you for your time.

    I have used the prj-files successfully in other scenarios, thats my reason to believe they work.
    As cooIn I use the file "SWEREF99 TM.prj" and for cooOut "RT90 25 gon V.prj". I found them under (App-Folder)\"Coordinate Systems\Projected Coordinate Systems\National Grids\Sweden\"

    My test coordinates is:
    x = 7454204.638
    y = 761811.242

    The result (in RT90 25 gon V) should be:
    pnt.X = 7453389.762
    pnt.Y = 1727060.905

    I'm using ArcView 9.3.1 and ArcGIS Desktop SDK .NET 9.3.3000.
    Hello Roger,

    I may have an answer. You have to remember how US-centric ArcGIS is. In ArcGIS,

    x = easting = longitude
    y = northing = latitude

    Try swapping the x and y values and you should get a better results.

    ArcGIS usually doesn't apply any geographic (datum) transformations automatically. You may want to switch to using IGeometry::ProjectEx and set up a GeoTransformation. It looks like the code is 108212 for SWEREF99 to RT90 so you apply this with esriTransformForward. To create it, use ISpatialReferenceFactory::CreateGeoTransformation.

    Melita
    Melita Kennedy
    Sr. Esri Product Engineer

  5. #5
    Roger Nordström
    Join Date
    Apr 2011
    Posts
    3
    Points
    0
    Answers Provided
    0


    0

    Default Re: Project a point from one coordinate system to another

    Quote Originally Posted by mkennedy View Post
    You have to remember how US-centric ArcGIS is.
    Thank you!

    Am I supposed to mark this thread as answered or something?
    Last edited by rogernordstrom; 04-10-2011 at 10:49 PM.

  6. #6
    Melita Kennedy

    Join Date
    Nov 2009
    Posts
    1,803
    Points
    513
    Answers Provided
    74


    0

    Default Re: Project a point from one coordinate system to another

    Quote Originally Posted by rogernordstrom View Post
    Thank you!

    Am I supposed to mark this thread as answered or something?
    There's no way to do so. The Esri team that works with the forum software is working on adding that type of functionality. I supposed you could rate the thread high, but you don't need to.

    Melita
    Melita Kennedy
    Sr. Esri Product Engineer

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts