Updating Service — ArcGIS API for Python

Lucas Suryana
3 min readMay 7, 2020

On this occasion, we will learn how to update a feature service by using ArcGIS API for Python. For you, who’s still new in ArcGIS, this is really a powerful API that will help you to manage your tasks with Python. Especially if we are used to programming.

Before we start, make sure that you have an account and access to publish a service on the following (you can choose one)*:
1. ArcGIS Enterprise
2. ArcGIS Online
*) For the next part, I will use Portal term for ArcGIS Enterprise and AGOL for ArcGIS Online

Next, we first need to publish a service to our Portal/AGOL. The service could be either a table or a feature layer. We will learn how to update the data for both the table and the feature layer.

Table and Feature Layer in My Content
Table
Feature Layer

Before we start, we need to install ArcGIS API for Python in your Python environment. This is simply a Python library.

pip install arcgis

After we install the ArcGIS API for Python, we need to connect to our Portal/AGOL in Python.

Now we will start by updating the feature layer then the table

Updating feature layer

In this case, we will update the location and the contractor name of well

STEP 1: Connect to our editable feature layer.

We can get the item id on our layer’s URL

STEP 2: Create a JSON file that will update the feature layer. We will change the Abab field location into a new location and change the contractor’s name.

STEP 3: Push updates

Now we can see the well location has been moved from Lat: -6.59 Long 106.00 into Lat: -6.70 Long 107.00. The contractor also has been changed from Schlumberger into Baker Hughes.

Updating the table layer

In this case, we will change the updated date. Actually this step is exactly the same as the previous step, but the difference is on # access the item’s feature layers part.

STEP 1: Connect to editable table

If we see at the # Access the item’s table layers, instead of using .layers we use .tables as we are not accessing layers but the table.

STEP 2: Create a JSON file that will update the table. We will change the date from 2020–05–02 to 2020–05–03. And if we see closely, we don’t need to create a geometry in the JSON file as table doesn’t have any geometries.

STEP 3: Push updates

Now we can see the table’s date has been updated.

CONCLUSION

Finishing the step above means we have done an update for the table and the feature layer. And the most important part is that we did that in our Python environment. If we have hundreds or thousands of rows or columns when a manual update is not effective anymore we can use ArcGIS API for Python for doing that.

You can try it on your own by accessing my Github.

--

--

Lucas Suryana

PhD Student @TU Delft — Developing a safer and a more acountable automated vehicle