2

I wrote the following code in order to automatically extract the objects' length of a line layer, but I think the « measureLine » expression is not working. This expression works very well PyQgis 2.0. Is there a new expression in PyQgis 3.0 ?

def dist_seg(layer):
  L=[]
  features=layer.getFeatures()
  d = QgsDistanceArea()
  for i, element in enumerate(features):
    m = d.measureLength(element.geometry())
    L.append((i, round(m,1)))
  return L
ennine
  • 863
  • 2
  • 10
  • 20

2 Answers2

2

Try to replace

m = d.measureLine(element.geometry().asPolyline())

with

m = element.length()
Arthur R
  • 516
  • 3
  • 10
1

I think you should use d.measureLength. I didn't test it. In meantime, you can try it, and on this are all changes in PyQGIS3: https://qgis.org/api/api_break.html#qgis_api_break_3_0_QgsDistanceArea

Neven
  • 526
  • 3
  • 15