If you use just QgsDistanceArea.measureLength(feat)
, you get an error: first argument of unbound method must have type 'QgsDistanceArea'
. That means you need to create an object of QgsDistanceArea
d = QgsDistanceArea()
Then you need to set ellipsoid. Use QgsEllipsoidUtils::acronyms()
to get a list of all known ellipsoid acronyms. If you don't set ellipsoid, calculations will be performed in plane geometry.
d.setEllipsoid('WGS84')
Then you can use measureLength
to get the length of the line on ellipsoid. Normally the measurement is in meters.
measure = d.measureLength(feat.geometry())
Or you can use measureLine
method instead of measureLength
.
measure = d.measureLine(feat.geometry().asPolyline())
# If geometry type is multipolyline
measure = d.measureLine(feat.geometry().asMultiPolyline()[0])
For more information, please review QgsDistanceArea documentation.