Learn R Programming

caliver (version 2.0.0)

mask_crop_subset: mask_crop_subset

Description

mask and/or crop a Raster* based on a Polygon.

Usage

mask_crop_subset(r, p, idx = NULL, ...)

Arguments

r

Raster* object

p

SpatialPolygon* object

idx

vector of strings indicating the layer indices to subset.

...

additional arguments as in writeRaster (e.g. progress = "text")

Value

A Raster* object with resolution and land-sea mask matching those of r and extent matching p.

Details

Please note that cells along the border with centroids falling outside the polygon p will not be returned. If cells along the border are needed, we suggest to identify cells covering the polygon and set all remaining pixels to NA, as described in this post: https://goo.gl/22LwJt.

Examples

Run this code
# NOT RUN {
  # Define dummy polygon
  shape <- as(raster::extent(7, 18, 37, 40), "SpatialPolygons")
  
  # Read RISICO test data
  r_risico <- readRDS(system.file("extdata", "RISICO_raster.rds",
                                  package = "caliver"))
  
  mask_crop_subset(r = r_risico, p = shape)

# }
# NOT RUN {
# }

Run the code above in your browser using DataLab