Here we demonstrate how we have downloaded and pre-processed the cartographic information for Cameroon which is included in the package.

#> Loading required package: raster
#> Loading required package: sp
#> Loading required package: rgdal
#> rgdal: version: 1.5-8, (SVN revision 990)
#> Geospatial Data Abstraction Library extensions to R successfully loaded
#> Loaded GDAL runtime: GDAL 3.0.2, released 2019/10/28
#> Path to GDAL shared files: /usr/share/gdal
#> GDAL binary built with GEOS: TRUE 
#> Loaded PROJ runtime: Rel. 6.2.1, November 1st, 2019, [PJ_VERSION: 621]
#> Path to PROJ shared files: /usr/share/proj
#> Linking to sp version:1.4-2
#> To mute warnings of possible GDAL/OSR exportToProj4() degradation,
#> use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.

if(!require(mapview, quietly = TRUE))
  cat("We suggest installing the pacakge mapview for interactive visualisation",
      "of cartography from within R")

Administrative borders

Download cartography from the Global Administrative Borders Database (GADM, directly from within R.

cmr_admin3 <- getData('GADM', country = "CMR", level=3)
# mapview(cmr_admin3, zcol = "NAME_3")
## This only works locally.
prodel_path <- "/home/facu/CmisSync/Cirad/Sites/PRODEL/documentLibrary/carto"
water_bodies <- readOGR(prodel_path, layer = "wb_cam.shp")
national_parks <- readOGR(
  file.path(prodel_path, "WDPA_Mar2018_CMR-shapefile"),
# Not using this for the moment
ps_cam <- raster("ps_cam.tif")
animal_density_world <- raster(file.path(prodel_path, "glw", "WdCt8k_vf_Mn_Rw_To.tif"))
animal_density <- mask(crop(animal_density_world, extent(cmr_admin3)), cmr_admin3)

# plot(animal_density)
# summary(animal_density$WdCt8k_vf_Mn_Rw_To)

Save pre-processed cartography for use within the package

Prefer standard and modern Open Geospatial Consortium (OGC) formats: GeoPackage for vector maps and GeoTiff for raster images.

cmr_dir <- "./inst/cartography/CMR"
dir.create(cmr_dir, recursive = TRUE)

writeOGR(cmr_admin3, file.path(cmr_dir, "cmr_admin3.gpkg"), layer = "cmr_admin3", driver = "GPKG")
writeOGR(water_bodies, file.path(cmr_dir, "water_bodies.gpkg"), layer = "water_bodies", driver = "GPKG")
writeOGR(national_parks, file.path(cmr_dir, "national_parks.gpkg"), layer = "national_parks", driver = "GPKG")

writeRaster(animal_density, file.path(cmr_dir, "animal.density.tif"))