Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/new_contributor_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
steps:
- uses: actions/first-interaction@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
pr-message: |
repo_token: ${{ secrets.GITHUB_TOKEN }}
pr_message: |
Hello! Thank you for your contribution 💪

As it's your first contribution be sure to check out the [patch review checklist](https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/submitting-patches/#patch-review-checklist).
Expand Down
3 changes: 2 additions & 1 deletion django/contrib/gis/db/backends/spatialite/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):
"ForcePolygonCW": "ST_ForceLHR",
"FromWKB": "ST_GeomFromWKB",
"FromWKT": "ST_GeomFromText",
"IsEmpty": "ST_IsEmpty",
"Length": "ST_Length",
"LineLocatePoint": "ST_Line_Locate_Point",
"NumPoints": "ST_NPoints",
Expand All @@ -84,7 +85,7 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):

@cached_property
def unsupported_functions(self):
unsupported = {"GeometryDistance", "IsEmpty", "MemSize", "Rotate"}
unsupported = {"GeometryDistance", "MemSize", "Rotate"}
if not self.geom_lib_version():
unsupported |= {"Azimuth", "GeoHash", "MakeValid"}
if self.spatial_version < (5, 1):
Expand Down
4 changes: 4 additions & 0 deletions django/contrib/gis/db/models/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ class IsEmpty(GeoFuncMixin, Transform):
lookup_name = "isempty"
output_field = BooleanField()

def as_sqlite(self, compiler, connection, **extra_context):
sql, params = super().as_sql(compiler, connection, **extra_context)
return "NULLIF(%s, -1)" % sql, params


@BaseSpatialField.register_lookup
class IsValid(OracleToleranceMixin, GeoFuncMixin, Transform):
Expand Down
4 changes: 2 additions & 2 deletions docs/ref/contrib/gis/db-api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ Lookup Type PostGIS Oracle MariaDB MySQL [#]_
:lookup:`exact <same_as>` X X X X X B
:lookup:`geom_type` X X (≥ 23c) X X X
:lookup:`intersects` X X X X X B
:lookup:`isempty` X
:lookup:`isempty` X X
:lookup:`isvalid` X X X (≥ 12.0.1) X X
:lookup:`overlaps` X X X X X B
:lookup:`relate` X X X X C
Expand Down Expand Up @@ -414,7 +414,7 @@ Function PostGIS Oracle MariaDB MySQL
:class:`GeometryDistance` X
:class:`GeometryType` X X (≥ 23c) X X X
:class:`Intersection` X X X X X
:class:`IsEmpty` X
:class:`IsEmpty` X X
:class:`IsValid` X X X (≥ 12.0.1) X X
:class:`Length` X X X X X
:class:`LineLocatePoint` X X
Expand Down
7 changes: 6 additions & 1 deletion docs/ref/contrib/gis/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,16 @@ Miscellaneous

.. class:: IsEmpty(expr)

*Availability*: `PostGIS <https://postgis.net/docs/ST_IsEmpty.html>`__
*Availability*: `PostGIS <https://postgis.net/docs/ST_IsEmpty.html>`__,
SpatiaLite

Accepts a geographic field or expression and tests if the value is an empty
geometry. Returns ``True`` if its value is empty and ``False`` otherwise.

.. versionchanged:: 6.1

SpatiaLite support was added.

``IsValid``
-----------

Expand Down
7 changes: 6 additions & 1 deletion docs/ref/contrib/gis/geoquerysets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,19 @@ SpatiaLite ``Intersects(poly, geom)``
``isempty``
-----------

*Availability*: `PostGIS <https://postgis.net/docs/ST_IsEmpty.html>`__
*Availability*: `PostGIS <https://postgis.net/docs/ST_IsEmpty.html>`__,
SpatiaLite

Tests if the geometry is empty.

Example::

Zipcode.objects.filter(poly__isempty=True)

.. versionchanged:: 6.1

SpatiaLite support was added.

.. fieldlookup:: isvalid

``isvalid``
Expand Down
4 changes: 3 additions & 1 deletion docs/releases/6.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ Minor features
:mod:`django.contrib.gis`
~~~~~~~~~~~~~~~~~~~~~~~~~

* ...
* The :lookup:`isempty` lookup and
:class:`IsEmpty() <django.contrib.gis.db.models.functions.IsEmpty>`
database function are now supported on SpatiaLite.

:mod:`django.contrib.messages`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
14 changes: 13 additions & 1 deletion tests/gis_tests/geoapp/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def test_intersection(self):
self.assertIs(c.inter.empty, True)

@skipUnlessDBFeature("supports_empty_geometries", "has_IsEmpty_function")
def test_isempty(self):
def test_isempty_geometry_empty(self):
empty = City.objects.create(name="Nowhere", point=Point(srid=4326))
City.objects.create(name="Somewhere", point=Point(6.825, 47.1, srid=4326))
self.assertSequenceEqual(
Expand All @@ -442,6 +442,18 @@ def test_isempty(self):
)
self.assertSequenceEqual(City.objects.filter(point__isempty=True), [empty])

@skipUnlessDBFeature("has_IsEmpty_function")
def test_isempty_geometry_null(self):
nowhere = State.objects.create(name="Nowhere", poly=None)
qs = State.objects.annotate(isempty=functions.IsEmpty("poly"))
self.assertSequenceEqual(qs.filter(isempty=None), [nowhere])
self.assertSequenceEqual(
qs.filter(isempty=False).order_by("name").values_list("name", flat=True),
["Colorado", "Kansas"],
)
self.assertSequenceEqual(qs.filter(isempty=True), [])
self.assertSequenceEqual(State.objects.filter(poly__isempty=True), [])

@skipUnlessDBFeature("has_IsValid_function")
def test_isvalid(self):
valid_geom = fromstr("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))")
Expand Down
Loading