Library for calculating distance between ZIP codes

17 views
Skip to first unread message

Ram

unread,
Feb 17, 2021, 4:28:52 AM2/17/21
to django...@googlegroups.com
Hi,

We've USA ZIP codes table with the following values. and we have a total of 81,939 ZIP codes.

INSERT INTO pages_zip_code (id, zip, city, st) VALUES
(1, '00501', 'Holtsville', 'NY'),
(2, '00544', 'Holtsville', 'NY'),
(3, '00601', 'Adjuntas', 'PR'),
(4, '00602', 'Aguada', 'PR'),
(5, '00603', 'Aguadilla', 'PR'),
.......................................

We need to calculate the distance between each zip code and save the distance value in table like "zip_codes_distance" with the following table columns

zip_codes_distance table
id | from_zip | to_zip | distancev

We're looking for an appropriate library that might be available in Python/Django to calculate the distance easily instead of using any API. We know we can use Google's distance API with allowable requests, but we are trying to see if any Python library out there that is capable of doing the same calculation.

I would appreciate expert advice on this.

Best regards
~Ram

Thomas Lockhart

unread,
Feb 17, 2021, 5:02:53 AM2/17/21
to django...@googlegroups.com
Pre-calculating is pretty expensive: 81939*81938/2 = 3,356,958,891 entries make a pretty big table. Calculating on the fly is probably not horribly expensive and you could calculate and save, thereby caching values which have been used before.

Anyway, geodjango might be what you need. Plus the info on the geodetic coordinates for each zip code of course.

hth

- Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BOi5F1-E-70zWo-8EPu0%2BrWD%2BCjFqZaCVaUEtbb9mRNKjpMNQ%40mail.gmail.com.

Ram

unread,
Feb 17, 2021, 6:06:54 AM2/17/21
to django...@googlegroups.com
Thank you very much, Thomas. We will explore Geodetic and see if it is helpful. I really appreciate for the pointer.

Best regards,
~Ram

Reply all
Reply to author
Forward
0 new messages