The distance object you have is a
If you have a look at the docs, the
distance.lengthUnits() method returns a
QgsUnitTypes.DistanceUnit code. QgsUnitTypes.DistanceUnit is an enum, that is, it has codes for each of its values.
You can get the value corresponding to certain code, i.e., the display string for the units in this way:
QgsUnitTypes.toString(6) # degrees
You'll get the same using this recommended way:
QgsUnitTypes.toString(distance.lengthUnits()) # degrees
Of course, you can also find the method
toString() in the docs.
NOTE: You can tell the
QgsDistanceArea object the CRS you want to use.
If you have the EPSG code, do something like this:
crs = QgsCoordinateReferenceSystem(2272, QgsCoordinateReferenceSystem.EpsgCrsId)
If you have a layer object with a CRS set, do something like this:
Next time you ask for length units, you'll get those defined in the CRS you passed to the