Does anyone have any recommendations for working with zip code distance ranges? I need to calculate the distances between US zip codes. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060711/f133d7de/attachment-0001.html
Does anyone have any recommendations for working with zip code distance ranges? I need to calculate the distances between US zip codes. Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060711/f740e783/attachment-0001.html
Somewhere online (I don''t recall where, but I''ve used it so I know it''s available) you can download a file with all the US zip codes and a bunch of data on each, including the lat/long on their approx. "center". Then you''ll need to use a "Great Circle" formula to compute the distance between two points. Sorry if my answer is a little vague. I''ve done this in Perl a while back, but not recently in Ruby. Good luck! Nathan P. Verni wrote:> Does anyone have any recommendations for working with zip code distance > ranges? I need to calculate the distances between US zip codes. > Thanks! > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060711/4ff0f12d/attachment.html
On Tue, 11 Jul 2006, Nathan P. Verni wrote:> Does anyone have any recommendations for working with zip code distance > ranges? I need to calculate the distances between US zip codes.If you get the right data set, you can get lat/long with the zip codes, and it''s a simple matter of spherical geometry from there. -- _Deirdre web / blog: http://deirdre.net/ "Memes are a hoax! Pass it on!"
You will need to purchase a list of zipcodes with their latitude/longitude coordinates (zipinfo.com has good prices), and then use a function to get the distance between the zipcodes in decimal degrees and convert that into meters, miles, or whatever end measurement you want. And because zipcodes have all sorts of strange geographic dimension, the distance between the zip centriod might not be what you expect. Here is a postgresql function I use for something similar that might help you figure out the math. Also, this is not going to be real accurate, since the number of decimal degrees per any other measurement (miles in this case) varies depending on where you are. It''s probably good enough for a lot of applications though. -- function to convert miles into decimal degrees create or replace function convertMilesToDecimalDegrees(numeric) returns numeric as $$ begin -- $1 = radius in miles -- x = ($1 * 63360) = convert to meters (i.e. 63360 meters/mile) -- x = (x * 0.0254) = convert to inches (i.e. 0.0254 inches/meter) -- x = (x / 1852) = convert to nautical miles (i.e. 1852 meters/nautical mile) -- x = (x / 60) = convert to decimal degrees of latitude -- (i.e. 1 nautical mile = 1 decimal minute; therefore nautical miles/60 = decimal degrees return (((($1 * 63360) * 0.0254) / 1852) / 60); end; $$ language plpgsql; --function to buffer a geometry by a radius whose value is specified in miles create or replace function getBufferedGeometry(geometry,numeric) returns geometry as $$ declare g geometry; begin select Buffer($1,convertMilesToDecimalDegrees($2)) into g; return g; end; $$ language plpgsql; On 7/11/06, Nathan P. Verni <nverni@blenderbox.com> wrote:> > > > > Does anyone have any recommendations for working with zip code distance > ranges? I need to calculate the distances between US zip codes. Thanks! > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
You might try Google, I think I read they just opened an API for this sort of thing. -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org]On Behalf Of Deirdre Saoirse Moen Sent: Tuesday, July 11, 2006 4:00 PM To: rails@lists.rubyonrails.org Subject: Re: [Rails] Zip Code Ranges On Tue, 11 Jul 2006, Nathan P. Verni wrote:> Does anyone have any recommendations for working with zip code distance > ranges? I need to calculate the distances between US zip codes.If you get the right data set, you can get lat/long with the zip codes, and it''s a simple matter of spherical geometry from there. -- _Deirdre web / blog: http://deirdre.net/ "Memes are a hoax! Pass it on!" _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Nate: This sourceforge project has the data you need. http://sourceforge.net/project/showfiles.php?group_id=100039 Its in MS-Access, but you should be able to export the data to something ruby-friendly. You should download the "ASP zipdistance" archive. The ASP page here also has the equation you use to calculate distance from Lat. and Long. It should be simple to port over. Thanks, Tristan On 7/11/06, Nathan P. Verni <nverni@blenderbox.com> wrote:> > > > > Does anyone have any recommendations for working with zip code distance > ranges? I need to calculate the distances between US zip codes. Thanks! > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Ya I forgot the part about how to calculate the distance. Actually we just use postgresql with postgis. Setup your geometry as a POINT with an SRID of 4326, then use the Distance function to calculate the distance between two points. For example how to add a geometry column: SELECT AddGeometryColumn( ''addresses_geom'', ''geom'', 4326, ''POINT'', 2); Update a database row to add lat/long: UPDATE addresses_geom set geom = GeomFromText(''POINT(47.651443 -117.411025)'', 4326) where id = 9 And the distance query. Calculates the distance from the geom to the specified coordinates where id = 9. SELECT Distance(geom,GeometryFromText(''POINT(44.422 -123.876)'',4326)) AS distance from addresses_geom where id = 9 To get the distance between two points stored in the database: SELECT Distance(geom,(SELECT geom from addresses_geom where id = 13)) AS distance from addresses_geom where id = 9;
I know I''ve downloaded them for free in the past. Now that I''ve thought about it more, I believe it was from the US Census Bureau website somewhere. http://www.census.gov/ snacktime wrote:> You will need to purchase a list of zipcodes with their > latitude/longitude coordinates (zipinfo.com has good prices),
Found it... http://www.census.gov/geo/ZCTA/zcta.html Jonathan Motta wrote:> I know I''ve downloaded them for free in the past. Now that I''ve thought > about it more, I believe it was from the US Census Bureau website > somewhere. > http://www.census.gov/ > > snacktime wrote: > >> You will need to purchase a list of zipcodes with their >> latitude/longitude coordinates (zipinfo.com has good prices), >> > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060711/11abe769/attachment.html
http://civicspacelabs.org/home/zipcodedb Thats what I use. Its a little dated and missing some zip codes. Maybe the holes can be filled in using the census data. It has a lot of cool stuff. Specifically it has timezone info which is very useful. On 7/11/06, Jonathan Motta <jmotta@wwidea.org> wrote:> > Found it... > http://www.census.gov/geo/ZCTA/zcta.html > > > Jonathan Motta wrote: > I know I''ve downloaded them for free in the past. Now that I''ve thought > about it more, I believe it was from the US Census Bureau website > somewhere. > http://www.census.gov/ > > snacktime wrote: > > > You will need to purchase a list of zipcodes with their > latitude/longitude coordinates (zipinfo.com has good prices), > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Elliott Clark eclark@cc.gatech.edu eclark@nife.us
On Tue, 11 Jul 2006, Elliott Clark wrote:> http://civicspacelabs.org/home/zipcodedb > Thats what I use. Its a little dated and missing some zip codes. > Maybe the holes can be filled in using the census data. It has a lot > of cool stuff. Specifically it has timezone info which is very > useful.Thanks Elliott -- that''s the one I use and find most useful. -- _Deirdre web / blog: http://deirdre.net/ "Memes are a hoax! Pass it on!"
Nathan P. Verni wrote:> Does anyone have any recommendations for working with zip code distance > ranges? I need to calculate the distances between US zip codes.Another option is Zipdy, which is free. I do not know how current the data is, but it seems to work pretty well. Can''t compre it to zipcodedb, but I''ve had good luck with it, and it gets its data from the same source. http://www.cryptnet.net/fsp/zipdy/ -- Posted via http://www.ruby-forum.com/.
Thanks for posting that. I didn''t even know it existed. On 7/11/06, Deirdre Saoirse Moen <deirdre@deirdre.net> wrote:> On Tue, 11 Jul 2006, Elliott Clark wrote: > > > http://civicspacelabs.org/home/zipcodedb > > Thats what I use. Its a little dated and missing some zip codes. > > Maybe the holes can be filled in using the census data. It has a lot > > of cool stuff. Specifically it has timezone info which is very > > useful. > > Thanks Elliott -- that''s the one I use and find most useful. > > -- > _Deirdre web / blog: http://deirdre.net/ > "Memes are a hoax! Pass it on!" > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I have a DB with ZipCodes and their Lat/long. What I hear is that basically, we need to compute distance between all points (~70K) calculations before returning a result. Isn''t there a better way to reduce the set of calculations to determine say, zipcodes < 50 miles from x. Rajat http://www.pilotoutlook.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, Feb 03, 2008 at 02:57:42AM +0100, Rajat Garg wrote:> I have a DB with ZipCodes and their Lat/long. > > What I hear is that basically, we need to compute distance between all > points (~70K) calculations before returning a result. Isn''t there a > better way to reduce the set of calculations to determine say, zipcodes > < 50 miles from x.Precompute it, rather than trying to compute it on the fly. Disk is cheap, indexes are good.> Rajat--Greg --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 2, 10:11 pm, Gregory Seidman <gsslist+...-dNXPQ6k9rNiG6BJUYyje5axOck334EZe@public.gmane.org> wrote:> On Sun, Feb 03, 2008 at 02:57:42AM +0100, Rajat Garg wrote: > > I have a DB with ZipCodes and their Lat/long. > > > What I hear is that basically, we need to compute distance between all > > points (~70K) calculations before returning a result. Isn''t there a > > better way to reduce the set of calculations to determine say, zipcodes > > < 50 miles from x. > > Precompute it, rather than trying to compute it on the fly. Disk is cheap, > indexes are good.For 25 million pairs of zip codes? Disk is cheap, but that seems a bit extreme. As an alternative, you could index the zip codes by degrees of latitude and longitude. Then to find zip codes within 50 miles of a given zip code, you could simply retrieve all the zip codes within one degree of latitude or longitude. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
A better idea: index all the zip codes by latitude and longitude to two decimal places. Then if your database has trigonometric functions you can get a result with a single database query, and no ruby code. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
There is a great tutorial with CODE to calculate both distance between zip codes and zip codes that fall within a specified range. free-zipcodes.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---