# Calculate geometry (lat/long for a projected points layer) with python geoprocessing

462
4
05-19-2012 12:11 PM
New Contributor III
As part of a longer script I'm writing, I need to add fields to my points layer and put the lat/long coordinates in those fields.  This is so EASY to do manually by opening the attributes table, adding the fields, and doing a "Calculate geometry."  There's an option to tell it what units you want.

I keep trying to find a way to do this with python geoprocessing, and I can't figure it out.

I was using AddXY_Management, but this only yields the X and Y coordinates in whatever projection my points layer happens to be in.  CalculateField_Management won't let me specify the units for a points layer (or if it does, I can't figure out how).

Anyone know how to do this?  I feel like it should be easy and I'm just missing the magic python command.
Tags (3)
1 Solution

Accepted Solutions
MVP Legendary Contributor
You will have to use the project tool
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Project/00170000007m000000/
produce a new file to your desired coordinate system then the addxy tool, there is no option to project on the fly using python as you can by setting the coordinate system of the data frame then using it.
4 Replies
MVP Legendary Contributor
You will have to use the project tool
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Project/00170000007m000000/
produce a new file to your desired coordinate system then the addxy tool, there is no option to project on the fly using python as you can by setting the coordinate system of the data frame then using it.
New Contributor III
That is super annoying.  That's what I was trying to avoid.  A points layer in a projected coordinate system has a geographic coordinate system with lat/long underneath, right?  For that reason, I don't see why there isn't a way to get lat/long even if the data is projected.
MVP Legendary Contributor
I agree, but there is only one coordinate system for the coordinates, long/lat and projected coordinates aren't stored in the same file.  It should operate as the calculate geometry done via the interface.  If you are interested post on the ArcGIS Ideas site   http://ideas.arcgis.com/
Esri Regular Contributor
Hi

Try an UpdateCursor with a spatial reference set to the datum:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001w000000

Then the XY values returned from the geometry should be in lat/long.

Regards