Two SpatRaster objects are compatible (in terms of combining layers) if
the CRS, extent and resolution are similar. In those cases you can combine
the objects simply as c(x, y).
This function compares those attributes and reports the results. See Resolving differences for minimal guidance.
Value
An invisible logical value indicating whether the SpatRaster
objects are compatible, plus an informative message flagging any issues
found.
terra equivalent
Resolving differences
For a different CRS, try
terra::project().For a different extent, try
terra::resample().For a different resolution, try
terra::resample(),terra::aggregate()orterra::disagg().
Examples
library(terra)
x <- rast(matrix(1:90, ncol = 3), crs = "EPSG:3857")
# Nothing
compare_spatrasters(x, x)
# Different CRS
y_nocrs <- x
crs(y_nocrs) <- NA
compare_spatrasters(x, y_nocrs)
#> ! Results of `tidyterra::compare_spatrasters()`:
#> The following attributes are not equal:
#> • CRS
# Different extent
compare_spatrasters(x, x[1:10, , drop = FALSE])
#> ! Results of `tidyterra::compare_spatrasters()`:
#> The following attributes are not equal:
#> • extent
# Different resolution
y_newres <- x
res(y_newres) <- res(x) / 2
compare_spatrasters(x, y_newres)
#> ! Results of `tidyterra::compare_spatrasters()`:
#> The following attributes are not equal:
#> • resolution
# Everything
compare_spatrasters(x, project(x, "epsg:3035"))
#> ! Results of `tidyterra::compare_spatrasters()`:
#> The following attributes are not equal:
#> • CRS
#> • extent
#> • resolution
