1
0
mirror of https://github.com/django/django.git synced 2024-12-22 09:05:43 +00:00

Refs #35783 -- Added NumDimensions geographic database function.

This commit is contained in:
David Smith 2024-12-01 10:25:07 +00:00
parent 3b7c018ceb
commit c26c6f8803
4 changed files with 33 additions and 2 deletions

View File

@ -491,7 +491,9 @@ class MemSize(GeoFunc):
arity = 1
class NumDimensions(GeoFunc):
@BaseSpatialField.register_lookup
class NumDimensions(GeoFuncMixin, Transform):
lookup_name = "num_dimensions"
output_field = IntegerField()
arity = 1

View File

@ -361,6 +361,7 @@ Lookup Type PostGIS Oracle MariaDB MySQL [#]_ S
:lookup:`intersects` X X X X X B
:lookup:`isempty` X
:lookup:`isvalid` X X X (≥ 11.7) X X
:lookup:`num_dimensions` X X
:lookup:`overlaps` X X X X X B
:lookup:`relate` X X X X C
:lookup:`same_as` X X X X X B

View File

@ -395,6 +395,29 @@ Oracle ``SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(p
MariaDB 11.7+ support was added.
.. fieldlookup:: num_dimensions
``num_dimensions``
------------------
.. versionadded:: 5.2
*Availability*: `PostGIS <https://postgis.net/docs/ST_NDims.html>`__,
SpatiaLite
Returns the number of dimensions used by the geometry.
Example::
Zipcode.objects.filter(geom__num_dimensions=3)
=================== ==================
Backend SQL Equivalent
=================== ==================
PostGIS, SpatiaLite ``ST_NDims(poly)``
=================== ==================
.. fieldlookup:: overlaps
``overlaps``

View File

@ -7,7 +7,7 @@ from django.contrib.gis.db.models import GeometryField, PolygonField, functions
from django.contrib.gis.geos import GEOSGeometry, LineString, Point, Polygon, fromstr
from django.contrib.gis.measure import Area
from django.db import NotSupportedError, connection
from django.db.models import IntegerField, Sum, Value
from django.db.models import F, IntegerField, Sum, Value
from django.test import TestCase, skipUnlessDBFeature
from ..utils import FuncTestMixin
@ -597,6 +597,11 @@ class GISFunctionsTests(FuncTestMixin, TestCase):
)
self.assertEqual(qs[0].num_dims, 3)
qs = ThreeDimensionalFeature.objects.annotate(
num_dims=F("geom__num_dimensions")
)
self.assertEqual(qs[0].num_dims, 3)
msg = "'NumDimensions' takes exactly 1 argument (2 given)"
with self.assertRaisesMessage(TypeError, msg):
Country.objects.annotate(num_dims=functions.NumDimensions("point", "error"))