﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25498	PostGIS Distance lookups use ST_Distance_Sphere() and not ST_Distance()	Bibhas C Debnath	nobody	"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.
"	Cleanup/optimization	closed	Documentation	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
