2

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?

3 Answers 3

1

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)

1

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.

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.

0

I replied to this same question over on the ESRI community forum. For me the error was trying to access a field in the SDF using incorrect punctuation. I also tried shifting the ObjectID value around in the updates payload (and removing it altogether) but ultimately it came down to changing sdf['field'] = value to sdf['Field'] = value in one of my data editing steps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.