#25498: PostGIS Distance lookups use ST_Distance_Sphere() and not ST_Distance()
-------------------------------+--------------------------------------
     Reporter:  iambibhas      |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  Documentation  |                  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 iambibhas:

Old description:

> Currently
> [https://docs.djangoproject.com/en/1.8/ref/contrib/gis/geoquerysets
> /#distance-gt the doc says] that PostGIS uses `ST_Distance()` for
> distance lookups like `distance_gte` etc. But actually
> `ST_Distance_Sphere()` is used. We need to fix that on the doc.
>
> The doc also says in the beginning -
>
> {{{
>
> ... an optional third element, 'spheroid', may be included to tell
> GeoDjango to use the more accurate spheroid distance calculation
> functions on fields with a geodetic coordinate system (e.g.,
> ST_Distance_Spheroid would be used instead of ST_Distance_Sphere).
>
> }}}
>
> But then `ST_Distance_Sphere` is not mentioned anywhere else.
>
> Here is what currently is happening -
>
> {{{
> current_localities = Locality.objects.filter(centroid__distance_lte=(pnt,
> 1000))
> }}}
>
> results in -
>
> {{{
> (0.005) SELECT "map_locality"."id", "map_locality"."name",
> "map_locality"."slug", "map_locality"."centroid", "map_locality"."radius"
> FROM "map_locality" WHERE ST_Distance_Sphere("map_locality"."centroid",
> ST_GeomFromEWKB('\x0101000020e6100000865ad3bce3685340e9b7af03e7ec2940'::bytea))
> <= 1000 LIMIT 21;
> args=(<django.contrib.gis.db.backends.postgis.adapter.PostGISAdapter
> object at 0x7fdcc9d320d0>, 1000)
> }}}
>
> Attaching a patch with the issue. I can send a PR.

New description:

 Currently
 [https://docs.djangoproject.com/en/1.8/ref/contrib/gis/geoquerysets
 /#distance-gt the doc says] that PostGIS uses `ST_Distance()` for distance
 lookups like `distance_gte` etc. But actually `ST_Distance_Sphere()` is
 used. We need to fix that on the doc.

 The doc also says in the beginning -

   ... an optional third element, 'spheroid', may be included to tell
 GeoDjango to use the more accurate spheroid distance calculation functions
 on fields with a geodetic coordinate system (e.g., `ST_Distance_Spheroid`
 would be used instead of `ST_Distance_Sphere`).

 But then `ST_Distance_Sphere` is not mentioned anywhere else.

 Here is what currently is happening -

 {{{
 current_localities = Locality.objects.filter(centroid__distance_lte=(pnt,
 1000))
 }}}

 results in -

 {{{
 (0.005) SELECT "map_locality"."id", "map_locality"."name",
 "map_locality"."slug", "map_locality"."centroid", "map_locality"."radius"
 FROM "map_locality" WHERE ST_Distance_Sphere("map_locality"."centroid",
 ST_GeomFromEWKB('\x0101000020e6100000865ad3bce3685340e9b7af03e7ec2940'::bytea))
 <= 1000 LIMIT 21;
 args=(<django.contrib.gis.db.backends.postgis.adapter.PostGISAdapter
 object at 0x7fdcc9d320d0>, 1000)
 }}}

 Attaching a patch with the issue. I can send a PR.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25498#comment:2>
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/067.97738a4108a6af1e02de695d944fff1a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to