Overwriting a feature layer on AGOL using a feature class

861
3
Jump to solution
07-11-2023 04:49 PM
Labels (1)
MichaelFowler1
New Contributor III

I am writing a script that will overwrite a feature layer on AGOL from a feature class I manage in a GDB - the issue I'm having is the .overwrite path

This is the script I have currently have is below. I successfully connect to AGOL and access the selected feature layer - but the script fails on line 21. The error is below.

import arcpy
from arcgis import GIS
from arcgis.features import FeatureLayerCollection
import os

# AGOL Details
username = 'myaccount'
password = 'password'
gis = GIS("https://www.arcgis.com", username, password)

# Item ID for feature to overwrite
itemid = '44ace4fd9e764c36bac2b9056679faee'

# Details for fc
GDB = r'H:\Projects\AGOL Overwrite Features\AGOL Overwrite Features.gdb'
newname = os.path.join(GDB, 'Test_Points_Overwrite')

# Overwrite feature layer
dataitem = gis.content.get(itemid)
flayercol = FeatureLayerCollection.fromitem(dataitem)
flayercol.manager.overwrite(newname) 

 

Error:

  File "H:\Projects\AGOL Overwrite Features\overwrite.py", line 50, in <module>
    flayercol.manager.overwrite(newname)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\managers.py", line 2271, in overwrite
    publish_parameters, overwrite=True
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 12743, in publish
    serviceitem_id = self._check_publish_status(ret, folder)

 

Instead of the variable 'newname' I've also tried fc = r'path to feature class in GDB' which got the same error.

Any help would be much appreciated 🙂

 

1 Solution

Accepted Solutions
MichaelFowler1
New Contributor III

The solution has been found!

For anyone else needing the solution - it was found here Automate overwrite web layer, feature class - Esri Community The answer by Jake Skinner worked wonders - I did have to change one line but that was in the comments with many other troubleshooting answers

View solution in original post

3 Replies
alex_mapintel
New Contributor III

Hi @MichaelFowler1 ,

Although you may have already seen the link, I'll share it here anyway. A few things to check out that may help. I've copied these steps from the overwrite ArcGIS API for Python here 

  1. Only hosted feature layer collection services can be overwritten

  2. The original data used to publish this layer should be available on the portal

  3. The data file used to overwrite should be of the same format and filename as the original that was used to publish the layer

  4. The schema (column names, column data types) of the data_file should be the same as original. You can have additional or fewer rows (features).

These may get you out of trouble. Specifically if you look into step 3 and 4.  

0 Kudos
MichaelFowler1
New Contributor III

Hi @alex_mapintel 

Thank you for sending that through!

I believe I'm good on Step 1, 2 and 4 - with step three I've gone back to 'fc = r'file path to original feature class' and now the script completes every time it is run. The issue now is it doesn't actually update/overwrite the feature layer with the new data and I've noticed that if I add or delete points from AGOL when I run the script it will revert back to the original dataset (even when the original dataset has changed). Do you happen to know why this occurs?

MichaelFowler1
New Contributor III

The solution has been found!

For anyone else needing the solution - it was found here Automate overwrite web layer, feature class - Esri Community The answer by Jake Skinner worked wonders - I did have to change one line but that was in the comments with many other troubleshooting answers