Is there a way to always have the current x and y value of a point listed in the attribute table if the point is moved?
I have a lot of points that get moved around by various people, and I randomly need to export the attribute table and see the current x and y values of all the points. I know how to do it manually each time, but I have to do it so often that I am positive I will forget one day, which will lead to mistakes in other parts of my workflow.
By the way, I am using ArcGIS Online to host the points, if that makes a difference. Most of the time, the points are moved using ArcGIS Desktop, but occasionally they are moved in ArcGIS Web Maps.
Hosting it in AGOL does make a difference, as it means you don't have access to Attribute Rules that will fire on any edit.
You could configure an expression in a Smart Form, but it will really depend on where the edits are happening. Where do your users edit these points? If it's just in web maps / apps, you can configure a smart form to update x/y fields based on the geometry.
What format do you export to? Some formats have the shape in an easy-to-parse format, and you could just use the geometry column.
You could also use a simple Field Calculation through a Python script and either schedule the script to run at regular intervals to keep those fields up to date, or else write a script that updates the field and then exports the file all in one go. Unfortunately, the SQL available to you through the Field Calculate method does not let you use any spatial functions against the SHAPE column, but we can still get this done with a spatial dataframe.
from arcgis import GIS
from arcgis.features import GeoSeriesAccessor
gis = GIS('your portal url', 'username', 'password')
fl = gis.content.get('itemid of your service').layers[0] # assuming layer is index 0, but change if part of multi-layer service
df = fl.query(as_df=True, out_fields=['objectid'])
# i'm using centroid here because i'm testing against a polygon layer, but you could use this against a points layer, too
c = GeoSeriesAccessor(df['SHAPE']).centroid
# calculate new fields; swap 'x' and 'y' for whatever your field names really are
calculated = df.assign(
x = c.apply(lambda c: c[0]),
y = c.apply(lambda c: c[1])
)
# update fields in service
fl.edit_features(updates = calculated.spatial.to_featureset())
# export table directly from dataframe
calculated.spatial.to_featureclass('export.shp')
Hello! I'm sure what you said is the answer, but now I just have to understand it 🙂
The editing will take place randomly between ArcGIS Pro desktop and via an AGOL webmap. When I export, I just export out the attribute table of the points feature class, and then I do some side work that modifies that version of the attribute table, including adding some additional points. Then, I "upsert" using the append command in ArcGIS Pro desktop. During the "upsert" process, it overwrites the existing data online and adds in the few new points that I might have added to the attribute table based on the latitude and longitude of the points.
So basically, my flow is as follows: I have an existing file of points hosted as a feature layer in AGOL. I sometimes move the points around via ArcGIS Pro or via an AGOL webmap, and then I randomly download the attribute table while in ArcGIS Pro and make some adjustments to the table in Excel, including possibly adding more points. Then, I "upsert" the data in ArcGIS Online via the append method in ArcGIS Pro.
I honestly wish I could skip the "upsert" step using Arcgis desktop and all the work be done in the the cloud, but using Arcgis Pro is the only way I have reliably been able to get the upsert to take place. If I try updating the data only in AGOL, I run into issues.
If you have any feedback or ideas on how I could do everything better/easier, that would be wonderful. Right now, I am doing the upsert manually, but I intend to make it occur automatically via the model process running on a set interval of maybe every hour because the Excel file that holds all the data, which becomes the attribute table, gets updated frequently on a shared OneDrive folder. My desire is to get these updates pushed to an AGOL map frequently.