Opened 16 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)

distance_sphere.diff (10.0 KB ) - added by jbronn 16 years ago.
Patch for using ST_distance_sphere by default.

Download all attachments as: .zip

Change History (4)

comment:1 by jbronn, 16 years ago

Status: newassigned
Triage Stage: UnreviewedDesign decision needed

comment:2 by jbronn, 16 years ago

Needs tests: set

by jbronn, 16 years ago

Attachment: distance_sphere.diff added

Patch for using ST_distance_sphere by default.

comment:3 by jbronn, 16 years ago

Resolution: fixed
Status: assignedclosed

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)
Note: See TracTickets for help on using tickets.
Back to Top