Skip to content

Geonames geocoding interface (alpha). Resolves addresses to lat & lon pairs using GeoNames webservice.

Notifications You must be signed in to change notification settings

aseidlitz/RGNCoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

R/GeoNames webservice interface

Geonames geocoding interface (alpha). Resolves addresses to lat and lon pairs using GeoNames webservice. Very early alpha code, use at your own risk. Based on ggmap::geocode code by David Kahle.

I tried several geocoding services supported in R, but none of them were suitable either due to the restrictive terms of use (Google) or the accuracy (CloudMade). Google, for example, states: "The Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited" https://developers.google.com/maps/documentation/geocoding/.

Since I needed to geocode locations for different purposes I tried a few services and settled on GeoNames. It imposes some limits on the numbers of queries per hour and per day, but the accuracy is better than on CloudMade (at least in my testing of rural Canadian addresses). CloudMade looks very promising and inexpensive, but the resolution quality needs to improve. They also provide awesome map tiles. This script could be easily repurposed to work with CloudMade geocoder API as well.

If you using a free GeoNames account, the script will respect usage limits, and continue processing when service will become available.

Sample usage:

if(geocode_refresh) #  || !ObjExists(loc)) 
{       
   writeLines("Geocoding...")
   loc <- count(rs[ , c("city","state","country")]) # calculate frequency (number of respondents from a city)  

   geo.data <- geocoder(loc)
   geo <- geo.data$results   
   geo <- rename(geo, c("city"="city.resolved","state"="state.resolved","country"="country.resolved"))  
   geo <- rename(geo, c("source_city"="city","source_state"="state","source_country"="country"))

   loc <- join(loc, geo, match="first", by=c("city","state","country"))
   save(loc, geo, geo.data, file="geo_locations.RData")
 } else {
   writeLines("Skipping Geocoding, loading saved data...")
   load("geo_locations.RData")
 }

About

Geonames geocoding interface (alpha). Resolves addresses to lat & lon pairs using GeoNames webservice.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages