How to Update attributes in an Online Feature Layer using Selection

1660
4
Jump to solution
08-11-2021 02:55 PM
ChuckBenton
Occasional Contributor

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! 

0 Kudos
1 Solution

Accepted Solutions
DavinWalker2
Esri Contributor

Hi Chuck,

I think  FeatureLayer.calculate is what you are looking for. 

View solution in original post

4 Replies
DavinWalker2
Esri Contributor

Hi Chuck,

I think  FeatureLayer.calculate is what you are looking for. 

ChuckBenton
Occasional Contributor

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?

0 Kudos
emedina
New Contributor III

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:

  1. Create a FeatureLayer object from the layer you want to update
  2. Create an SEDF from the FeatureLayer
  3. Perform your selections/manipulations in the SEDF. When satisfied with the result, optionally create a version of the dataframe that only includes the field(s) you're updating and the unique identifier used for the update (ObjectID/GlobalID).
  4. Convert the result dataframe to a feature set.
  5. Execute an update operation with the FeatureLayer object's  "edit_features" method (your update is the feature set you created).

Hope this helps.

0 Kudos
ChuckBenton
Occasional Contributor

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