Update Hosted Feature Layer

10-19-2020 06:07 AM
Esri Contributor
5 2 1,026

Recently I came across ESRI web course Update Real-Time Data with Python, and it walks through a tutorial on how to built what is called "feed routine". The idea is basically is to read latest version of certain feature-set from a JSON file shared and accessed through a URL, and feed that into your system, which in this case is a hosted feature layer. 

In this blog, I wanted to focus on the function "deployLogic" which takes places after reading the latest JSON data and converting it to ESRI file-geodatabase. This function demonstrate really important workflow on how to update the data of hosted feature layer, while keeping the hosted layer item id - as a Portal for ArcGIS or AGOL item. I didn't find similar workflow explained in the published documentation for ArcPy or API for Python, and I believe it can be accommodated to be used with more complex scenarios.

I will try to summarize the function logic in the following bullets:

  • Using 7zip sub-process, extract the hosted layer service definition file
  • Browse to the extracted folder, reach the underlying source file gdb, and delete it
  • Copy the fresh file-geodatabase that was created in previous step to the extracted service definition folder
  • Using 7zip, compress the service definition folder into a new service definition file with '.sd' extension, not '.zip'
  • Using "FeatureLayerCollectionManager" instance, update the hosted layer using the new service definition file

The simplicity of this workflow is that it avoids republishing the service using ArcGIS Pro project, so you won't need to go through something like "getWebLayerSharingDraft" from a Map object, and worry about setting the needed flags "overwriteExistingService", etc.. I find this really easy shortcut, and it will get the job done.

Update Real-Time Data with Python

Update Real-Time Data with Python

Update Real-Time Data with Python

New Contributor II


Yes, I had been doing something similar to your last approach by overwriting the sd using a weblayersharing draft.  The issue with this approach is there is a bug in the implementation so that not all the prior sd information is preserved (like sync & editing setting, item description, symbology?,...)

From my understanding this approach downloads the sd, unzips it, then overwrite the feature classes in the geodatabase, rezips the sd and updates the item's sd.  This way only the feature class is updated but the other aspects of the sd are preserved.  Does this sound about correct?



Esri Contributor

Hi Brent

This definitely sounds correct, given that the only changing bit is the data source of the hosted layer, so probably the method explained here is for this specific need. I wonder if it is possible to extent it to include -as you mentioned- the rest of the hosted layer capabilities (symbology, desc, sync..).