Skip to content

Commit

Permalink
compareGeom<SpatRaster,list> method
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Jun 27, 2023
1 parent 73ea161 commit 1d8b22a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
25 changes: 25 additions & 0 deletions R/values.R
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,31 @@ setMethod("compareGeom", signature(x="SpatRaster", y="SpatRaster"),
)


setMethod("compareGeom", signature(x="SpatRaster", y="list"),
function(x, y, ..., lyrs=FALSE, crs=TRUE, warncrs=FALSE, ext=TRUE, rowcol=TRUE, res=FALSE, stopOnError=TRUE, messages=FALSE) {
isr <- sapply(y, inherits, "SpatRaster")
if (!all(isr)) {
y <- y[isr]
if (length(y) == 0) error("compareGeom", "none of the elements of y is a SpatRaster")
n <- sum(!isr)
if (n > 1) {
warn("compareGeom", paste(n, "elements of y are not a SpatRaster"))
} else {
warn("compareGeom", paste("1 element of y is not a SpatRaster"))
}
}
out <- sapply(y, compareGeom, y=x, lyrs=lyrs, crs=crs, warncrs=warncrs, ext=ext, rowcol=rowcol, res=res, stopOnError=stopOnError, messages=messages)
if (!all(isr)) {
res <- rep(NA, length(isr))
res[isr] <- out
return(res)
}
out
}
)




setMethod("compareGeom", signature(x="SpatVector", y="SpatVector"),
function(x, y, tolerance=0) {
Expand Down
10 changes: 7 additions & 3 deletions man/compareGeom.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

\alias{compareGeom}
\alias{compareGeom,SpatRaster,SpatRaster-method}
\alias{compareGeom,SpatRaster,list-method}

\alias{compareGeom,SpatVector,SpatVector-method}
\alias{compareGeom,SpatVector,missing-method}

\title{Compare geometries of SpatRasters}

\description{
Evaluate whether two SpatRasters have the same extent, number of rows and columns, projection, resolution, and origin (or a subset of these comparisons). Or whether two SpatVectors have the same geometries, or whether a SpatVector has duplicated geometries.
Evaluate whether two SpatRasters have the same extent, number of rows and columns, projection, resolution, and origin (or a subset of these comparisons).

Or evaluate whether two SpatVectors have the same geometries, or whether a SpatVector has duplicated geometries.
}

\usage{
Expand All @@ -21,8 +25,8 @@ Evaluate whether two SpatRasters have the same extent, number of rows and column
}

\arguments{
\item{x}{SpatRaster}
\item{y}{SpatRaster}
\item{x}{SpatRaster or SpatVector}
\item{y}{Same as \code{x}. If \code{x} is a SpatRaster, \code{y} can also be a list of SpatRasters. If code{x} is a SpatVector, \code{y} can be missing}
\item{...}{Additional SpatRasters}
\item{lyrs}{logical. If \code{TRUE}, the number of layers is compared}
\item{crs}{logical. If \code{TRUE}, coordinate reference systems are compared}
Expand Down

0 comments on commit 1d8b22a

Please sign in to comment.