I have two input vector layers and I want to create an Output vector layer by doing some calculations. But somehow, the setAttribute method does not work. In QGIS 2.18, I was able to set an attribute like this:
ID = 'id' inEdges = self.parameterAsSource(parameters, self.INPUT_VECTOR_LAYER_EDGES, context) # get field indices for inputlayer fieldsEdges= inEdges.fields() idxEdgeId = fieldsEdges.indexFromName(ID) edgeIdTrimmed = some calculation ... (...) newEdge = QgsFeature() newEdge.setAttribute(idxEdgeId, edgeIdTrimmed) # <-- the error is here
But now, using QGIS 3, I get the following error message:
Traceback (most recent call last): File "", line 125, in processAlgorithm KeyError: '0'
Any ideas on how to set an attribute value in QGIS 3?
Is there any other method to do this now?
And what does that KeyError mean exactly?