Opened 16 months ago

Last modified 16 months ago

#28738 new New feature

Add support for PostGIS <-> operator

Reported by: Matthew Somerville Owned by: nobody
Component: GIS Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Matthew Somerville) – 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)))

took 5 seconds, whereas:

postcode = Postcode.objects
    .annotate(centroid_distance=GeometryCentroidDistance('location', location))

is pretty instantaneous.

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

(There is also <#>

Change History (4)

comment:1 Changed 16 months ago by Matthew Somerville

Description: modified (diff)

comment:2 Changed 16 months ago by Tim Graham

Summary: Addition of PostGIS <-> operatorAdd support for PostGIS <-> operator

Based on your description, I can't tell whether this is different from the TrigramDistance function?

comment:3 Changed 16 months ago by Matthew Somerville

The operator itself is the same, but the trigram code takes a string (which will be passed to Value() if not already a Value, so passed in strings aren't F() by default), whereas this operator would want to be a GeoFunc (a bit like Distance, I guess? Its return is the same as ST_Distance) taking geometries/expressions, transforming them to the same SRID and so on.

comment:4 Changed 16 months ago by Tim Graham

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