cmr_cartography-rmd.Rmd
Here we demonstrate how we have downloaded and pre-processed the cartographic information for Cameroon which is included in the package.
require(terra)
#> Loading required package: terra
#> terra 1.7.65
require(sf)
#> Loading required package: sf
#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
require(geodata)
#> Loading required package: geodata
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.
cmr_admin3 <- geodata::gadm(
country = "Cameroon",
level=3, # 3rd admin level
resolution = 2, # low-res
path = tempdir()
)
# mapview(cmr_admin3, zcol = "NAME_3")
## This only works locally.
prodel_path <- "/home/facu/CmisSync/Cirad/Sites/PRODEL/documentLibrary/carto"
water_bodies <- read_sf(file.path(prodel_path, "wb_cam.shp.shp"))
national_parks <- read_sf(
file.path(prodel_path, "WDPA_Mar2018_CMR-shapefile"),
"WDPA_Mar2018_CMR-shapefile-polygons"
)
# Not using this for the moment
ps_cam <- terra::rast("ps_cam.tif")
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)
writeVector(cmr_admin3, file.path(cmr_dir, "cmr_admin3.gpkg"))
write_sf(water_bodies, file.path(cmr_dir, "water_bodies.gpkg"), layer = "water_bodies", driver = "GPKG")
write_sf(national_parks, file.path(cmr_dir, "national_parks.gpkg"), layer = "national_parks", driver = "GPKG")
terra::writeRaster(animal_density, file.path(cmr_dir, "animal.density.tif"))