1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +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

@@ -565,6 +565,14 @@ class OGRGeometry(GDALBase):
"""
return self._geomgen(capi.geom_union, other)
@property
def centroid(self):
"""Return the centroid (a Point) of this Polygon."""
# The centroid is a Point, create a geometry for this.
p = OGRGeometry(OGRGeomType("Point"))
capi.get_centroid(self.ptr, p.ptr)
return p
# The subclasses for OGR Geometry.
class Point(OGRGeometry):
@@ -708,14 +716,6 @@ class Polygon(OGRGeometry):
# Summing up the number of points in each ring of the Polygon.
return sum(self[i].point_count for i in range(self.geom_count))
@property
def centroid(self):
"Return the centroid (a Point) of this Polygon."
# The centroid is a Point, create a geometry for this.
p = OGRGeometry(OGRGeomType("Point"))
capi.get_centroid(self.ptr, p.ptr)
return p
# Geometry Collection base class.
class GeometryCollection(OGRGeometry):