I am making a notebook that will archive data by appending data into an existing feature layer. I have the data download as a geodatabase on ArcGIS Online and then append in. It has worked for me in the past, but today it's giving me a real hard time. Odd part is, It will run if there is no data in the existing target feature layer, but if there is data in the feature layer, then I get the "Object reference not set to an instance of an object" error. Code below, any help would be great, thanks!
exportCounty= counties.export(counties.title, "File Geodatabase")
exportCounty.download("/arcgis/home/")
exportCounty.id
countyLog=gis.content.search('title:County_Log', item_type='Feature Layer')[0]
countyLog
countyLog.layers[0].append(item_id=exportCounty.id,
upload_format='filegdb')
Output:
AdamFackler1_0-1616616711702.png
Solved! Go to Solution.
Okay for those who stumble across this and want an answer, I figured it out (with Esri help). There is a parameter in the append function called "Upsert". It is optional and defaults to "False"; this is what threw me off. If you do not include this, any feature that has the same geometry will fail to append. HOWEVER, if you add in "upsert=False" into the append, then it will stack the data if the target and source is the same fields (like I was trying to do). You will have to do some field matching coding if they are not the same. Upsert = True means you are overwriting/ updating existing data and you'll have to put in some other parameters.
AdamFackler1_0-1618586151698.png
countyLog=gis.content.search('title:County_Log', item_type='Feature Layer')[0]
countyLog.layers[0].append(item_id=exportCounty.id,upload_format='filegdb')
is countyLog the layer? You seem to try to see what it is in the line below
did you try
countyLog.append(item_id=exportCounty.id,upload_format='filegdb')
CountyLog is the existing layer I am appending data into. I tried taking out the .layer but got an error "'Item' object has no attribute 'append'". This is in ArcGIS Online Notebooks in case that matters.
AdamFackler1_0-1616622378307.png
It seems CountyLog is an AGOL item rather than a FeatureLayer.
Try CountyLog.layers[0].append(...)
That's what I had originally and what is giving me the "Object reference not set to an instance of an object" Error.
Okay for those who stumble across this and want an answer, I figured it out (with Esri help). There is a parameter in the append function called "Upsert". It is optional and defaults to "False"; this is what threw me off. If you do not include this, any feature that has the same geometry will fail to append. HOWEVER, if you add in "upsert=False" into the append, then it will stack the data if the target and source is the same fields (like I was trying to do). You will have to do some field matching coding if they are not the same. Upsert = True means you are overwriting/ updating existing data and you'll have to put in some other parameters.
AdamFackler1_0-1618586151698.png