Casts x to POLYGON geometries and subsets it to those features that intersect y, using sf::st_intersects() as the join predicate. The attribute-geometry relationship of x is set to "constant" to suppress sf::st_cast() warnings.

spatial_join_intersects(x, y)

Arguments

x

An sf (multi)polygon object to subset.

y

An sf object to intersect against.

Value

An sf object: the subset of (cast) features of x that intersect y.

Examples

grid <- sf::st_sf(
  id = 1:2,
  geometry = sf::st_sfc(
    sf::st_polygon(list(rbind(c(0, 0), c(1, 0), c(1, 1), c(0, 1), c(0, 0)))),
    sf::st_polygon(list(rbind(c(2, 2), c(3, 2), c(3, 3), c(2, 3), c(2, 2)))),
    crs = 4326
  )
)
pt <- sf::st_sf(
  geometry = sf::st_sfc(sf::st_point(c(0.5, 0.5)), crs = 4326)
)
spatial_join_intersects(grid, pt)
#> Simple feature collection with 1 feature and 1 field
#> Attribute-geometry relationship: constant (1)
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 0 ymin: 0 xmax: 1 ymax: 1
#> Geodetic CRS:  WGS 84
#>   id                       geometry
#> 1  1 POLYGON ((0 0, 1 0, 1 1, 0 ...