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 🙂
Solved! Go to Solution.
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
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
Only hosted feature layer collection services can be overwritten
The original data used to publish this layer should be available on the portal
The data file used to overwrite should be of the same format and filename as the original that was used to publish the layer
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.
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?
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