Select to view content in your preferred language

best way to update feature layer via spatial data frame?

1494
3
Jump to solution
07-23-2018 09:05 AM
JoeMcGlinchy1
New Contributor

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
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JeffBigos
Esri Contributor

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

View solution in original post

3 Replies
by Anonymous User
Not applicable

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.

JeffBigos
Esri Contributor

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

JoeMcGlinchy1
New Contributor

Thanks Jeff! This seems to do the trick.

Cheers,

Joe

0 Kudos