I'm trying to update an ArcGIS Online (AGOL) feature layer using an updated local CSV file (the steps for this process are detailed in this Sample Notebook). I am using Jupyter Notebook to handle all the code. Here is the code I am running:
csv2 = sql2CSVout
updates_df_2 = pd.read_csv(csv2)
fl = featureLayer.layers[0]
flquery = fl.query()
overlap_rows = pd.merge(left - flquery.sdf, right = updates_df_2, how = 'inner', on = 'FID')
updatefeatures = []
all_features = flquery.features
for fid in overlap_rows['FID']:
original_feature = [f for f in all_features if f.attributes['FID'] == fid]
[0]
ftbu = deepcopy(original_feature)
matching_row = updates_df_2.where(updates_df_2.FID == fid).dropna()
input_geometry = {'y':float(matching_row['Y']),
'x':float(matching_row['X'])}
output_geometry = geometry.project(geometries = [input_geometry],
in_sr = 4326
out_sr = flquery.spatial_reference['latestWkid'],
gis = gis)
ftbu.geometry = output_geometry[0]
ftbu.attributes['BUILDINGID'] = matching_row['BuildingID'].values[0]
ftbu.attributes['Classrooms'] = matching_row['Classrooms'].values[0]
ftbu.attributes['Descriptio'] = matching_row['Description'].values[0]
ftbu.attributes['TypeCode'] = matching_row['TypeCode'].values[0]
ftbu.attributes['FID'] = int(matching_row['FID'])
ftbu.attributes['Email'] = matching_row['Email'].values[0]
updatefeatures.append(ftbu)
fl.edit_features(updates = updatefeatures)
Running this section of code has given me no issue until yesterday. After running the edit_features
method, a syntax error threw an error later in the script. After fixing the syntax error, I tried to rerun the script in Jupyter and was given the following error:
Runtime Error: Cannot perform operation. Invalid operation parameters.
'updates' parameter is invalid
An item with the same key has already been added.
(Error Code: 400)
I'm not sure where the issue lies. I've tried restarting the Jupyter kernel to no avail. I've checked for any created feature layers or collections on ArcGIS Online that could be considered "the same key" and there's nothing. I even used xmode
to raise verbose error messages to view the exact inputs for edit_features
method and while I did get those, it still doesn't work.
I feel like it has something to do with an ArcGIS connection somewhere and edits are apparently stored there before being applied and those stored edits need to be erased so that this script can work, but that feels like a guess.
Anybody got any ideas what to do?