Opened 7 years ago

Last modified 5 years ago

#28738 closed New feature

Addition of PostGIS <-> operator — at Initial Version

Reported by: Matthew Somerville Owned by: nobody
Component: GIS Version: 1.11
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

https://postgis.net/docs/geometry_distance_knn.html – this function is so much quicker when looking up the nearest neighbour of an index, and it'd be great to be built into Django. For example, on a dataset of c. 1.8 million rows:

postcode = Postcode.objects
    .filter(location__distance_gte=(location, D(mi=0)))
    .distance(location)
    .order_by('distance')[0]

took 5 seconds, whereas:

postcode = Postcode.objects
    .annotate(centroid_distance=GeometryCentroidDistance('location', location))
    .filter(centroid_distance__gte=0)
    .distance(location)
    .order_by('centroid_distance')[0]

is pretty instantaneous.

(Where GeometryCentroidDistance is a Func subclass that sets function='', arg_joiner = '<-> ', output_field FloatField.)

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top