I want to have a radius based distance search. To do this, I want to create a buffer around a point object in order to filter objects that are inside it.
Here is where I am at with it:
>>> lat = 37.7762179974
>>> lon = -122.411562492
>>> from django.contrib.gis.geos import Point
>>> pnt = Point(lat, lon)
>>> buf = pnt.buffer(0.0001)
But I am having problems filtering the Thing
objects based on whether they are inside the buffer:
>>> z = Thing.objects.filter(pnt__intersects=buf)
(I know that the above is incorrect, but I use it to elaborate what I am trying to do.)
How can I create a buffer around the Point
and then filter Things
that are inside the buffer
?
EDIT: models.py
class Thing(models.Model):
lat = models.FloatField()
lon = models.FloatField()
How can I filter based on a point comprised of a combination of these two model fields?
This cannot work obviously, because I do not have a pnt
field in my model:
>>> pnt = Point(lat, lon)
>>> z = Thing.objects.filter(pnt__intersects=buf)
But how can I do something similar?