overlap: Extract SpatRaster overlap

View source: R/overlap.R

overlapR Documentation

Extract SpatRaster overlap

Description

Extract the union of overlapping terra SpatRasters with different extents, origins, and projections.

Usage

overlap(x, y, last = FALSE)

Arguments

x, y

SpatRaster.

last

Logical. Should only the last layer be returned?

Details

SpatRaster y will be transformed (e.g., projected, resampled) with respect to x if extents, origins, or crs do not match.

Value

SpatRaster

Examples

bb2016 <- rast(system.file('extdata', 'bb2016.tif', package='bulkshift'))
bb2017 <- rast(system.file('extdata', 'bb2017.tif', package='bulkshift'))

ovlp <- overlap(bb2016, bb2017)
plot(ovlp)

#this function could be used to facilitate your own bespoke bulkshift, or to use a different model
err <- c(ovlp$bb2016 - ovlp$bb2017)
names(err) <- "err"
model_rast <- c(err, ovlp$bb2017)
df <- as.data.frame(model_rast)

model <- glm(err ~ bb2017, data = df)

bb2017_shifted <- bb2017 + terra::predict(bb2017, model)


benjaminmisiuk/bulkshift documentation built on May 24, 2023, 9:32 p.m.