Overwriting a Feature Layer from SpatialDataFrame Data Source

11-27-2018 08:51 AM
New Contributor III

I am trying to update / overwrite a Feature Layer using the ArcGIS API for Python. 

I am currently loading and manipulating the data in a SpatialDataFrame and I have published the data using `sdf.spatial.to_featurelayer()`.  This function creates a shapefile and the resulting Feature Layer.  However, the data is going to be updating and changing on maybe a weekly basis.  I could delete the layer and simply recreate it, but there is a good chance that the layer will be part of a StoryMap or some other AGOL web map, so that is not an option.

There is a good tutorial on how to overwrite a Feature Layer using pandas and a CSV here: overwriting_feature_layers | ArcGIS for Developers , but this depends on having the data in CSV format and utilizes the pandas `read_csv()` method, which does not have read_shapefile() equivalent.  

The `manager.overwrite()` method does not accept SDF format (though that would be super cool), so I think the best way to do it is probably updating the underlying shapefile and then overwriting from there.  Any ideas on how to do that or any other ideas?

0 Kudos
4 Replies
New Contributor III

In case anyone else tries to do the same, it turned out to be easier to simply update / add / delete using the edit_features functionality as described in the following ESRI guides: updating_features_in_a_feature_layer | ArcGIS for Developers  and Editing Features | ArcGIS for Developers 

Kind of a bummer because I need to manage all the data updates individually instead of simply rewriting, but this solution is definitely the most efficient.  

New Contributor III

Hi Nathaniel, thanks for sharing your feedback. Did you try to do the same with GeoJSON hosted Feature Layer? I'm trying to use flayer_collection.manager.overwrite()from the Jupyter notebook. I get the {'success': True} response, the modified date in AGOL metadata is updated but the actual data is still the same... I'm using a web GeoJSON ('http://www.gdacs.org/xml/archive.geojson').

Does anyone have any idea why the data is not getting updated? It gets updated without any problems via AGOL web interface...



0 Kudos
Occasional Contributor

Hi Jan, did you end up finding out a work around or reason why the  flayer_collection.manager.overwrite() method did not work?

0 Kudos
New Contributor

I've been experiencing a very similar issue. My process in jupyter imports the feature layer from AGOL, drops a field using json, performs a join with another AGOL layer to append the current version of the field, then overwrites the original layer in AGOL. Dropping and adding fields does change the target AGOL layer, but overwriting doesn't perform as expected.

The same number of rows are preserved in the target layer even though there should be more. Puzzlingly, the modified field does show changes. I'm looking into "upsert/append" as a solution instead.

0 Kudos