I have a problem with my first QGIS 3 plugin. I want to calculate lenght each segment in my polyline and next creating buffer equal 1/2 length of line.
The first 13 lines code have to do calculating the length of the selected layer and it works. But I have a problem with the buffer. I tried many ways that I found on the internet and it still doesn't work. Now I have no errors, but the plugin does not return anything.
Can you solve this problem?
if result:
for layer in QgsProject.instance().mapLayers().values():
features = layer.getFeatures()
coluna = QgsField('Length', QVariant.Double)
res = layer.dataProvider().addAttributes([coluna])
leng = layer.dataProvider().fieldNameIndex
layer.updateFields()
fieldIndex = layer.dataProvider().fieldNameIndex( "Length" )
layer.startEditing()
for f in features:
geom = f.geometry()
leng = geom.length()
layer.changeAttributeValue(f.id(),fieldIndex, leng)
result = processing.run("native:buffer",
{'INPUT': layer,
'DISTANCE' : 100,
'SEGMENTS' : 10,
'DISSOLVE': True,
'END_CAP_STYLE' : 1,
'JOIN_STYLE': 0,
'MITER_LIMIT': 10,
'OUTPUT': 'memory:buffer'})
layer.commitChanges()
layer.updateFields()