[GIS] How to query for all polygons within a distance from a point

distancegeodjangospatialite

Call me stupid, but somehow I couldn't figure out how to do the following.

I've got a testing shapefile with 18 features, which I successfully imported into GeoDjango (1.3, running on Spatialite). As an practical example, I've taken a centroid of one of them (area.mpoly.centroid) and tried to find all areas within a 20 km distance (touching would be enough, needn't cover complete area).

Area.objects.filter(mpoly__dwithin=(centroid, D(km=20)))

However, this only gives me an empty list. Increasing the number to 200 km (in theory, this should cover all of my dataset) also yields nothing.

Am I doing something wrong?

Best Answer

I missed this before, you're using SpatialLite. dwithin is not supported with SpatialLite.


Old answer: 'Area' is a GeoDjango class. You probably have a name conflict. Don't name your models with the same name of any GeoDjango classes.

Also, 'centroid' should not be used as a variable name for the same reason.

Related Question