library(raster)
library(rgdal)
#download data
download.file("http://www.protectedplanet.net/downloads/WDPA_July2015?type=shapefile","WDPA_July2015-shapefile.zip")
#unzip files
unzip("WDPA_July2015-shapefile.zip")
#read in shapefile
a <- shapefile("WDPA_July2015-shapefile-polygons.shx",verbose=TRUE)
#Exclude polygons with areas smaller than 1 km^2
a <- a[a$GIS_AREA >= 1,]
#generate 0.5 degree raster
r <- raster(ncols=720, nrows=360)
#convert polygon cover to raster (as cell share)
x <- rasterize(a,r,getCover=TRUE,progress="text")
#write output as netCDF
writeRaster(x,"WDPA_July2015_raster.nc",xname="lon",yname="lat",overwrite=TRUE)
The above code (run time of several hours) results in this map (plotted with Panoply). Obviously there is something wrong here (compare to the map on http://protectedplanet.net).
Excluding all polygons with area below 100000 km^2 gives the following map.
a <- a[a$GIS_AREA >= 100000,]
The second map is closer to the one on http://protectedplanet.net. From my understanding, all raster cells that are colored in the second map should also appear in the first map. Is that correct? And if so, what is wrong with my code?