Hi, I am trying to update a hosted feature layer after some manipulation on the data as a data frame. I am trying to follow the presentation here: updating_features_in_a_feature_layer | ArcGIS for Developers
As a test, I have `update_layer` as a Spatial Data Frame object, but it is essentially the result of `flayer.query().df`, so, I was hoping this would overwrite the data in the feature layer, with the data in the feature layer, thus not actually changing anything but testing the overwrite operation:
```
flayer = search_result[0].layers[0] # this is the feature layer I want to update
print(flayer.properties.capabilities)
# get each row in the updated feature dataframe as a dictionary. store in a list.
features_for_update = [json.loads(row.to_json()) for index,row in update_layer.iterrows()]
# update should track by OID or whatever the default index is specified
flayer.edit_features(updates=features_for_update)
```
However, I receive this error:
Cannot perform operation. Invalid operation parameters. 'updates' parameter is invalid Object reference not set to an instance of an object. What is the correct representation of the items in `features_for_update`? The example in the link seems like it should be a list of dictionaries, which is what I have. Cheers, Joe
Solved! Go to Solution.
Hi Joe,
One thing you can look into is the SpatialDataFrame Object supports a to_featureset method.
That could be used as input to the edit_features method on the featurelayer.
fs = MySpatDataFrame.to_featureset()
flayer.edit_features(updates=fs)
Take a look at the above and let me know if you have any questions.
Thanks,
Jeff
I haven't run the code in jupyter, but I'd recommend trying a print statement of type(flayer) and type(features_for_update).
However, I'd recommend following the structure outlined here for updating hosted feature layers.
Hi Joe,
One thing you can look into is the SpatialDataFrame Object supports a to_featureset method.
That could be used as input to the edit_features method on the featurelayer.
fs = MySpatDataFrame.to_featureset()
flayer.edit_features(updates=fs)
Take a look at the above and let me know if you have any questions.
Thanks,
Jeff
Thanks Jeff! This seems to do the trick.
Cheers,
Joe