Skip to content
Open
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
34 changes: 24 additions & 10 deletions R/eval.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ eval_buffer <-
direction,
coords = NULL) {

if (missing(x) || is.null(x) || !inherits(x, 'SpatRaster')) {
stop('x must be provided. expected type is SpatRaster.')
if (missing(x) || is.null(x)) {# || !inherits(x, 'SpatRaster')) {
stop('x must be provided.')# expected type is SpatRaster.')
}
if (missing(y) || is.null(y)) {
stop('y must be provided.')
Expand Down Expand Up @@ -184,14 +184,28 @@ eval_buffer <-
# }
# how to summarize buffers with ordinal/categorical

terra::extract(
x = x,
y = st_buffer(y, dist = buffer_size),
layer = layer,
na.rm = FALSE,
fun = buffer_fun,
ID = FALSE
)[[layer]]
if (inherits(x, "SpatRaster")) {
terra::extract(
x = x,
y = st_buffer(y, dist = buffer_size),
layer = layer,
na.rm = FALSE,
fun = buffer_fun,
ID = FALSE
)[[layer]]
} else if (inherits(x, "sf")) {
# TODO: intersect buffered points with unioned x and return area / buffer area
x_unioned <- st_union(x)
y_buffered <- st_buffer(y, buffer_size)
xy_intersection <- st_intersection(y_buffered, x_unioned)

y_buffered_area <- st_area(y_buffered)
# out <- rep(NA, length(y_buffered_area))
# out[xy_intersection]

# xy_intersects <- st_intersects(y_buffered, x_unioned)
}

}


Expand Down