Skip to content

Commit

Permalink
r
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Nov 24, 2024
1 parent 9173a1c commit f68905d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
38 changes: 21 additions & 17 deletions R/geom.R
Original file line number Diff line number Diff line change
Expand Up @@ -318,34 +318,38 @@ setMethod("buffer", signature(x="SpatVector"),
)



setMethod("crop", signature(x="SpatVector", y="SpatVector"),
function(x, y, ext=FALSE) {
if (ext) {
return(crop(x, ext(y)))
}
x@ptr <- x@ptr$crop_vct(y@ptr)
messages(x, "crop")
}
)

setMethod("crop", signature(x="SpatVector", y="ANY"),
function(x, y) {
y <- ext(y)
if (geomtype(x) == "points") {
#if (ext) {
# y <- ext(y)
# x@ptr <- x@ptr$crop_ext(y@ptr, TRUE)
# return(x)
#}
if (inherits(y, "SpatVector")) {
x@ptr <- x@ptr$crop_vct(y@ptr)
} else {
if (!inherits(y, "SpatExtent")) {
y <- try(ext(y), silent=TRUE)
if (inherits(y, "try-error")) {
stop("y does not have a SpatExtent")
}
}
## crop_ext does not include points on the borders
## https://github.com/rspatial/raster/issues/283
#x@ptr <- x@ptr$crop_ext(y@ptr)
y <- as.polygons(y)
x@ptr <- x@ptr$crop_vct(y@ptr)
} else {
x@ptr <- x@ptr$crop_ext(y@ptr, TRUE)
if (geomtype(x) == "points") {
y <- as.polygons(y)
x@ptr <- x@ptr$crop_vct(y@ptr)
} else {
x@ptr <- x@ptr$crop_ext(y@ptr, TRUE)
}
}
messages(x, "crop")
}
)



setMethod("convHull", signature(x="SpatVector"),
function(x, by="") {
x@ptr <- x@ptr$hull("convex", by[1])
Expand Down
4 changes: 2 additions & 2 deletions R/plot_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

hexcols <- function(cols, alpha=FALSE) {
if (alpha) {
m <- col2rgb(cols, alpha=TRUE)/255
m <- grDevices::col2rgb(cols, alpha=TRUE)/255
rgb(m[1,], m[2,], m[3,], m[4,])
} else {
m <- col2rgb(cols, alpha=FALSE)/255
m <- grDevices::col2rgb(cols, alpha=FALSE)/255
rgb(m[1,], m[2,], m[3,])
}
}
Expand Down
7 changes: 2 additions & 5 deletions man/crop.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
\alias{crop,SpatRaster-method}
\alias{crop,SpatRasterDataset-method}
\alias{crop,SpatRasterCollection-method}
\alias{crop,SpatVector,SpatVector-method}
\alias{crop,SpatVector,ANY-method}
\alias{crop,SpatVector-method}
\alias{crop,SpatGraticule-method}


Expand All @@ -30,9 +29,7 @@ You can crop a SpatVector with another SpatVector. If these are not polygons, th

\S4method{crop}{SpatRasterCollection}(x, y, snap="near", extend=FALSE)

\S4method{crop}{SpatVector,SpatVector}(x, y, ext=FALSE)

\S4method{crop}{SpatVector,ANY}(x, y)
\S4method{crop}{SpatVector}(x, y)

\S4method{crop}{SpatGraticule}(x, y)
}
Expand Down
3 changes: 2 additions & 1 deletion man/surfArea.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ surfArea(x, filename="", ...)

\arguments{
\item{x}{SpatRaster with elevation values. Currently the raster CRS must be planar and have the same distance units (e.g. m) as the elevation values}

\item{filename}{character. Output filename}
\item{...}{additional arguments for writing files as in \code{\link{writeRaster}}}
}

\value{SpatRaster}
Expand Down

0 comments on commit f68905d

Please sign in to comment.