Opened 9 years ago
Last modified 9 years ago
#25498 closed Cleanup/optimization
PostGIS Distance lookups use ST_Distance_Sphere() and not ST_Distance() — at Initial Version
Reported by: | Bibhas C Debnath | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently 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.
Note:
See TracTickets
for help on using tickets.
patch to rename st_distance to st_distance_sphere