Update feature service with ArcGIS api for python

11891
14
Jump to solution
07-24-2017 10:02 AM
Highlighted
Occasional Contributor II

I am trying to figure out how to update a feature service hosted on arcgis online using the arcgis api for python. Essentially, every morning I would like to run a script that takes new features from a feature class on our organizations egdb and update a replica of the feature service on AGOL. 

Is this possible?

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Contributor
14 Replies
Highlighted
Occasional Contributor II

Patrick,

If you utilize the Python API from an IDE and pull in ArcPy functions as well, you can utilize adding/editing features:

Editing features | ArcGIS for Developers 

You just need to create loop through your feature class to grab the pertinent attributes, format them for the ingestion into the Python API.  Definitely possible.

~Alex

Highlighted
Occasional Contributor II

Thanks Alexander, working through the demo now. 

Reply
0 Kudos
Highlighted
Occasional Contributor II

I made a test data set and was able to successfully add a point using the python api. However, when i implement this into our GIS, I will be adding polygons. Would you know how to write the geometry (coordinates) for a polygon? Adding a point is pretty straight forward as it is just an x,y value. 

Reply
0 Kudos
Highlighted
Esri Contributor
Highlighted
Occasional Contributor II

Rohit,

Do you have to export your new data to a csv?  Can you connect directly to your geodatabases using the Python API?  Definitely easier utilizing just the ArcGIS API, but I can see numerous occasions where users would want to update directly from their authoritative databases.

~Alex

Highlighted
Occasional Contributor II

Ideally this is what I would like to do. 

Reply
0 Kudos
Highlighted
Occasional Contributor III

Does this require Portal or can it be done using straight AGOL?

Reply
0 Kudos
Highlighted
Esri Contributor

You don't have to export your data to a csv. 

You can overwrite feature layers using arcgis.features.managers module — arcgis 1.2.0 documentation 

You can also read in a file geodatabase or shapefile as a Spatial Data Frame and get it in pandas before pushing the updates to a feature layer, on similar patterns as the examples shared above.

Highlighted
Occasional Contributor III

Thanks for the API. It is helpful. 

Here is some advice for those attempting to use .overwrite(). If you are passing a string file path, try pointing to the zipfile name while dropping the '.zip'. This worked for me. 

C:\RootFolder\example.zip
C:\RootFolder\example
Reply
0 Kudos