Calculate the fewest zip codes, for the largest coverage - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Calculate the fewest zip codes, for the largest coverage (/thread-2329.html) |
Calculate the fewest zip codes, for the largest coverage - nilamo - Mar-07-2017 This is a problem I'm in the middle of solving, and because I don't want to spend forever on it, I'll probably brute force a solution. Suppose there's a third party website which displays information within a radius (max 25 miles) of a given zip code. Suppose you want to scrape that website, for all the available info for the entire US. You know, so you can analyze it, or whatever. The site in question isn't the fastest in the world, so just blasting it with thousands of zip codes will take... too long to run. So the problem is then, how do you choose zip codes strategically to cover the entire US, without having too much overlap between the radii between those zip codes? This seems like basic geometry to me, but I'm bad at math, so... What I'm working on now is basically pick a zipcode, then in each of the cardinal directions, the next zip code is as close to 10 miles away without going over. So there's a 15 mile overlap (in each direction, for each zip code), but there's no uncovered territory. So I'll need to dedupe the results from the external system. Is there a better way to do this, such that there's no uncovered territory and ALSO less zips involved? For reference, here's five zip codes, each with a 25(ish) mile radius, near Seattle (you can see that there will be A LOT of requests this way...). RE: Calculate the fewest zip codes, for the largest coverage - wavic - Mar-07-2017 Perhaps you can take lon/lat for each point to building a grid. Then I think you can take the corresponding zip code for each of these from several places. It should have to be some public database available or even Google. I am not American so I can't be more specific without more digging. RE: Calculate the fewest zip codes, for the largest coverage - nilamo - Mar-07-2017 The problem with using lon/lat is that... they curve. 1 degree of longitude in Minnesota is different than 1 degree of longitude in Texas. This is an interesting problem, but really has nothing to do with python. So this thread will probably be pruned in the near future. RE: Calculate the fewest zip codes, for the largest coverage - Larz60+ - Mar-07-2017 One way to do this is to use the us Census Bureau GeoCoder. The main site is here: https://geocoding.geo.census.gov/ You can submit an address batch file if you want to do it by street addresses (if you don't know latitude and longtitude, which by the way can be calculated if you know center lat and lon, distance from center and angle to point. Given that information, you will receive: Here's a document that explains the whole process: https://www.census.gov/mso/www/training/pdf/geocoder7-13-16.pdfAnd another for finding lat and long from bearing and distance from a point: http://www.movable-type.co.uk/scripts/latlong.html You can also download all of the raw data (Tiger files) if you want to do it all yourself. But a lot easier to use the api. RE: Calculate the fewest zip codes, for the largest coverage - Bass - Mar-23-2017 Hi, Not sure if this is still current, but some thoughts... My inital thoughts relates to long/lat, but I then read your difficulties with this. So in that vain, have you come across the Haversine Formula (I hadn't) but this may help. You take a FULL list of zip codes and use this/ perhaps combined with some alternative API's to remove zip codes from the full list that fall into the same unique area. This may give you a more manageable list, but without tryiing it, I have no idea. Some links that you may have/have not seen: http://mcdc.missouri.edu/allabout/zipcodes.html https://www.zipcodeapi.com/ In particular -> Find Close Zip Codes (https://www.zipcodeapi.com/API#matchClose ) (50 free requests/hour) The API can take a list of zip codes and match together those that are within a specified distance of each other. Sounds like a interesting conundrum. Even Quora has been asking this https://www.quora.com/Geolocation-What-is-the-minimum-set-of-zip-codes-based-on-a-radius-of-100-miles-that-I-can-use-in-a-series-of-searches-to-cover-the-entire-USA But I may be covering the same ground as you. Bass PS I have just seen this blog, it seems to generate a single number to relate to the geography by combining L&Lat. This may be able to let you feed in all the zip codes and extract those that are 'unique' http://mitchelsellers.com/blogs/2012/01/23/simple-zip-code-to-zip-code-distance-calculations-with-sql-server.aspx |