Last active
June 8, 2022 17:07
-
-
Save andybega/6159870 to your computer and use it in GitHub Desktop.
Look up coordinates for city names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(geonames) | |
# list of city names (in Afghanistan) | |
cities <- c("Gereshk", "Lashkar Gah", "Marjah", "Nad-e Ali") | |
-5L), class = "data.frame") | |
# conveninence function to look up and format results | |
GNsearchAF <- function(x) { | |
res <- GNsearch(name=x, country="AF") | |
return(res[1, ]) | |
} | |
# loop over city names and reformat | |
GNresult <- sapply(cities, GNsearchAF) | |
GNresult <- do.call("rbind", GNresult) | |
GNresult <- cbind(city=row.names(GNresult), | |
subset(GNresult, select=c("lng", "lat", "adminName1"))) |
Hi - same issue as above. What is the username requirement?
To work with the geonames package you will need to sign up for a free account and take a note of your username or it will not work.
library(geonames)
options(geonamesUsername="yourid")
previosuly your account should be enabled to use the free webservices at the login page
(http://www.geonames.org/enablefreewebservice)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It ask for username which I added but still I get the same error, can you let me know how it can be solved, Thanks.