Skip to content

Commit e55fbeb

Browse files
committedMar 26, 2017
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
1 parent 631c7cd commit e55fbeb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed
 

‎tests/src/python/test_qgsgeometry.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,6 +4108,11 @@ def testCentroid(self):
41084108
self.assertTrue(compareWkt(result, exp, 0.00001),
41094109
"centroid: mismatch Expected:\n{}\nGot:\n{}\n".format(exp, result))
41104110

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

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

2 commit comments

Comments
 (2)

NathanW2 commented on Mar 26, 2017

@NathanW2
Member

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

nyalldawson commented on Mar 26, 2017

@nyalldawson
CollaboratorAuthor

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.