Skip to content
Permalink
Browse files
Add failing test to ensure that QgsAbstractGeometry.centroid
result matches that of GEOS

It doesn't, and reveals the the QGIS native centroid calculation
is quite broken
  • Loading branch information
nyalldawson committed Mar 26, 2017
1 parent 631c7cd commit e55fbebf680bfdce8bb2709493f1f92c2922f900
Showing with 5 additions and 0 deletions.
  1. +5 −0 tests/src/python/test_qgsgeometry.py
@@ -4108,6 +4108,11 @@ def testCentroid(self):
self.assertTrue(compareWkt(result, exp, 0.00001),
"centroid: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result))

# QGIS native algorithms are bad!
if False:
result = QgsGeometry(input.geometry().centroid()).exportToWkt()
self.assertTrue(compareWkt(result, exp, 0.00001),
"centroid: mismatch using QgsAbstractGeometry methods Input {} \n Expected:\n{}\nGot:\n{}\n".format(t[0], exp, result))

if __name__ == '__main__':
unittest.main()

2 comments on commit e55fbeb

@NathanW2

This comment has been minimized.

Copy link
Member

@NathanW2 NathanW2 replied Mar 26, 2017

Ouch. Why are they wrong. I thought we used GEOS for that.

@nyalldawson

This comment has been minimized.

Copy link
Collaborator Author

@nyalldawson nyalldawson replied Mar 26, 2017

If you call QgsGeometry::centroid it uses GEOS. But QgsAbstractGeometry has some native centroid methods, so calling .geometry().centroid() gives a different (wrong) result.

Please sign in to comment.