Finding Distance GeoDjango

I want to use GeoDjango to do basic location searches. In particular, I want to give the search function a zip code / city / county and find all zip codes / cities / counties within 5mi, 10mi, 20mi, etc. In the documentation, I found the following paragraph:

Using a geographic coordinate system can subsequently complicate the work of the developer. For example, PostGIS does not have the ability to calculate the distance between inaccurate geometries using geographic coordinate systems, for example, to construct a query to find all points within 5 miles of the county boundary stored in WGS84. [6]

What does it mean if I want to use PostGIS and be able to perform the searches described above in the USA? Documents suggest using a projected coordinate system to cover only a specific region. I need to cover the whole country, so I believe that this is not an option.

Basically, in the end, I want to find nearby zip codes / cities / counties, given the starting location and distance. I don’t care how it is done at a technical level.

And where can I find a database that contains the geographical boundaries of US zip codes / cities / counties that I can import into the GeoDjango model?

UPDATE

, . , GeoDjango PostGis , x . , , , . , - , .

:

: 2000 ,

: 10 , 2010

:

+3
2

, zipcode, , zipcode, 5, 10 , , , geodjango, postgis .

, , , , : " , 5 ".

+3
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
0

Source: https://habr.com/ru/post/1726200/


All Articles