Learn R Programming

tidyterra (version 1.3.0)

compare_spatrasters: Compare attributes of two SpatRaster objects

Description

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.

Usage

compare_spatrasters(x, y, digits = 6)

Value

An invisible logical value indicating whether the SpatRaster

objects are compatible, plus an informative message flagging any issues found.

Arguments

x, y

SpatRaster objects.

digits

Integer to set the precision for comparing the extent and the resolution.

<a href="https://CRAN.R-project.org/package=terra"><span class="pkg">terra</span></a> equivalent

terra::compareGeom().

Resolving differences

See Also

terra::identical().

Examples

Run this code
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)

# Different extent
compare_spatrasters(x, x[1:10, , drop = FALSE])

# Different resolution
y_newres <- x

res(y_newres) <- res(x) / 2
compare_spatrasters(x, y_newres)

# Everything

compare_spatrasters(x, project(x, "epsg:3035"))

Run the code above in your browser using DataLab