cmr_cartography-rmd.RmdHere we demonstrate how we have downloaded and pre-processed the cartographic information for Cameroon which is included in the package.
require(raster)
#> Loading required package: raster
#> Loading required package: sp
require(rgdal)
#> Loading required package: rgdal
#> rgdal: version: 1.4-4, (SVN revision 833)
#> Geospatial Data Abstraction Library extensions to R successfully loaded
#> Loaded GDAL runtime: GDAL 2.2.2, released 2017/09/15
#> Path to GDAL shared files: /usr/share/gdal/2.2
#> GDAL binary built with GEOS: TRUE
#> Loaded PROJ.4 runtime: Rel. 4.9.2, 08 September 2015, [PJ_VERSION: 492]
#> Path to PROJ.4 shared files: (autodetected)
#> Linking to sp version: 1.3-1
if(!require(mapview, quietly = TRUE))
cat("We suggest installing the pacakge mapview for interactive visualisation",
"of cartography from within R")Download cartography from the Global Administrative Borders Database (GADM, https://gadm.org/) directly from within R.
## This only works locally.
prodel_path <- "/home/facu/CmisSync/Cirad/Sites/PRODEL/documentLibrary/carto"
water_bodies <- readOGR(prodel_path, layer = "wb_cam.shp")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"))