st_joins: Join two 'sf' objects.

st_joinsR Documentation

Join two 'sf' objects.

Description

Both st_left_join() and st_inner_join() are wrappers around sf::st_join() with appropriate argument handling for left.

Both st_anti_join() and st_semi_join() are wrappers around sfx::st_any() used within dplyr::filter() (plus the application of logical ! where appropriate).

Usage

st_left_join(x, y, ...)

st_inner_join(x, y, ...)

st_right_join(x, y, ...)

st_semi_join(x, y, join = sf::st_intersects, ...)

st_anti_join(x, y, join = sf::st_intersects, ...)

Arguments

x

object of class sf

y

object of class sf

...

arguments passed on to the join or .predicate function, e.g. prepared, or a pattern for st_relate

join

geometry predicate function with the same profile as st_intersects; see details

Examples

suppressPackageStartupMessages(library(sf))
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(dplyr))
data(states_map)
data(ngp)

show_map <- function (x) {
    ggplot(x) +
        geom_sf(data = tx) +
        geom_sf(color = "red") +
        theme_void()
}

# MUTLIPOLYGON of the US state of Texas
tx <- states_map %>%
    filter(region == "texas")

# [Semi-join] Intersects (Default)
ngp %>%
        st_semi_join(tx) %>%
        show_map()

# [Semi-join] Coveredy by
ngp %>%
        st_semi_join(tx, sf::st_covered_by) %>%
        show_map()

# [Anti-join] Intersects (Default)
ngp %>%
        st_anti_join(tx) %>%
        show_map()

# [Inner-join] Intersects (Default)
ngp %>%
  st_inner_join(tx)


seasmith/sfx documentation built on April 1, 2024, 2:36 p.m.