Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm using mysql 5.1.50, so the distance QuerySet method is not available to me.

Here is my model:

class Location(models.Model):
    name = models.CharField(max_length='100')
    point = models.PointField(spatial_index=False)

    objects = models.GeoManager()

I would like to find all the locations where the point is within 5 miles of another point (eg. test_point). I've found some potential ways to do this but am unsure of all of them.

Location.objects.filter(point__within=test_point.buffer(1))

But it's not clear to me what the unit is for '1'. It looks like degrees. I can convert miles to degrees but it seems like there's a cleaner way to do this.

share|improve this question
add comment

1 Answer 1

You created a geo-model without expliciting the srid. This means that your geometries will default to 4326 (also known as WGS84, units are in degrees of longitude and latitude).

If you would be using PostGis < 1.5 for performing spatial queries using a distance like the buffer method does, you would need first to project your point to a projected system (most general is 900913, but there may be much better ones, depends on the zone of the world where your point is located), then create the buffered polygon, then reproject back the polygon to 4326, finally use this polygon in the within filter.

This should also apply to MySql, AFAIK.

If you would have the possibility of using PostGis 1.5, then you could create your model with geographic data type by using a GeometryField.geography option set to true [0]

[0] http://docs.djangoproject.com/en/dev/ref/contrib/gis/model-api/#geography

share|improve this answer
    
I'm not using PostGIS at all. Nonetheless, I will explore the projection path a bit. –  Adam Nelson Jan 21 '11 at 19:08
    
yep, I don't know MySql Spatial, but as I suggested the project-reproject strategy should work well ;) –  capooti Jan 23 '11 at 22:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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