Skip to content

Commit 45f59d0

Browse files
smithdc1felixxm
authored andcommitted
Fixed #35086 -- Added support for BoundedCircle on Spatialite 5.1+.
Spatialite 5.1 added support for BoundingCircle (GEOSMinimumBoundingCircle). GEOS 3.7 is required which is lower than Django's currently supported minmum of 3.8. https://groups.google.com/g/spatialite-users/c/hAJ2SgitN4M https://www.gaia-gis.it/gaia-sins/spatialite-sql-5.1.0.html
1 parent 9b056aa commit 45f59d0

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

django/contrib/gis/db/backends/spatialite/operations.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):
6666

6767
function_names = {
6868
"AsWKB": "St_AsBinary",
69+
"BoundingCircle": "GEOSMinimumBoundingCircle",
6970
"ForcePolygonCW": "ST_ForceLHR",
7071
"FromWKB": "ST_GeomFromWKB",
7172
"FromWKT": "ST_GeomFromText",
@@ -80,9 +81,11 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):
8081

8182
@cached_property
8283
def unsupported_functions(self):
83-
unsupported = {"BoundingCircle", "GeometryDistance", "IsEmpty", "MemSize"}
84+
unsupported = {"GeometryDistance", "IsEmpty", "MemSize"}
8485
if not self.geom_lib_version():
8586
unsupported |= {"Azimuth", "GeoHash", "MakeValid"}
87+
if self.spatial_version < (5, 1):
88+
unsupported |= {"BoundingCircle"}
8689
return unsupported
8790

8891
@cached_property

django/contrib/gis/db/models/functions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ def as_oracle(self, compiler, connection, **extra_context):
274274
compiler, connection, **extra_context
275275
)
276276

277+
def as_sqlite(self, compiler, connection, **extra_context):
278+
clone = self.copy()
279+
clone.set_source_expressions([self.get_source_expressions()[0]])
280+
return super(BoundingCircle, clone).as_sqlite(
281+
compiler, connection, **extra_context
282+
)
283+
277284

278285
class Centroid(OracleToleranceMixin, GeomOutputGeoFunc):
279286
arity = 1

docs/ref/contrib/gis/db-api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ Function PostGIS Oracle MariaDB MySQL
397397
:class:`AsWKB` X X X X X
398398
:class:`AsWKT` X X X X X
399399
:class:`Azimuth` X X (LWGEOM/RTTOPO)
400-
:class:`BoundingCircle` X X
400+
:class:`BoundingCircle` X X X (≥ 5.1)
401401
:class:`Centroid` X X X X X
402402
:class:`ClosestPoint` X X
403403
:class:`Difference` X X X X X

docs/ref/contrib/gis/functions.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,18 @@ south = ``π``; west = ``3π/2``.
230230

231231
*Availability*: `PostGIS <https://postgis.net/docs/ST_MinimumBoundingCircle.html>`__,
232232
`Oracle <https://docs.oracle.com/en/database/oracle/oracle-database/21/spatl/
233-
SDO_GEOM-reference.html#GUID-82A61626-BB64-4793-B53D-A0DBEC91831A>`_
233+
SDO_GEOM-reference.html#GUID-82A61626-BB64-4793-B53D-A0DBEC91831A>`_,
234+
SpatiaLite 5.1+
234235

235236
Accepts a single geographic field or expression and returns the smallest circle
236237
polygon that can fully contain the geometry.
237238

238239
The ``num_seg`` parameter is used only on PostGIS.
239240

241+
.. versionchanged:: 5.1
242+
243+
SpatiaLite 5.1+ support was added.
244+
240245
``Centroid``
241246
============
242247

docs/releases/5.1.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ Minor features
5353
:mod:`django.contrib.gis`
5454
~~~~~~~~~~~~~~~~~~~~~~~~~
5555

56-
* ...
56+
* :class:`~django.contrib.gis.db.models.functions.BoundingCircle` is now
57+
supported on SpatiaLite 5.1+.
5758

5859
:mod:`django.contrib.messages`
5960
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tests/gis_tests/geoapp/test_functions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,12 @@ def circle_num_points(num_seg):
258258
# num_seg is the number of segments per quarter circle.
259259
return (4 * num_seg) + 1
260260

261-
expected_areas = (169, 136) if connection.ops.postgis else (171, 126)
261+
if connection.ops.postgis:
262+
expected_areas = (169, 136)
263+
elif connection.ops.spatialite:
264+
expected_areas = (168, 135)
265+
else: # Oracle.
266+
expected_areas = (171, 126)
262267
qs = Country.objects.annotate(
263268
circle=functions.BoundingCircle("mpoly")
264269
).order_by("name")

0 commit comments

Comments
 (0)