Geographic Information Systems Asked by Jeremy Mullins on December 29, 2020
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?
I had the same error - for me, ensuring the fields in the updates were identical to the fields in the original solved the problem (columns suffixed _y and _x resulting from the pandas merge are one source of non-identical fields)
Answered by Robmattles on December 29, 2020
I had a similar issue a while ago. I determined that ArcGIS REST API does not like that the objectIdField is being provided in the attributes section of the FeatureSet. ArcGIS REST API likes to index the rows on its own terms. Assuming that FID is already assigned as the objectIdField ( check this out by typing updatefeatures.object_id_field_name
in the console ), I would leave it out since it will be handled by a separate step in your process.
I have a couple of other resources that appear similar to what you are looking for.
Publish multiple layers in one feature service - Notice that the objectIdField is defined as a field, but its values are not defined in the script.
add_to_definition - This is an example of what is being sent when you are making a Feature Layer or Feature Layer Collection.
Note: The following post is my best guess as to what is going on. I welcome comments correcting or adding understanding to the issue at hand.
Answered by Kotebiya on December 29, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP