Select to view content in your preferred language

One feature not showing edits made when using edit_feature function

559
1
12-30-2022 05:45 AM
Labels (3)
ColeHowell
Occasional Contributor

Title says it all. I'm working for a water company and am developing a system to take flow data from our SCADA system and import the data into GIS for leak detection purposes. Specifically what I'm working on now takes the forward and reverse flow and puts those numbers into those fields on my zone meter hosted feature layer. The problem I'm having is that the 'P10' meter's fields are not being updated when I run the script while the rest of the meters I'm working with are working just fine. I just need a little help troubleshooting since I'm new to using the API. I'm attaching the function I wrote to do this.

 

def update_zone_meters(dictionary):
    gis = GIS("url", "username", "password")
    portal_item = gis.content.get('item id')
    meter_layer = portal_item.layers[0]
    meter_fset = meter_layer.query()
    meter_features = meter_fset.features

    for meter in meter_features:
        edit = meter
        #print(edit.attributes['constrno2'])
        if (edit.attributes['constrno2'] + 'F') in dictionary:
            #print(dictionary[edit.attributes['constrno2']+'F'])
            edit.attributes['forward_flow'] = dictionary[edit.attributes['constrno2']+'F']
            #print(edit.attributes['forward_flow'])
        elif edit.attributes['constrno2'] == 'P10':
            edit.attributes['forward_flow'] = dictionary[edit.attributes['constrno2']]
            edit.attributes['reverse_flow'] = 0.0
        else:
            continue

        if (edit.attributes['constrno2'] + 'R') in dictionary:
            edit.attributes['reverse_flow'] = dictionary[edit.attributes['constrno2'] + 'R']
        else:
            continue

        meter_layer.edit_features(updates=[edit])
0 Kudos
1 Reply
Clubdebambos
Frequent Contributor

Hi @ColeHowell 

It could be that the elif edit.attributes['constrno2'] == 'P10' never gets executed.

Try

def update_zone_meters(dictionary):
    gis = GIS("url", "username", "password")
    portal_item = gis.content.get('item id')
    meter_layer = portal_item.layers[0]
    meter_fset = meter_layer.query()
    meter_features = meter_fset.features

    for meter in meter_features:
        edit = meter
        #print(edit.attributes['constrno2'])
        if (edit.attributes['constrno2'] + 'F') in dictionary:
            #print(dictionary[edit.attributes['constrno2']+'F'])
            edit.attributes['forward_flow'] = dictionary[edit.attributes['constrno2']+'F']
            #print(edit.attributes['forward_flow'])
        else:
            continue

        ## EDITED HERE to an if/else
        if edit.attributes['constrno2'] == 'P10':
            edit.attributes['forward_flow'] = dictionary[edit.attributes['constrno2']]
            edit.attributes['reverse_flow'] = 0.0
        else:
            continue

        if (edit.attributes['constrno2'] + 'R') in dictionary:
            edit.attributes['reverse_flow'] = dictionary[edit.attributes['constrno2'] + 'R']
        else:
            continue

        meter_layer.edit_features(updates=[edit])
~ learn.finaldraftmapping.com