st_any_pred: Simple geometry predicates

View source: R/geometry_operation.R

st_any_predR Documentation

Simple geometry predicates

Description

Unlike functions in sf like st_intersects, this function simply returns a logical vector indicating whether each geometry in x intersects (or returns TRUE from other predicates) anything in y, preferably when y only contains a small number of geometries or is one single MULTI geometry. This is useful when cropping or subsetting an SFE object with a geometry, such as tissue boundary or histological region polygons or a bounding box.

Usage

st_any_pred(x, y, pred)

st_any_intersects(x, y)

st_n_pred(x, y, pred)

st_n_intersects(x, y)

Arguments

x

An object of class sf, sfc, or sfg.

y

Another object of class sf, sfc, or sfg.

pred

A geometric binary predicate function, such as st_intersects. It should return an object of class sgbp, for sparse predicates.

Value

For st_any_*, a logical vector indicating whether each geometry in x intersects (or other predicates such as is covered by) anything in y. Simplified from the sgbp results which indicate which item in y each item in x intersects, which might not always be relevant. For st_n_*, an integer vector indicating the number of geometries in y returns TRUE for each geometry in x.

Examples

library(sf)
pts <- st_sfc(
    st_point(c(.5, .5)), st_point(c(1.5, 1.5)),
    st_point(c(2.5, 2.5))
)
pol <- st_polygon(list(rbind(c(0, 0), c(2, 0), c(2, 2), c(0, 2), c(0, 0))))
st_any_pred(pts, pol, pred = st_disjoint)
st_any_intersects(pts, pol)
st_n_pred(pts, pol, pred = st_disjoint)
st_n_intersects(pts, pol)

pachterlab/SpatialFeatureExperiment documentation built on March 11, 2024, 11:11 p.m.