strict_cfp: get a list of cell numbers intersecting a polygon

View source: R/dsmartr_helpers.R

strict_cfpR Documentation

get a list of cell numbers intersecting a polygon

Description

Determines which covariate cells intersect with a given map polygon.

Usage

strict_cfp(src_map = NULL, covariates = NULL)

Arguments

src_map

An sfc_POLYGON/MULTIPOLYGON or SpatialPolygonsDataFrame object representing the soil map to be disaggregated. Attributes are not required.

covariates

RasterStack or RasterBrick; environmental covariate datasets.

Details

Given a polygon layer and spatially intersecting raster object, determines which raster cells intersect which polygons. This function is primarily intended for use in prep_polygons but can be used as a standalone.

Value

a list of atomic vectors containing raster cell numbers.

Examples

## Not run: 
data('heronvale_soilmap')
data('heronvale_covariates')

# just get the list object
intersecting_cells <- strict_cfp(src_map = heronvale_soilmap,
                                 covariates = heronvale_covariates)

# to check that this output is complete and non overlapping
r_blank <- raster(heronvale_covariates)
r_blank[] <- 1:ncell(r_blank)
dup_chk <- table(unlist(intersecting_cells)) # all shld be freq = 1
values(r_blank)[!(values(r_blank) %in% as.data.frame(dup_chk)$Var1)] <- NA
plot(r_blank) # only cells underlying the polygons are kept

# or place it in a new list-column for later use
heronvale_soilmap$int_cells <- strict_cfp(src_map = heronvale_soilmap,
                                          covariates = heronvale_covariates)

# as above, tidyverse style
library(dplyr)
heronvale_soilmap <- heronvale_soilmap %>%
  mutate(int_cells = strict_cfp(., heronvale_covariates))


## End(Not run)

obrl-soil/dsmartr documentation built on Feb. 1, 2024, 10:57 p.m.