Skip to content

Commit

Permalink
Add failing test to ensure that QgsAbstractGeometry.centroid
Browse files Browse the repository at this point in the history
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 e55fbeb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/src/python/test_qgsgeometry.py
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@nyalldawson
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.