1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Refs #35058 -- Made centroid available on all geometry types.

Centroid is available on all geometry types since GDAL 1.8.0.
Previously it was restricted to Polygon.

https://gdal.org/doxygen/classOGRGeometry.html#a91787f669b2a148169667e270e7e40df
This commit is contained in:
David Smith
2024-01-28 08:41:25 +00:00
committed by Mariusz Felisiak
parent 9c6d7b4a67
commit 2005530920
4 changed files with 43 additions and 12 deletions

View File

@@ -877,6 +877,29 @@ class OGRGeomTest(SimpleTestCase, TestDataMixin):
geom = OGRGeometry("POINT M (1 2 3)")
self.assertEqual(geom.geos.wkt, "POINT (1 2)")
def test_centroid(self):
point = OGRGeometry("POINT (1 2 3)")
self.assertEqual(point.centroid.wkt, "POINT (1 2)")
linestring = OGRGeometry("LINESTRING (0 0 0, 1 1 1, 2 2 2)")
self.assertEqual(linestring.centroid.wkt, "POINT (1 1)")
polygon = OGRGeometry("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))")
self.assertEqual(polygon.centroid.wkt, "POINT (5 5)")
multipoint = OGRGeometry("MULTIPOINT (0 0,10 10)")
self.assertEqual(multipoint.centroid.wkt, "POINT (5 5)")
multilinestring = OGRGeometry(
"MULTILINESTRING ((0 0,0 10,0 20),(10 0,10 10,10 20))"
)
self.assertEqual(multilinestring.centroid.wkt, "POINT (5 10)")
multipolygon = OGRGeometry(
"MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0)),"
"((20 20, 20 30, 30 30, 30 20, 20 20)))"
)
self.assertEqual(multipolygon.centroid.wkt, "POINT (15 15)")
geometrycollection = OGRGeometry(
"GEOMETRYCOLLECTION (POINT (110 260),LINESTRING (110 0,110 60))"
)
self.assertEqual(geometrycollection.centroid.wkt, "POINT (110 30)")
class DeprecationTests(SimpleTestCase):
def test_coord_setter_deprecation(self):