Search code examples
djangogeodjangospatial-queryspatialite

Do I need specific configuration for Spatialite with GeoDjango?


According to https://docs.djangoproject.com/en/1.3/ref/contrib/gis/db-api/, Spatialite supports GeoQuerySet.distance(). However, having imported an area list (MultiPolygon as mpoly attribute), I'm trying to do the following:

Area.objects.all().distance(center)

And instead of something usable, I only get an error message: "ValueError: SQLite does not support linear distance calculations on geodetic coordinate systems."

What's wrong here, do I need some special configuration on Spatialite or is the documentation plain wrong?


Solution

  • You don't need to do anything regarding spatialite, but rather change the coordinate system (srid) you're using. Spatialite does distance calculations only on geographic coordinate systems, not geodetic. Check the SRID do you have in your model definition. Alternatively you can also switch to the postgis backend.