Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a data set that includes a list of zip codes. Is there a way in R to convert these zip codes to latitude and longitude coordinates?

share|improve this question
add comment

4 Answers 4

up vote 13 down vote accepted

There's no strict algorithmic relationship between latitude and longitude and zip code - they're all custom areas generated by the postal service. You need access to a dataset that codes polygons / polygon centroids by zip code.

1) Complex

Traditionally, this task (coupled with address lookup) is termed 'Geocoding'. The most convenient method for full address lookup is to find a preexisting online geocoder, whether by Google Maps, Bing Maps, or ESRI.

2) Simpler

For just US zip codes, though, there is data available from the Census:

http://www.census.gov/geo/www/cob/z52000.html

I'm not familiar with R geospatial capability, but all you should need is polygon->centroid, and centroid->coordinates.

3) Simplest

This task is common enough that a preexisting centroid dataset exists: http://coolthingoftheday.blogspot.com/2008/04/free-us-zip-code-database-as-csv.html

share|improve this answer
add comment

have you looked at the zipcode package? it's basically a dataframe with ~45,000 zipcodes along with their city, state, latitude and longitude.

share|improve this answer
add comment

I use the geocode function in the ggmap package.

share|improve this answer
    
will this allow zip+4 or does it only use zip centroids? –  B_Miner Jun 22 '12 at 17:49
    
It's using Google Maps, so works however Google would. (Only get a limited number of geocodes per day.) –  Wayne Jun 22 '12 at 17:50
    
...and apparently you aren't allowed to store the data (you'd basically have to query the API about every time you need it) –  Matt Jun 22 '12 at 19:09
    
Do they mean you can't store them for future geocoding (i.e. creating your own cache of mappings), or that you can't store the results at all? I've used it to locate crimes in my neighborhood and certainly store the Lat/Lon of each crime for future reference. I haven't created a cache that I use to avoid Google for future geocoding, though. –  Wayne Jun 22 '12 at 19:40
1  
My reading of the TOS (thanks for the link!) is that they have to do with the presenting of maps to other people. That is, you can't make your own map service that uses Google as a back end and doesn't credit them. It doesn't appear to have anything directly to do with geocoding data. Though who knows in this litigious era... –  Wayne Jun 22 '12 at 21:08
show 1 more comment

Seems like you are using Ruby on Rails
Try this tutorial from Ryan Bates http://railscasts.com/episodes/273-geocoder?view=asciicast
I've tried it before and it works perfectly. When you type address or zipcode , it will show the longitude and latitude. Hope it works for u too

Edy

share|improve this answer
1  
He is asking for a solution in R, not Ruby on Rails. –  Fezter Dec 3 '12 at 3:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.