Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SRID4326的GeoDjango距离查询返回';SpatiaLite不支持对具有大地坐标系的几何体字段进行距离查询;_Python_Django_Sqlite_Geodjango_Spatialite - Fatal编程技术网

Python SRID4326的GeoDjango距离查询返回';SpatiaLite不支持对具有大地坐标系的几何体字段进行距离查询;

Python SRID4326的GeoDjango距离查询返回';SpatiaLite不支持对具有大地坐标系的几何体字段进行距离查询;,python,django,sqlite,geodjango,spatialite,Python,Django,Sqlite,Geodjango,Spatialite,我正试着去附近的厨房,在距离给定lat/long半径4公里的范围内。 我的spatial后端是spatialite,设置是 INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contr

我正试着去附近的厨房,在距离给定lat/long半径4公里的范围内。 我的spatial后端是spatialite,设置是

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'),
    }
}
这是我的模型

from django.contrib.gis.db import models
from 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()
Django shell的问题是

from kitchen.models import Kitchen
from django.contrib.gis import measure
from django.contrib.gis import geos

current_point = geos.fromstr('POINT(%s %s)' % (76.7698996, 17.338993), srid=4326)
Kitchen.objects.filter(location__distance_lte=(current_point, measure.D(km=4)))
返回下面的值错误

SpatiaLite does not support distance queries on geometry fields with a geodetic coordinate system. Distance objects; use a numeric value of your distance in degrees instead.
在模型中设置不同的预计srid(例如3857、24381等)会返回不正确的结果。
非常感谢您的帮助。

您的问题很可能是SRID。spatialite似乎不支持对具有未投影坐标系的字段进行这种类型的距离查询

因此,您的做法是正确的,但只要在模型定义中启用了
geography=True
,将srid设置为其他值将不会产生任何效果。地理类型强制srid为4326,如中所述


因此,请尝试将
geography=False
和srid设置为您正在尝试的投影坐标系之一。

如果
srid=3857,geography=False
,则返回的结果不正确(所有厨房)。