Sunday 7 August 2016

geometry - Calculate length of selected features in PyQGIS



I create a selection with getFeatures(QgsFeatureRequest()) and I want to calculate the length of the result which is a QgsFeatureIterator :


select = QgsExpression(" myexpression ")
selectedfeats = layer.getFeatures(QgsFeatureRequest(select ))

total = 0
for feature in selectedfeats :
geom = feature.geometry()
total += geom.length()

But it doesn't work it returns 0 whereas the selectedfeats is not empty.





No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...