1

I am trying to insert a python dict record to the hosted online service. I am getting the following error:

Traceback (most recent call last): File "", line 1, in File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\layer.py", line 2824, in edit_features if isinstance(adds[0], dict): KeyError: 0

My dict is:

{
    'OBJECTID': 21641,
    'Shape': (689718.442176355, 15309636.152327772),
    'ANCILLARYROLE': 0,
    'ENABLED': 1,
    'CREATIONUSER': 'U437198',
    'DATECREATED': datetime.datetime(2023, 1, 11, 0, 0),
    'DATEMODIFIED': None,
    'LASTUSER': None,
    'SUBTYPECD': 1,
    'OWNER': 'NYSEG',
    'WORKORDERID': '801000483026',
    'PROJECTNUMBER': None,
    'PROPERTYUNITCODE': None,
    'WORKMANAGEMENTSYSTEMCODE': None,
    'GASTRACEWEIGHT': 541589504,
    'SYMBOLROTATION': 88.94467079,
    'DIVISION': 'DANS',
    'FACILITYID': '61020001',
    'EQUIPMENTID': None,
    'COMMENTS': None,
    'INSERVICEDATE': None,
    'MATERIAL': 'PL',
    'VALVEDIAMETER': '4',
    'VALVETYPE': 'BAL',
    'VALVEUSE': 'ISO',
    'ANSIPRESSURERATING': None,
    'BONDEDINDICATOR': 'N',
    'CLOCKWISETOCLOSE': 'C',
    'DEPTH': None,
    'DEPTHTONUT': None,
    'EMERISOLATIONSYSSTATUS': None,
    'GASPRESSURESYSTEMSTATUS': None,
    'GASSYSTEMSTATUS': None,
    'GROUNDLEVELINDICATOR': None,
    'INSULATEDINDICATOR': None,
    'NORMALPOSITION': 1,
    'PRESENTPOSITION': 1,
    'OPERATINGCLASSIFICATION': 'NC',
    'LOCATIONDESCRIPTION': None,
    'DIMENSIONTIE1': None,
    'DIMENSIONTIE2': None,
    'MANUFACTURER': None,
    'MODEL': None,
    'EMERISOLATIONSYSOBJECTID': None,
    'GASPRESSURESYSTEMOBJECTID': 830,
    'GASSYSTEMOBJECTID': 34,
    'SAP_FUNCTIONALLOCATION': None,
    'SAP_EQUIPMENTNUMBER': None,
    'CIVILDIVISION': None,
    'LEGACYID': None,
    'INSTALLATIONDATE': datetime.datetime(2022, 12, 6, 0, 0),
    'TURNSTOCLOSE': 0.25,
    'GLOBALID': '{B10CFD9F-2DB7-40C2-B708-E222222A0AED}',
    'OPERATINGSTATE': 'ACTIVE',
    'CUSTOMERCOUNT': None,
    'CUSTOMERCOUNTDATE': None,
    'MAINTENANCE_JOB': 'N',
    'CPSYSTEMSTATUS': None,
    'DIMENSIONTIE3': None,
    'ELEVATION': None,
    'ELECTRONICMARKERS': None,
    'FLOC_ID': None
}

MY code is :

import arcpy
from arcgis.features import FeatureLayer
lyr_url = 'https://services6.arcgis.com/A1NU60yx0I8XSDFS/arcgis/rest/services/ValvesTest/FeatureServer/0'

layer = FeatureLayer(lyr_url)
feature_count = layer.query(return_count_only=True)
print("Feature Count: ", feature_count)
layer.manager.truncate()
feature_count = layer.query(return_count_only=True)
print("Now Feature Count: ", feature_count)

fc = "E:\\ABC\\gaspopups.gdb\\DistributionGasValve"

feature = None
cursor = arcpy.da.SearchCursor(fc, ["*"])
row = next(cursor)
feature = {field: value for field, value in zip(cursor.fields, row)}
layer.edit_features(adds=feature )

How to go about it?

2
  • At least the shape value in your dict doesn't look right, it needs to be a dict, too, e.g. {"x": 123, "y": 456 }. See the documentation here
    – Berend
    Feb 3 at 7:56
  • 1
    Also, adds expects an array, so that would be adds=[feature].
    – Berend
    Feb 3 at 8:00

0

Your Answer

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

Browse other questions tagged or ask your own question.