1

The following code works very well in pyqgis 2.0 with a line shapefile, but when executed with pyqgis 3.0 the instruction measureLine return 0 and with no errors signaled. What is the new instruction in pyqgis 3.0?

from qgis.core import *
from qgis.gui import *

def dist_seg():
  layer=iface.activeLayer()
  L=[]
  features = layer.getFeatures()
  d = QgsDistanceArea()
  for i,element in enumerate (features):
    m = d.measureLine(element.geometry().asPolyline())
    L.append ((i,round(m,1)))
  return L
2

I think the version of QGis 3.0.2-1 has an issue with "measureLine". I upgrade to QGis 3.0.3-1 and the code is now working very well.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.