A very simple django application to find the distance between two US Zip Code Tabulation Areas. #complete
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Elf M. Sternberg f50c7178ed Merge pull request #1 from thisismess/master 10 years ago
zipdistance Better data 11 years ago
.gitignore Cleaning up inherited cruft. 12 years ago
AUTHORS Initial commit of working zipdistance. 12 years ago
LICENSE Initial commit of working zipdistance. 12 years ago
README Reflects change in model name. 12 years ago
requirements.txt Initial commit of working zipdistance. 12 years ago
setup.py Initial commit of working zipdistance. 12 years ago

README

==============================
django-zipdistance
==============================

django-zipdistance is a simple application to find the distance
between any two zip codes. The fixture provided with this application
is derived from the Year 2000 Zip Code Tabulation Area (ZCTA) tables
provided by the US Census Bureau. The Census Bureau notes:

ZCTAs are generalized area representations of U.S. Postal Service
(USPS) ZIP Code service areas. In most instances the ZCTA code
equals the ZIP Code for an area. Some ZIP Codes represent very
few addresses (sometimes only one) and therefore will not appear
in the ZCTA database. ZCTA is a trademark of the U.S. Census
Bureau; ZIP Code is a registered trademark of the U.S. Postal
Service.

In short, the ZCTAs most likely, but are not guaranteed to, correspond
with ZIP Codes for any given address. In testing, this database
proved to be entirely acceptable for most of the United States. But
just to make sure, I repeat: THE SOFTWARE AND DATA FILES ARE PROVIDED
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

-----------------------------
Standard Usage:

Find all the zipcodes within 50 miles:

from zipdistance.models import ZipDistance
target = ZipDistance.objects.get(zipcode = zip_form.cleaned_data['zipcode1'].strip())
zips = ZipDistance.objects.distance_from(target, 50)

Find the distance between two zipcodes:

from zipdistance.models import ZipDistance
zip1 = ZipDistance.objects.get(zipcode = zip_form.cleaned_data['zipcode1'].strip())
zip2 = ZipDistance.objects.get(zipcode = zip_form.cleaned_data['zipcode1'].strip())
zip1.distance_between(zip_2)

Find all the stores within a given distance.

from zipdistance.models import ZipDistance
from yourapp.models import Store
zips = ZipDistance.objects.distance_from(target, 50)
stores = Store.objects.get(zipcode__in = [z.zipcode for z in zips])

That last one's not terribly efficient. If you used the ZipMap as a
way of storing zipcodes, you could probably come up with something
smarter.