Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # "getCountries" code taken from:
- # http://stackoverflow.com/questions/5126745/gadm-maps-cross-country-comparision-graphics
- # Load required libraries
- library(sp)
- # Load file from GADM
- # Specify the countries for fileName using ISO3C
- # like "AFG" for Afghanistan.
- # "level" specifies adminsitrative level.
- loadGADM<-function(fileName,level=0,...){
- load(url(paste("http://gadm.org/data/rda/",fileName,"_adm",level,".RData",sep = "")))
- gadm
- }
- # Add prefix (ISO3C code) to shapefile.
- changeGADMPrefix<-function(GADM, prefix) {
- GADM <- spChFIDs(GADM, paste(prefix, row.names(GADM), sep = "_"))
- GADM
- }
- # Load file and change prefix
- loadChangePrefix<-function (fileName, level = 0, ...) {
- theFile <- loadGADM(fileName, level)
- theFile <- changeGADMPrefix(theFile, fileName)
- theFile
- }
- # Apply all the functions:
- getCountries <- function (fileNames, level = 0, ...) {
- polygon <- sapply(fileNames, loadChangePrefix, level)
- polyMap <- do.call("rbind", polygon)
- polyMap
- }
- ## Example
- countries<-c("CZE","DEU","AUT","SVK","POL")
- EUR<-getCountries(countries,level=1) # Level 1
- CZE<-subset(EUR,ISO=="CZE")
- plot(EUR)
- plot(CZE,col="steelblue4",add=T)
Advertisement
Add Comment
Please, Sign In to add comment