[Django] #30649: Implement geometry validation in GIS database backend

22 views
Skip to first unread message

Django

unread,
Jul 18, 2019, 11:10:41 AM7/18/19
to django-...@googlegroups.com
#30649: Implement geometry validation in GIS database backend
---------------------------------------+------------------------
Reporter: milosu | Owner: nobody
Type: New feature | Status: new
Component: GIS | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------+------------------------
PostGIS provides function ST_MakeValid, that can be used in Django as a
PostGISOperator.

There is however now way how to use ST_MakeValid to simply repair GEOS
Geometry.

Note that there is also now comparable function in the GEOS library itself
(not counting something simple like buffer(0)).

This missing feature is also subject to Stackoverflow questions, like:
https://stackoverflow.com/questions/45631855/equivalent-of-postgis-st-
makevalid-in-django-geos/45633779

Attached patch implements new PostGISOperations method called
"make_valid", that can be run from implementation code simply by:

{{{
from django.db import connection

repaired_geos_geometry = connection.ops.make_valid(some_goes_geometry)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30649>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 18, 2019, 11:11:25 AM7/18/19
to django-...@googlegroups.com
#30649: Implement geometry validation in GIS database backend
-----------------------------+--------------------------------------

Reporter: milosu | Owner: nobody
Type: New feature | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by milosu):

* Attachment "make_valid_patch.diff" added.

Django

unread,
Jul 18, 2019, 11:12:09 AM7/18/19
to django-...@googlegroups.com
#30649: Implement geometry validation in GIS database backend
-----------------------------+--------------------------------------

Reporter: milosu | Owner: nobody
Type: New feature | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Description changed by milosu:

Old description:

> PostGIS provides function ST_MakeValid, that can be used in Django as a
> PostGISOperator.
>
> There is however now way how to use ST_MakeValid to simply repair GEOS
> Geometry.
>
> Note that there is also now comparable function in the GEOS library
> itself (not counting something simple like buffer(0)).
>
> This missing feature is also subject to Stackoverflow questions, like:
> https://stackoverflow.com/questions/45631855/equivalent-of-postgis-st-
> makevalid-in-django-geos/45633779
>
> Attached patch implements new PostGISOperations method called
> "make_valid", that can be run from implementation code simply by:
>
> {{{
> from django.db import connection
>
> repaired_geos_geometry = connection.ops.make_valid(some_goes_geometry)
> }}}

New description:

PostGIS provides function ST_MakeValid, that can be used in Django as a
PostGISOperator.

There is however no way how to use ST_MakeValid to simply repair GEOS
Geometry.

Note that there is also now comparable function in the GEOS library itself
(not counting something simple like buffer(0)).

This missing feature is also subject to Stackoverflow questions, like:
https://stackoverflow.com/questions/45631855/equivalent-of-postgis-st-
makevalid-in-django-geos/45633779

Attached patch implements new PostGISOperations method called
"make_valid", that can be run from implementation code simply by:

{{{
from django.db import connection

repaired_geos_geometry = connection.ops.make_valid(some_goes_geometry)
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30649#comment:1>

Django

unread,
Jul 18, 2019, 11:12:37 AM7/18/19
to django-...@googlegroups.com
#30649: Implement geometry validation in GIS database backend
-----------------------------+--------------------------------------

Reporter: milosu | Owner: nobody
Type: New feature | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Description changed by milosu:

Old description:

> PostGIS provides function ST_MakeValid, that can be used in Django as a
> PostGISOperator.
>
> There is however no way how to use ST_MakeValid to simply repair GEOS


> Geometry.
>
> Note that there is also now comparable function in the GEOS library
> itself (not counting something simple like buffer(0)).
>
> This missing feature is also subject to Stackoverflow questions, like:
> https://stackoverflow.com/questions/45631855/equivalent-of-postgis-st-
> makevalid-in-django-geos/45633779
>
> Attached patch implements new PostGISOperations method called
> "make_valid", that can be run from implementation code simply by:
>
> {{{
> from django.db import connection
>
> repaired_geos_geometry = connection.ops.make_valid(some_goes_geometry)
> }}}

New description:

PostGIS provides function ST_MakeValid, that can be used in Django as a
PostGISOperator.

There is however no way how to use ST_MakeValid to simply repair GEOS
Geometry.

Note that there is also no comparable function in the GEOS library itself


(not counting something simple like buffer(0)).

This missing feature is also subject to Stackoverflow questions, like:
https://stackoverflow.com/questions/45631855/equivalent-of-postgis-st-
makevalid-in-django-geos/45633779

Attached patch implements new PostGISOperations method called
"make_valid", that can be run from implementation code simply by:

{{{
from django.db import connection

repaired_geos_geometry = connection.ops.make_valid(some_goes_geometry)
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30649#comment:2>

Django

unread,
Jul 18, 2019, 11:44:09 AM7/18/19
to django-...@googlegroups.com
#30649: Implement geometry validation in GIS database backend.
-----------------------------+--------------------------------------
Reporter: milosu | Owner: nobody
Type: New feature | Status: closed
Component: GIS | Version: master
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => invalid


Comment:

[https://docs.djangoproject.com/en/2.2/ref/contrib/gis/functions/#django.contrib.gis.db.models.functions.MakeValid
MakeValid] is already implemented.

--
Ticket URL: <https://code.djangoproject.com/ticket/30649#comment:3>

Django

unread,
Jul 18, 2019, 12:58:06 PM7/18/19
to django-...@googlegroups.com
#30649: Implement geometry validation in GIS database backend.
-----------------------------+--------------------------------------

Reporter: milosu | Owner: nobody
Type: New feature | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by milosu):

* status: closed => new
* resolution: invalid =>


Comment:

St_MakeValid is implemented, but there is no way to use it to call it on
GEOS geometry.
See e.g.
https://stackoverflow.com/questions/45631855/equivalent-of-postgis-st-
makevalid-in-django-geos/45633779

--
Ticket URL: <https://code.djangoproject.com/ticket/30649#comment:4>

Django

unread,
Jul 18, 2019, 2:18:24 PM7/18/19
to django-...@googlegroups.com
#30649: Implement geometry validation in GIS database backend.
-----------------------------+--------------------------------------

Reporter: milosu | Owner: nobody
Type: New feature | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------

Comment (by Simon Charette):

The `MakeValid` function also supports `Geometry` objects so you could
theoretically do

{{{#!python
valid_geometry = AModel.objects.annotate(
valid_geometry=MakeValid(invalid_geometry),
).values_list('valid_geometry', flat=True).first()
}}}

But that assumes `AModel` has at least one row.

The ORM doesn't support `SELECT` from no tables by it's table <-> model
class mapping nature.

If we wanted to add a way to do that it we should do it for all non-column
referencing expressions and not only for `MakeValid`.

e.g.

- `Expression.from_db()`
- `MakeValid(invalid_geometry).from_db('other')`
- `Unaccent(Lower('ÉtÉ')).from_db()`

This would have to be discussed on the developer mailing list and I
wouldn't be surprised if there was existing tickets tracking this feature
request.

--
Ticket URL: <https://code.djangoproject.com/ticket/30649#comment:5>

Django

unread,
Jul 19, 2019, 12:37:30 AM7/19/19
to django-...@googlegroups.com
#30649: Implement MakeValid() for non-column values.
-----------------------------+--------------------------------------
Reporter: milosu | Owner: nobody
Type: New feature | Status: closed
Component: GIS | Version: master
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by felixxm):

* status: new => closed

* resolution: => wontfix


Comment:

If you want to propose to add a new API for all non-column expressions (as
described by Simon) then please fill a new ticket (I couldn't find an
existing ticket) that would have to be discussed on the developer mailing
list.

IMO, adding a special behavior only for `MakeValid()` is not something
that we would like to add into Django.

--
Ticket URL: <https://code.djangoproject.com/ticket/30649#comment:6>

Reply all
Reply to author
Forward
0 new messages