data-raw/accessibility_2000.R

library(sf)
library(terra)
library(mapme.biodiversity)

# Load the spatial object (x) for cropping
x <- read_sf(system.file("extdata", "sierra_de_neiba_478140.gpkg", package = "mapme.biodiversity"))

# Set output directory for cropped data
outdir <- "inst/res/accessibility_2000"
dir.create(outdir, recursive = TRUE, showWarnings = FALSE)

# Set the temporary directory for processing
tmp_loc <- tempfile()
dir.create(tmp_loc)
mapme_options(outdir = tmp_loc)

# Download and process the full accessibility data
get_resources(x, get_accessibility_2000())
resources <- prep_resources(x)

# Crop the accessibility data to the extent of x
access_raster <- resources$accessibility_2000

# Save the cropped raster in the package inst/resources directory
writeRaster(access_raster,
            filename = file.path(outdir, "acc_50k.tif"),
            datatype = "INT4S",
            overwrite = TRUE,
            wopt = list(gdal = c("COMPRESS=LZW",
                                 "BLOCKXSIZE=128",
                                 "BLOCKYSIZE=128",
                                 "TILED=YES"))
)
mapme-initiative/mapme.biodiversity documentation built on April 5, 2025, 12:47 p.m.