[Django]-GeoDjango distance search

3👍

To get around the limitation in the quote, you can just take the centroid of the zipcode region provided by the user, and then from that point find all zipcode regions that intersect a 5, 10 or whatever mile circle emanating from that point. I’m not sure how that would be achieved in geodjango, but with postgis it’s definitely possible.

The limitation you quoted basically says you can’t write a query that says “give me all points that are within 5 miles on the inside of the border of Ohio.”

0👍

In [1]: o = Place.objects.get(pk=2463583)  # Oakland, CA

In [2]: sf = Place.objects.get(pk=2487956)  # San Francisco, CA

In [3]: o.coords.transform(3410)  # use the NSIDC EASE-Grid Global projection

In [4]: sf.coords.transform(3410)  # use the NSIDC EASE-Grid Global projection

In [5]: o.coords.distance(sf.coords)  # find the distance between Oakland and San Francisco (in meters)
Out[5]: 14401.942808571299

Leave a comment