Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add normalize argument to st_crop #686

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion R/stars.R
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ st_cells_from_xy = function(x, xy) {

#' return the cell index corresponding to the location of a set of points
#'
#' return the cell index corresponding to the location of a set of points
#' If the object has been cropped without normalization, then the indices return
#' are relative to the original uncropped extent. See \code{\link{st_crop}}
#' @param x object of class \code{stars}
#' @param sf object of class \code{sf} or \code{sfc}
#' @examples
Expand Down
4 changes: 3 additions & 1 deletion R/subset.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ st_intersects.bbox = function(x, y, ...) { # FIXME: segmentize first if geograph
#' @param as_points logical; only relevant if \code{y} is of class \code{sf} or \code{sfc}: if \code{FALSE}, treat \code{x} as a set of points, else as a set of small polygons. Default: \code{TRUE} if \code{y} is two-dimensional, else \code{FALSE}; see Details
#' @param ... ignored
#' @param crop logical; if \code{TRUE}, the spatial extent of the returned object is cropped to still cover \code{obj}, if \code{FALSE}, the extent remains the same but cells outside \code{y} are given \code{NA} values.
#' @param normalize logical; if \code{TRUE} then pass the cropped object to \code{\link{st_normalize}} before returning.
#' @details for raster \code{x}, \code{st_crop} selects cells that intersect with \code{y}.
#' For intersection, are raster cells interpreted as points or as small polygons?
#' If \code{y} is of class \code{stars}, \code{x} raster cells are interpreted as points; if \code{y} is of class \code{bbox}, \code{x} cells are interpreted as cells (small polygons). Otherwise, if \code{as_points} is not given, cells are interpreted as points if \code{y} has a two-dimensional geometry.
Expand Down Expand Up @@ -250,7 +251,7 @@ st_intersects.bbox = function(x, y, ...) { # FIXME: segmentize first if geograph
#' image(l7[bb,,,1], add = TRUE, col = sf.colors())
#' plot(st_as_sfc(bb), add = TRUE, border = 'green', lwd = 2)
st_crop.stars = function(x, y, ..., crop = TRUE, epsilon = sqrt(.Machine$double.eps),
as_points = all(st_dimension(y) == 2, na.rm = TRUE)) {
as_points = all(st_dimension(y) == 2, na.rm = TRUE), normalize = FALSE) {
x = st_upfront(x) # put spatial dimensions up front; https://github.com/r-spatial/stars/issues/457
d = dim(x)
dm = st_dimensions(x)
Expand Down Expand Up @@ -307,6 +308,7 @@ st_crop.stars = function(x, y, ..., crop = TRUE, epsilon = sqrt(.Machine$double.
for (i in seq_along(x))
x[[i]][mask] = NA
}
if (normalize[1]) x = st_normalize(x)
x
}

Expand Down
3 changes: 2 additions & 1 deletion man/st_cells.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/st_crop.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading