GeoDjango distance query with srid 4326 returns 'SpatiaLite does not support distance queries on geometry fields with a geodetic coordinate system.'
<p>I'm trying to fetch nearby kitchens, within 4 km radius from a given lat/long.
My spatial backend is spatialite and settings are,</p>

<pre>

    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'),
        }
    }

</pre>

<p>Here is my model</p>

<pre>

    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()

</pre>

<p>My query from Django shell is,</p>

<pre>

    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__distanc

e_lte=(current_point, measure.D(km=4)))
</pre>

<p>which return the below <strong>Value Error</strong>,</p>

<pre>

    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.

</pre>

<p>Setting a different projected srid in the model(ex. 3857, 24381 etc) returns incorrect results. 
Some help here would be greatly appreciated. </p>

<p>Most likely your problem is the SRID. It seems like spatialite does not support this type of distance query on fields with unprojected coordinate systems.</p>

<p>So you are on the right track, but setting the srid to a different value will have no effect as long as you have <code>geography=True</code> enabled in your model definition. The geography type forces the srid to be 4326, as described in the <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/gis/model-api/#django.contrib.gis.db.models.GeometryField.geography" rel="nofollow">django geography docs</a>.</p>

<p>So try setting <code>geography=False</code> and the srid to one of the projected coordinate systems that you were trying out.</p>

python django sqlite geodjango spatialite