# NOT RUN {
# reading taxon density maps:
kml.file <- "taxon-celldensity-2294100.kml"
# download.file(paste("http://data.gbif.org/occurrences/taxon/celldensity/", kml.file, sep=""),
# destfile=paste(getwd(), kml.file, sep=""))
# this will not run (you must first accept the data usage agreeent);
# instead, obtain the kml file via a web browser, and save it to the working directory:
r <- readKML.GBIFdensity(kml.file)
class(r)
summary(r)
image(r)
# add world borders:
library(maps)
country.m = map('world', plot=FALSE, fill=TRUE)
IDs <- sapply(strsplit(country.m$names, ":"), function(x) x[1])
library(maptools)
country <- as(map2SpatialPolygons(country.m, IDs=IDs), "SpatialLines")
lines(country)
# to import a list of files, use e.g.:
kml.list <- list(kml.file)
r.lst <- lapply(kml.list, readKML.GBIFdensity, silent = TRUE)
# mask out missing layers (empty KML files):
mask <- !sapply(r.lst, is.null)
r.lst <- brick(r.lst[mask])
# }
Run the code above in your browser using DataLab