Here’s a little showcase on how this package can be used. Just some code, with not much explaination.

Prepare Environment

library(swissrastermaps4r)
library(sf)
library(purrr)
library(dplyr)
library(tmap)
library(glue)
library(grid)

Get Data

Initialize the file directory and load the dataset sample_polygons containing the largest 10 municipalities in Switzerland.

fdir_init("C:/Users/rata/Geodata/01_Switzerland/01_Maps")

data("sample_polygons")

Prepare Vector Data

Calculate area and population density per municipality:

Create an cookiecutter shape for each feature.

Create plots

Run a loop over each feature calling get_raster() within the plot. This avoids saving all the rasters in a huge list.

## Collective Size of Rasters to harmonize: 138.24516 (mb)
## Collective Size of Rasters to harmonize: 64.0809 (mb)

## Collective Size of Rasters to harmonize: 61.425089 (mb)

## Collective Size of Rasters to harmonize: 130.175831 (mb)

## Collective Size of Rasters to harmonize: 137.074061 (mb)

## Collective Size of Rasters to harmonize: 61.408868 (mb)

## Collective Size of Rasters to harmonize: 67.787406 (mb)

## Collective Size of Rasters to harmonize: 132.685739 (mb)

## Collective Size of Rasters to harmonize: 71.149182 (mb)

## Collective Size of Rasters to harmonize: 67.559457 (mb)