Convert coordinate units using Python

1056
3
03-11-2013 09:35 AM
Status: Open
Labels (1)
LucasMurray2
Occasional Contributor II
Add the ability to easily convert the units of XY coordinates using Python code.  For example, using Calculate Geometry tool, I can get the coordinate of a point in meters, feet, decimal degrees, etc.  However, there's no easy way to do this in Python.

The ability to convert units in code is available for areas and lengths.  For example, !shape.length@yards! will calculate the length of a feature in yards.  What about adding a python function like !shape.extent.XMax@decimaldegrees! that will calculate the X coordinate of a point in decimal degrees?
3 Comments
ChrisFox
It is not that simple because the x coordinate of a point in decimal degrees will be different if the point is in NAD27 vs NAD83. I think the best way to accomplish this is to use the projectAs method on the Geometry object passing in a new spatial reference and appropriate geographic transformation. This will return a new Geometry object and then you can access the X and Y coordinates of the point in the new spatial reference.
JoelMcCune1
Chris, I investigated your proposed solution, and it works provided you are working with only geographic coordinate systems. However, working with UTM or MGRS really does not faciliate this.

To relate this solution to be more aligned to existing functinality, all we need is a tool doing the exact same thing as the Convert Coordinate Notation tool, except not requiring a table to be created first. If a method were provided with the same parameters, except the input and output were not a table and feature class, but simply an input set of coordinates and output set of coordinates, this would be ideal.

Right now, to convert in a tool, I have to create an in_memory table with the input coordinates, use the convert coordinate notation tool to convert to another in_memory feature class and extract the SHAPE@X and SHAPE@Y attributes to get what I need. This is a huge amount of overhead for something so simple. A simple method very similar to the functionality provided by the convert coordinate notation tool, except not requiring complete datasets...this is what is needed.
JimPhilippi1
...yeah but, in the calculate geometry tool you're allowed to enter the Coordinate System to calculate on...

0EME0000000Tk5U