ArcPy – Calculating XY Coordinates in Decimal Degrees from Projected Datasets

arcgis-10.0arcpycursormodelbuilder

Is it possible to calculate points XY coordinates in Decimal Degrees in model or script when a feature class is in projected coordinate system?

It's easy when a FC is in geographic coordinate system:

  • using Add XY Coordinates tool or
  • using Python expression eg. !shape.extent.XMax!

I've found that area and length properties of geometry field can be modified with geometry unit conversion keyword. For linear units of measue one can use @DECIMALDEGREES.
Unfortunatelly, !shape.extent.XMax@decimaldegrees! doesn't work as XMax is not a length.

In Calculate Geometry function (accessed from right-click) there's a possibility to choose Decimal Degrees output type even for projected feature class.
Can I do this using ArcPy?


Here's a code snippet based on iRfAn's solution:

import arcpy, os
projectedFC = r"C:\tmp\test.gdb\points01_Projected"
prjFile = os.path.join(arcpy.GetInstallInfo()["InstallDir"],
            r"Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj")
spatialRef = arcpy.SpatialReference(prjFile)

updCursor = arcpy.UpdateCursor(projectedFC,"", spatialRef)
for row in updCursor:
    pnt = row.Shape.getPart(0)
    row.X = pnt.X
    row.Y = pnt.Y
    updCursor.updateRow(row)

del updCursor, row

Best Answer

I think you can.

Just define the Spatial Reference in WGS-84 and use cursor using this Spatial Reference.

Coordinates are specified in the spatial_reference provided, and converted on the fly to the coordinate system of the dataset.

Fore more detail see this.

Related Question