Update feature service with ArcGIS api for python

13961
14
Jump to solution
07-24-2017 10:02 AM
PatrickFilyer
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)
0 Kudos
1 Solution

Accepted Solutions
RohitSingh2
Esri Contributor
14 Replies
AlexanderBrown5
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

PatrickFilyer
Occasional Contributor II

Thanks Alexander, working through the demo now. 

0 Kudos
PatrickFilyer
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. 

0 Kudos
RohitSingh2
Esri Contributor
AlexanderBrown5
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

PatrickFilyer
Occasional Contributor II

Ideally this is what I would like to do. 

0 Kudos
NaomiBegg2
Occasional Contributor III

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

0 Kudos
RohitSingh2
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.

PhilLarkin1
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