mask_crop_subset: mask_crop_subset

View source: R/mask_crop_subset.R

mask_crop_subsetR Documentation

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

SpatialPolygons* object

idx

vector of strings indicating the layer indices to subset.

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.

Value

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

Examples

## Not run: 

  # Define dummy polygon
  dummy_polygon <- as(raster::extent(7, 18, 37, 40), "SpatialPolygons")
  raster::crs(dummy_polygon) <- "+proj=longlat +datum=WGS84 +no_defs"

  # Read RISICO test data
  r_risico <- readRDS(system.file("extdata", "RISICO_raster.rds",
                                  package = "caliver"))

  mask_crop_subset(r = r_risico, p = dummy_polygon)


## End(Not run)


ecmwf/caliver documentation built on March 25, 2022, 6:59 a.m.