I have a large feature layer hosted in ArcGIS Online. I want to select a subset by matching a field attribute to a value, and then update another field to specific value. Ideally I'd prefer not to iterate through any loops as the overall layer is > 150M records. The selection field is indexed and performs quickly, I just can't figure out how to modify/update the other field based on the selection. I've seen arcpy solutions that work with shapefiles and fgdbs, but nothing for Online.
Thanks in advance for any advice or pointers!
Solved! Go to Solution.
Hi Chuck,
I think FeatureLayer.calculate is what you are looking for.
I'm sure this is a simple issue, but it's stumped me.
The following line executes without issue:
fs_layer.calculate(where="FIPS=18039", calc_expression={"field":"VERSION", "value": "07/04/2021"})
This fails:
where_str = '"FIPS=18039"'
calc_str = '"field":"VERSION", "value":"07/10/2021"'
fs_layer.calculate(where=where_str, calc_expression={calc_str})
I've multiple ways to build the parameters to be passed, building the entire argument, varying quote schemes. What am I missing?
Chuck,
looks like the difference is a dict versus a set containing a string.
This is a valid dict (key: value) and looks to be an acceptable parameter type for calculate
Simplifying your code your second option is:
@DavinWalker2 Hi Davin, it not does work with me when I am passing my own value to be updated for an attribute. However, it works if I pass the column name ?
This does not work: fs_layer.calculate(where="FIPS=18039", calc_expression={"field":"FIELDNAME1", "value":"newattributevalue"}) // this returns an error PerformEdit() failure. ColumnName='newattributevalue' not found in field name map. (Error Code: 400)
This works: fs_layer.calculate(where="FIPS=18039", calc_expression={"field":"FIELDNAME1", "value":"FIELDNAME2"}) // this one copies the value from FIELDNAME2 to FIELDNAME1. Is this how calculate works?
Thank you
For this kind of thing, I'd recommend familiarizing yourself with Spatially Enabled DataFrames: https://developers.arcgis.com/python/guide/introduction-to-the-spatially-enabled-dataframe/
Your general process will look like this:
Hope this helps.
This worked great - thanks for the workflow
Thanks for the responses! featurelayer.calculate fit the bill. I'd skipped over it in my searches, because I'm not doing any "calculations". Once found it was an easy implementation. Thanks!!!
Chuck
.calculate() proved to be very simple and precise. Didn't know it existed before but definitely valuable for very precise editing of individual field(s).