-
-
Save Bustami/cc93d4ddc8d05e233b23 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"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment