Project a point from one coordinate system to another

582
5
04-07-2011 08:18 AM
RogerNordström
New Contributor
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?

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
0 Kudos
5 Replies
MelitaKennedy
Esri Notable Contributor
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
0 Kudos
RogerNordström
New Contributor
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.
0 Kudos
MelitaKennedy
Esri Notable Contributor
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
0 Kudos
RogerNordström
New Contributor
You have to remember how US-centric ArcGIS is.


Thank you!

Am I supposed to mark this thread as answered or something?
0 Kudos
MelitaKennedy
Esri Notable Contributor
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
0 Kudos