You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects General forum

Converting XY coordinates to Decimal Degree...   Greg Gowing Aug 06, 2002
Re: Converting XY coordinates to Decimal De...   Christine Czapski Aug 06, 2002
Re: Converting XY coordinates to Decimal De...   Greg Gowing Aug 06, 2002
Re: Converting XY coordinates to Decimal De...   Christine Czapski Aug 06, 2002
Re: Converting XY coordinates to Decimal De...   Greg Gowing Aug 07, 2002
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Converting XY coordinates to Decimal Degrees 
Author Greg Gowing 
Date Aug 06, 2002 
Message I have an app that requires a flat file with output in both X/Y and decimal degrees co-ordinates. My data is stored as X/Y co-ordinates in NAD83 UTM Zone 17. How do I calculate the appropriate Lat/Long co-ordinates from the X/Y coordinates? (without re-projecting the data) 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Converting XY coordinates to Decimal Degrees 
Author Christine Czapski 
Date Aug 06, 2002 
Message Hi Greg,

I have been trying to get an answer to exactly what you've posted too. Yesterday, I found the code below in the Exploring ArcObjects book which allows the user to click on the map and get the coordinates in decimal degrees. Its very interesting to see the decimal values displayed from my map which is in UTM also. So, I know that it can't be a big deal to do what we want, just how.

Since I just found the code, I'll spend today trying to understand everything.

Hope this helps you and I'll keep watch on this thread too.

Chris
 
 
Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)

Dim pDocument As IMxDocument
Dim pPoint As IPoint
Dim pClone As IClone
Dim pGeometry As IGeometry
Dim pSpatialRefFactory As ISpatialReferenceFactory2
Dim pSpatialRef As ISpatialReference
Dim pGeogrpahicCoordSys As IGeographicCoordinateSystem

'get the point where the user clicked
Set pMxDoc = Application.Document
If pMxDoc.CurrentLocation.IsEmpty Then Exit Sub
'clone the point because we don't want to alter the actual doc current location point

Set pClone = pMxDoc.CurrentLocation
Set pPoint = pClone.Clone
Set pGeometry = pPoint 'QI
'create a new geographic coordinate system to use in the conversion

Set pSpatialRefFactory = New SpatialReferenceEnvironment
Set pGeogrpahicCoordSys = _
  pSpatialRefFactory.CreateGeographicCoordinateSystem(esriSRGeoCS_NAD1927)
Set pSpatialRef = pGeogrpahicCoordSys 'QI
pSpatialRef.SetFalseOriginAndUnits -180, -90, 1000000

pGeometry.Project pSpatialRef
MsgBox pPoint.x & ", " & pPoint.y, , "Decimal degrees"

End Sub
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Converting XY coordinates to Decimal Degrees 
Author Greg Gowing 
Date Aug 06, 2002 
Message Many thanks Christine

The code that I've included converts XY to Lat/Long (Decimal Degrees)

Just pass your iPoint object, in whatever projection you are using, to this routine and it will return Decimal Lat/Long. 
 
Private Sub ConvertXY(ByRef ppPoint As Point,
ByRef Lat As Double, ByRef Longitude As Double)

Dim pPoint As IPoint
Dim pClone As IClone
Dim pGeometry As IGeometry
Dim pSpatialRefFactory As ISpatialReferenceFactory2
Dim pSpatialRef As ISpatialReference
Dim pGeogrpahicCoordSys As IGeographicCoordinateSystem


    Set pClone = ppPoint
    Set pPoint = pClone.Clone
    Set pGeometry = pPoint 'QI

    Set pSpatialRefFactory = New SpatialReferenceEnvironment
    Set pGeogrpahicCoordSys = pSpatialRefFactory.CreateGeographicCoordinateSystem(esriSRGeoCS_NAD1983)
    Set pSpatialRef = pGeogrpahicCoordSys 'QI
    pSpatialRef.SetFalseOriginAndUnits -180, -90, 1000000

    pGeometry.Project pSpatialRef

    Lat = pPoint.y
    Longitude = pPoint.x

End Sub

 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Converting XY coordinates to Decimal Degrees 
Author Christine Czapski 
Date Aug 06, 2002 
Message Hi Greg, That's great the code helped you. These things are sometimes easier than one thinks, once you understand what's going on!

I am really new to GIS, so I have a question for you. What I want to do is to pass in lat/long in either decimal degrees or deg/min/sec which the users has entered into a form and zoom in to the point.

I have this working just fine for UTM XY values thgat they enter. I can use the same routine for zooming in, etc. But, how would I change this code to pass in the decimal degrees and return the xy values so I can zoom into the point?

Any help would be appreciated! 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Converting XY coordinates to Decimal Degrees 
Author Greg Gowing 
Date Aug 07, 2002 
Message I've solved my problems and will not follow this thread anymore.

A couple of suggestions:

Replace "CreateGeographicCoordinateSystem" with "CreateProjectedCoordinateSystem" and replace its parameter with an appropriate parameter from esriSRProjectCSType.

Here in SW Ontario, I'd try ESRISRPROJCS_WGS1984UTM_17N