Hey all, longtime lurker finally encountering enough resistance from the Python implementation to come shouting for help. I'm using Python 3.6, latest Arcpy and ArcPro.
My company keeps a hosted feature layer of previous work (telecom construction) in our ArcOnline Organization; my task is to build an automation script to take CAD .dwg files, extract out certain polylines, check to see if there are duplicates in our existing layer, replace them if so, and finally upload the new polylines to the existing online feature layer.
Everything besides comparing the two layers has gone fine, but I've been stuck for a week on getting the hosted feature layer to cooperate properly.
From my understanding, the proper syntax to pull the layer into Python is as such:
dataitem = gis.content.get(itemid)
flayer = FeatureLayer.fromitem(dataitem)
I then have to convert the CAD feature class to a .gdb, zip it, and use
item_cad = gis.content.add(data, item_properties)
in order for them to be able to append to one another.
I was able to run that once with success, now I get thrown "Exception: item (data) already exists" and the script breaks.
How can I append the CAD feature class I'm creating to the online feature layer in a way that will allow me to continue and find the duplicates of a unique field? I've made sure all of the fields are the same, and when I've tried using
arcpy.Append_management(flayer, cad_fc, "NO_TEST") # I get a runtime error
flayer.append(cad_fc) # I get "Exception: Unable to append data. Append is not enabled. (Error Code: 405)" although the layer is editable in our organization content.
I'll add the relevant code below, please give a shout if you have any ideas!
import os, sys, traceback, datetime, arcpy, shutil
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
...
...
arcpy.FeatureClassToGeodatabase_conversion(cad_fc, gdb)
# Download hosted feature layer
print('Downloading online layer...')
dataitem = gis.content.get(itemid)
flayer = FeatureLayer.fromitem(dataitem)
geo_zip = r'path/to/file.zip'
# Compress local gdb with update data to zip
make_archive(gdb, geo_zip)
gdb_properties = {'title': 'Updated Works',
'type': 'File Geodatabase',
'tags' : 'tag,tag'}
item_cad = gis.content.add(data=geo_zip, item_properties=gdb_properties)
# Combine then Compare via Job Name (Unique) and delete older Job Name feature if there's a match
print('Comparing to online layer...')
#THIS IS WHERE I NEED A HAND#
flayer.append(cad_fc) #throws Error(stated above)
arcpy.Append_management(flayer, cad_fc, "NO_TEST") #throws Exception (above)
flayer.append(item_id=item_cad.id, upload_format='filegdb',source_table_name='Scratch')#throws a runtime error
...
...