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?

  • If you're trying to do this in ArcGIS prior to the import, I believe you want to write a command to make a 20 km buffer around your points, then do an intersect between the polygon layer and your buffer. Sorry, I don't know any programming, but that's how I'd do it using tools in ESRI. Does that help at all? – Dano Aug 12 '11 at 14:24
  • @Dano: no, sorry, I need to do this in GeoDjango. – Nikolai Prokoschenko Aug 12 '11 at 14:29

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.

  • 1
    code above is not the exact copy of my code, I've changed the specific model name to Area, likewise with centroid, both shouldn't be a problem as long as the imports are correct. It's not a naming conflict. – Nikolai Prokoschenko Aug 14 '11 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.