Skip to content

Commit 54f0b93

Browse files
committed
make adjustments
1 parent 2108101 commit 54f0b93

File tree

5 files changed

+87
-26
lines changed

5 files changed

+87
-26
lines changed

R/geom-predicates.R

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ st_relate = function(x, y, pattern = NA_character_, sparse = !is.na(pattern)) {
114114
#' @param y object of class \code{sf}, \code{sfc} or \code{sfg}; if missing, \code{x} is used
115115
#' @param sparse logical; should a sparse index list be returned (`TRUE`) or a dense logical matrix? See below.
116116
#' @inheritDotParams s2::s2_options
117-
#' @param prepared logical; prepare geometry for `x`, before looping over `y`? See Details.
118-
#' @details If \code{prepared} is \code{TRUE}, and \code{x} contains POINT geometries and \code{y} contains polygons, then the polygon geometries are prepared, rather than the points.
119117
#' @return If \code{sparse=FALSE}, \code{st_predicate} (with \code{predicate} e.g. "intersects") returns a dense logical matrix with element \code{i,j} equal to \code{TRUE} when \code{predicate(x[i], y[j])} (e.g., when geometry of feature i and j intersect); if \code{sparse=TRUE}, an object of class \code{\link{sgbp}} is returned, which is a sparse list representation of the same matrix, with list element \code{i} an integer vector with all indices \code{j} for which \code{predicate(x[i],y[j])} is \code{TRUE} (and hence a zero-length integer vector if none of them is \code{TRUE}). From the dense matrix, one can find out if one or more elements intersect by \code{apply(mat, 1, any)}, and from the sparse list by \code{lengths(lst) > 0}, see examples below.
120118
#' @details For most predicates, a spatial index is built on argument \code{x}; see \url{https://r-spatial.org/r/2017/06/22/spatial-index.html}.
121119
#' Specifically, \code{st_intersects}, \code{st_disjoint}, \code{st_touches} \code{st_crosses}, \code{st_within}, \code{st_contains}, \code{st_contains_properly}, \code{st_overlaps}, \code{st_equals}, \code{st_covers} and \code{st_covered_by} all build spatial indexes for more efficient geometry calculations. \code{st_relate}, \code{st_equals_exact}, and do not; \code{st_is_within_distance} uses a spatial index for geographic coordinates when \code{sf_use_s2()} is true.
@@ -138,15 +136,7 @@ st_relate = function(x, y, pattern = NA_character_, sparse = !is.na(pattern)) {
138136
#' lengths(lst) > 0
139137
#' # which points fall inside the first polygon?
140138
#' st_intersects(pol, pts)[[1]]
141-
#' # remove duplicate geometries:
142-
#' p1 = st_point(0:1)
143-
#' p2 = st_point(2:1)
144-
#' p = st_sf(a = letters[1:8], geom = st_sfc(p1, p1, p2, p1, p1, p2, p2, p1))
145-
#' st_equals(p)
146-
#' st_equals(p, remove_self = TRUE)
147-
#' (u = st_equals(p, retain_unique = TRUE))
148139
#' # retain the records with unique geometries:
149-
#' p[-unlist(u),]
150140
#' @export
151141
st_intersects = function(x, y, sparse = TRUE, ...) UseMethod("st_intersects")
152142

@@ -179,6 +169,11 @@ st_disjoint = function(x, y = x, sparse = TRUE, prepared = TRUE) {
179169
}
180170

181171
#' @name geos_binary_pred
172+
#' @inheritParams st_intersects
173+
#' @inheritDotParams s2::s2_options
174+
#' @details If \code{prepared} is \code{TRUE}, and \code{x} contains POINT geometries and \code{y} contains polygons, then the polygon geometries are prepared, rather than the points.
175+
176+
#' @param prepared logical; prepare geometry for `x`, before looping over `y`? See Details.
182177
#' @export
183178
st_touches = function(x, y, sparse = TRUE, prepared = TRUE, ...)
184179
st_geos_binop("touches", x, y, sparse = sparse, prepared = prepared, ...)
@@ -200,7 +195,8 @@ st_within = function(x, y, sparse = TRUE, prepared = TRUE, ...)
200195
#' @param model character; polygon/polyline model; one of
201196
#' "open", "semi-open" or "closed"; see Details.
202197
#' @details for \code{model}, see https://github.com/r-spatial/s2/issues/32
203-
#' @inheritParams st_intersects
198+
#' @inheritParams geos_binary_pred
199+
#' @param ... passed on to [s2::s2_contains()]
204200
#' @export
205201
#' @family geometric binary predicates for two spatial objects
206202
st_contains = function(x, y, sparse = TRUE, prepared = TRUE, ..., model = "open")
@@ -227,14 +223,26 @@ st_overlaps = function(x, y, sparse = TRUE, prepared = TRUE, ...)
227223
#' * `st_equals()` validate if x and y are equal.
228224
#' * `st_equals_exact()` returns true for two geometries of the same type and their vertices corresponding by index are equal up to a specified tolerance.
229225
#'
230-
#' @inheritParams st_intersects
226+
#' @inheritParams geos_binary_pred
231227
#' @param retain_unique logical; if `TRUE` (and `y` is missing) return only
232228
#' indexes of points larger than the current index; this can be used to select
233229
#' unique geometries, see examples. This argument can be used for all geometry predicates;
234230
#' see also \link{distinct.sf} to find records where geometries AND attributes are distinct.
235-
#' @param remove_self logical; if `TRUE` (and `y` is missing) return only indexes of geometries different from the current index; this can be used to omit self-intersections; see examples. This argument can be used for all geometry predicates
231+
#' @param remove_self logical; if `TRUE` (and `y` is missing) return only indexes of geometries different from the current index; this can be used to omit self-intersections; see examples.
232+
#' This argument can be used for all geometry predicates
233+
#' @param ... passed on to [s2::s2_equals()]
236234
#' @export
237235
#' @family geometric binary predicates for two spatial objects
236+
#' @examples
237+
#' # remove duplicate geometries:
238+
#' p1 = st_point(0:1)
239+
#' p2 = st_point(2:1)
240+
#' p = st_sf(a = letters[1:8], geom = st_sfc(p1, p1, p2, p1, p1, p2, p2, p1))
241+
#' st_equals(p)
242+
#' st_equals(p, remove_self = TRUE)
243+
#' (u = st_equals(p, retain_unique = TRUE))
244+
#' p[-unlist(u),]
245+
#' st_equals_exact(p1, p2)
238246
st_equals = function(x, y, sparse = TRUE, prepared = FALSE, ...,
239247
retain_unique = FALSE, remove_self = FALSE) {
240248
if (prepared)
@@ -244,6 +252,9 @@ st_equals = function(x, y, sparse = TRUE, prepared = FALSE, ...,
244252
}
245253

246254
#' @name geos_binary_pred
255+
#' @param model character; polygon/polyline model; one of
256+
#' `"open"`, `"semi-open"` or `"closed"`; see Details.
257+
#' @details for \code{model}, see https://github.com/r-spatial/s2/issues/32
247258
#' @export
248259
st_covers = function(x, y, sparse = TRUE, prepared = TRUE, ..., model = "closed")
249260
st_geos_binop("covers", x, y, sparse = sparse, prepared = prepared, ..., model = model)

man/geos_binary_pred.Rd

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/st_contains.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/st_equals.Rd

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/st_intersects.Rd

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)