I am trying to do simple geodjango app, which contains list of shops, and when you put an address in it it returns closest shops to your location.
I am following tutorial which used PostgreSQL and Postgis, but I want to use SQLite and SpatiaLite (I want to use it later in another app which uses SQLite, so I don't know if I won't mess up, if I try to change it into PostgreSQL. I don't usually work with Python nor SQLite nor PostgreSQL)
I have a problem when I try to make a query and count the distance.
In my models.py I have:
from django.contrib.gis.db import models as gis_models
from django.contrib.gis import geos
from django.db import models
class Shop(models.Model):
name = models.CharField(max_length=200)
address = models.CharField(max_length=100)
city = models.CharField(max_length=50)
location = gis_models.PointField(u"longitude/latitude", geography=True, blank=True, null=True)
gis = gis_models.GeoManager()
objects = models.Manager()
And in views.py I have function:
def get_shops(longitude, latitude):
current_point = geos.fromstr("POINT(%s %s)" % (longitude, latitude))
distance_from_point = {'km': 10}
shops = models.Shop.gis.filter(location__distance_lte=(current_point, measure.D(**distance_from_point)))
shops = shops.distance(current_point).order_by('distance')
return shops.distance(current_point)
I get error:
SQLite does not support linear distance calculations on geodetic coordinate systems.
I've read about SRID, I guess that I should change my model. But I have no idea how to write it down. And there is a possibility that it's there is a problem with how I try to get the sorted data.