Skip to content

Commit

Permalink
Add dev st_join_within_dist function
Browse files Browse the repository at this point in the history
  • Loading branch information
elipousson committed Oct 9, 2024
1 parent a9277c9 commit f2b96ff
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions R/st_join_within_dist.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' Join sf objects within specified distance
#'
#' @noRd
st_join_within_dist <- function(x,
y,
dist = NULL,
...) {
x <- map(
vctrs::vec_chop(x),
function(feat) {
feat_y <- y

if (!is.null(dist)) {
if (has_length(dist, 1)) {
feat <- st_buffer_ext(feat, dist = dist, ...)
} else {
feat <- st_erase(
st_buffer_ext(feat, dist = max(dist), ...),
st_buffer_ext(feat, dist = min(dist), ...)
)
}

feat_y <- st_filter_ext(y, feat, crs = x)
}

if (nrow(feat_y) == 0) {
return(feat)
}

st_join(
x = feat,
y = feat_y,
join = st_nearest_feature
)
}
)

sf_list_rbind(x)
}

0 comments on commit f2b96ff

Please sign in to comment.