Opened 17 years ago
Closed 16 years ago
#6715 closed (fixed)
Use `ST_distance_sphere` as default instead of `ST_distance_spheroid` for geodetic distance calculations.
Reported by: | jbronn | Owned by: | jbronn |
---|---|---|---|
Component: | GIS | Version: | gis |
Severity: | Keywords: | gis distance geodetic geographic sphere spheroid | |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
As brought up by kmishler in this django-users thread about GeoDjango geodetic distances, ST_distance_sphere
performs faster than ST_distance_spheroid
. My informal tests suggest that using ST_distance_sphere
yields results ~30-40% faster that are a maximum of 0.25% less accurate.
The attached patch changes the default to ST_distance_sphere
-- spheroid calculations may be enabled by setting the distance_spheroid
keyword to True
in the geographic model definition (e.g., point = models.PointField(distance_spheroid=True)
). I haven't committed this yet because I wanted to solicit comments on whether there's a better way to do this.
Attachments (1)
Change History (4)
comment:1 by , 17 years ago
Status: | new → assigned |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 17 years ago
Needs tests: | set |
---|
by , 17 years ago
Attachment: | distance_sphere.diff added |
---|
comment:3 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixed in r7641. ST_distance_sphere
is used by default. However, the mechanism to use ST_distance_spheroid
is more dynamic than the original solution in the patch attached to this ticket.
For the distance lookup types the following syntax will enable spheroid calculations:
qs = City.objects.filter(point__distance_lte=(pnt, D(km=5), 'spheroid'))
When using GeoQuerySet
distance method, the spheroid keyword just needs to be set:
qs = City.objects.distance(pnt, spheroid=True)
Patch for using ST_distance_sphere by default.