1

I have written a python script which has one output line-vector layer. The python script should calculate some value and then the script should set the attribute (with that value) of a newFeature (which will be added to the output layer).

As I have tried it with code from QGIS2.18, I get the following error:

Traceback (most recent call last): File "", line 125, in processAlgorithm KeyError: '0'

My code looks like this:

# loop through edges of inLayerEdges and merge 
    for feat in inEdges.getFeatures(QgsFeatureRequest()):

        # create new edge(line) for outputLayer
        newEdge= QgsFeature()
        currentPriority = feat.attributes()[idxPriority]
        currentEdgeId = feat.attributes()[idxEdgeId]

        if currentEdgeId.find('From') == -1:
            edgeIdTrimmed = currentEdgeId.replace('To', '')
        else:
            edgeIdTrimmed = currentEdgeId.replace('From', '')

        if edgeIdTrimmed in listOfEdgeIds:
            # if current edge id already processed -> skip it.
            #print "current edgeid already in list. Continue ..."
            continue

        else:      
            # if not, find all entries in the graph which share the same current edge id
            # and merge them
            listOfEdgeIds.append(edgeIdTrimmed)

            newEdge.setAttribute(EDGEID, edgeIdTrimmed)
            newEdge.setAttribute(PRIORITY, currentPriority)

    (...)

    # add the feature to the layer
    (res, outFeats) = outdp.addFeatures([newEdge])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.