(Where GeometryCentroidDistance is a Func subclass that sets`
function=''`, `arg_joiner = '<-> '`, output_field FloatField.)
--
Ticket URL: <https://code.djangoproject.com/ticket/28738>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old 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.)
New 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.)
(There is also `<#>` https://postgis.net/docs/geometry_distance_box.html)
--
--
Ticket URL: <https://code.djangoproject.com/ticket/28738#comment:1>
Comment (by Tim Graham):
Based on your description, I can't tell whether this is different from the
[https://github.com/django/django/blob/d1317edad0a2908574d2a5b07383bfe58884628c/django/contrib/postgres/search.py#L217-L219
TrigramDistance] function?
--
Ticket URL: <https://code.djangoproject.com/ticket/28738#comment:2>
Comment (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.
--
Ticket URL: <https://code.djangoproject.com/ticket/28738#comment:3>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/28738#comment:4>
* owner: nobody => franciscouzo
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/28738#comment:5>
* has_patch: 0 => 1
* stage: Accepted => Ready for checkin
Comment:
[https://github.com/django/django/pull/11091 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/28738#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"0193bf874f08f21cdec628b8d80d261471bfe5fc" 0193bf8]:
{{{
#!CommitTicketReference repository=""
revision="0193bf874f08f21cdec628b8d80d261471bfe5fc"
Fixed #28738 -- Added the GeometryDistance function.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28738#comment:7>