python - GeoDjango distance query with srid 4326 returns 'SpatiaLite does not support distance queries on geometry fields with a geodetic coordinate system.' -
i'm trying fetch nearby kitchens, within 4 km radius given lat/long. spatial backend spatialite , settings are,
installed_apps = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.gis', 'rest_framework', 'oauth2_provider', 'kitchen', ) databases = { 'default': { 'engine': 'django.contrib.gis.db.backends.spatialite', 'name': os.path.join(base_dir, 'db.sqlite3'), } }
here model
django.contrib.gis.db import models django.contrib.gis.geos import point class kitchen(models.model): id = models.charfield(max_length=100,primary_key=true) #id = models.autofield(primary_key=true) name = models.charfield(max_length=100,blank=false) address = models.charfield(max_length=1000, blank=true, default='') contact_no = models.charfield(max_length=100,blank=true, default='') location = models.pointfield(srid=4326, geography=true, blank=true, null=true) objects = models.geomanager()
my query django shell is,
kitchen.models import kitchen django.contrib.gis import measure django.contrib.gis import geos current_point = geos.fromstr('point(%s %s)' % (76.7698996, 17.338993), srid=4326) kitchen.objects.filter(location__distanc e_lte=(current_point, measure.d(km=4)))
which return below value error,
spatialite not support distance queries on geometry fields geodetic coordinate system. distance objects; use numeric value of distance in degrees instead.
setting different projected srid in model(ex. 3857, 24381 etc) returns incorrect results. here appreciated.
most problem srid. seems spatialite not support type of distance query on fields unprojected coordinate systems.
so on right track, setting srid different value have no effect long have geography=true
enabled in model definition. geography type forces srid 4326, described in django geography docs.
so try setting geography=false
, srid 1 of projected coordinate systems trying out.
Comments
Post a Comment