Bug report #12406
QgsDistanceArea.measure(geometry) - for Polygons in WGS84
|Affected QGIS version:||2.8.0||Regression?:||No|
|Operating System:||Windows||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:||fixed/implemented|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||20579|
This is since Version 2.8 (newer i dont know). The Method measures something but the Nummber is extremly tiny. And there for wrong!
If you project it to a CooRdinateSystem somewhere in the world it would measure something nearly correctly (because of the incorrect projection). But this could not be a workaround... if you need the whole world.
Fix #12406 (measured area is wrong when computed on ellipsoid)
Introduced in e568493
#2 Updated by Martin Dobias over 4 years ago
Could you paste a snipped of code where you use QgsDistanceArea? I assume you didn't enable ellipsoid mode, so the measurements you get are using Euclidean distance on your coordinates. You probably want to do something like this:
d = QgsDistanceArea() d.setEllipsoidalMode(True) d.setEllipsoid("WGS84") d.measure(QgsGeometry.fromPolyline([QgsPoint(0,0),QgsPoint(1,0)]))
#3 Updated by Jens Deutschmann over 4 years ago
Here is a snipped, but i dont think its that Problem because in QGIS 2.6 it all works well!? And i think i enabled it this way....
def analyzeGeometry(self, geometry, layer, info):
crs = QgsCoordinateReferenceSystem(layer.dataProvider().crs())
calculator = QgsDistanceArea()
elif geometry.type() == QGis.Polygon:
self.add(info, 'num_polygons', 1)
self.add(info, 'tot_poly_area', int(calculator.measure(geometry)/1000000))
self.add(info, 'tot_poly_perimeter', int(calculator.measurePerimeter(geometry)/1000))