#25446: Can't use PostGIS function ST_OrderingEquals with GeoDjango
-----------------------------+--------------------------------------
     Reporter:  ezheidtmann  |                    Owner:  nobody
         Type:  Bug          |                   Status:  new
    Component:  GIS          |                  Version:  1.8
     Severity:  Normal       |               Resolution:
     Keywords:               |             Triage Stage:  Unreviewed
    Has patch:  0            |      Needs documentation:  0
  Needs tests:  0            |  Patch needs improvement:  0
Easy pickings:  0            |                    UI/UX:  0
-----------------------------+--------------------------------------
Changes (by ezheidtmann):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Old description:

> Unless I'm missing something, Django 1.8 provides no facility in the ORM
> to use the ST_OrderingEquals() function to compare two geometries. I
> would like to use this function in a query.
>
> Am I correct? If so, I may attempt a patch or at least a workaround.
>
> Thanks!
>
> Ref: http://postgis.net/docs/manual-1.3/ch06.html#ST_OrderingEquals

New description:

 Unless I'm missing something, Django 1.8 provides no facility in the ORM
 to use the ST_OrderingEquals() function to compare two geometries. I would
 like to use this function in a query.

 Am I correct? If so, I may attempt a patch or at least a workaround.

 Thanks!

 Ref: http://postgis.net/docs/manual-1.3/ch06.html#ST_OrderingEquals

 P.S. It's another question entirely whether the '__exact' lookup should
 use this function. For comparison, two LineString objects with opposite
 vertex ordering are not considered equal, so why should they be considered
 equal at the DB level?

--

Comment:

 For other users who may find this, here's my workaround that allows me to
 find the geometry that matches an input geometry, both in vertex values
 and in vertex ordering. A Django wizard may be able to improve this and I
 would welcome any criticism.

 {{{
 class SegmentModel(models.Model):
     ...

     @classmethod
     def get_or_create_for_line(cls, line):
         from django.contrib.gis.db.backends.postgis.adapter import
 PostGISAdapter

         sql = 'SELECT * FROM ride_segment WHERE line ~= {line_serialized}
 AND ST_OrderingEquals(line, {line_serialized})'.format(
             line_serialized=str(PostGISAdapter(line)))

         segments = list(cls.objects.raw(sql))

         if len(segments) > 1:
             from django.db import IntegrityError
             raise IntegrityError('Multiple segments for line
 {}'.format(line.ewkt))
         elif len(segments) == 0:
             return (True, cls.objects.create(line=line))
         else:
             return (False, segments[0])

 }}}

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.08166c2bbd81d15fbb24524928cd0d0c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to