Calculate Point X Y

2118
8
Jump to solution
07-08-2019 01:50 PM
JoeBorgione
MVP Esteemed Contributor

I got suckered into thinking Calculate Geometry Attributes available in 10.6.1 by believing the online help.  This post set me straight:  https://community.esri.com/message/820951-calculate-geometry-attributes-tool.  And no, ESRI has not updated the online help

However, the question remains: is there a way to calculate the X and Y geometry values of a point?  I have a point feature class that's in State Plane coordinates, and I've added Lat/Long fields that I can manually calculate into GCS NAD 83 decimal degrees.  I'd like to perform this task in a stand alone script....

That should just about do it....
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

You can use an Data Access Update Cursor to reproject the spatial data and then use the SHAPE@XY or SHAPE@X and SHAPE@Y tokens to get the X,Y values and then update the new fields.

View solution in original post

0 Kudos
8 Replies
JoshuaBixby
MVP Esteemed Contributor

You can use an Data Access Update Cursor to reproject the spatial data and then use the SHAPE@XY or SHAPE@X and SHAPE@Y tokens to get the X,Y values and then update the new fields.

0 Kudos
JoeBorgione
MVP Esteemed Contributor

I knew there had to be a way.  Thanks.  The new tool has a funky syntax, but I got it figured out:

arcpy.env.outputCoordinateSystem = 4269  #GCS_North_American_1983
arcpy.CalculateGeometryAttributes_management(fc,[['Latitude','POINT_Y'],['Longitude','POINT_X']])

Where fc is my feature class and the two fields are named accordingly.

That should just about do it....
LanceCole
MVP Regular Contributor

Joe, 

Are you looking to do this for a single point or all points in a feature class?  If for a feature class you can use Add XY Coordinates.  This will add or update the PointX and PointY fields to your feature class.  To do this for a different coordinate system than that of the feature class you need to set the output coordinate system and transformation in the environment settings when running the tool.  I use this all the time to add GCS decimal degrees to our state plane data for use in other applications.  I will add a few screen shots once I can get on a desktop system later this evening.

0 Kudos
JoeBorgione
MVP Esteemed Contributor

Thanks Lance; this particular script is more or less for maintenance of the point feature class.  The default coordinate system is  State Plane NAD 83 feet;  The two fields are added to the feature class since the field techs thin in Lat/Long, not feet.  The points get edited (moved) from time to time, so I just want to re-calculate them on a regular basis.  Looking at the Add XY Coordinates link you provide, the field names have to be Point_X and Point_Y; once it's run initially, it can be run as a maintenance item I presume...

Lance Cole

That should just about do it....
0 Kudos
LanceCole
MVP Regular Contributor

Joe, 

You are correct AddXY uses or will add the Point_X and Point_Y attributes to your feature when run. We use this when pushing out data to AGOL to add X and Y attributes to be consumed by other applications such as Collector or Survey123 that need lat/long in WGS 1984 decimal degrees for example. 

arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(4326) #WGS 84 
arcpy.env.geographicTransformations = "WGS_1984_(ITRF00)_To_NAD_1983"
arcpy.AddXY_management(fc)‍‍‍‍‍‍‍‍‍‍‍‍

One other side note, do not forget about the transformation for projecting coordinate systems in addition to the coordinate system.  This can be added to your script using the arcpy.env.geographicTransforamtions.

AlexP_
by
Regular Contributor

Hello @JoeBorgione @JoshuaBixby @LanceCole 

I would like to do this same result but  for attribute rule. Please kindly advise. Thank you.

0 Kudos
JoeBorgione
MVP Esteemed Contributor

It appears that

Geometry($feature).x  and

Geometry(#feature).y

Should return what you want.

A quick google search of 'arcgis arcade return coordinates' got me going.

That should just about do it....
AlexP_
by
Regular Contributor

@JoeBorgione  Thank you. Yes, i did that as the following. I posted but no one has answer.

https://community.esri.com/t5/geodatabase-questions/attribute-rule-x-and-y-coordinates-decimal-degre... 

0 Kudos