Return the bounding box as 'sf' or 'sfc'

st_extent(x, type = "sf")

Arguments

x

(sf/sfc) Spatial data

type

(character) Return type; either "sf" (Default) or "sfc"

Examples

suppressPackageStartupMessages(library(dplyr)) suppressPackageStartupMessages(library(ggplot2)) data(states_map) tx_extent <- states_map %>% filter(region == "texas") %>% st_extent() class(tx_extent)
#> [1] "sf" "data.frame"
# Can use in joins ngp %>% st_anti_join(tx_extent) %>% ggplot() + geom_sf(data = states_map) + geom_sf(data = tx_extent, fill = NA) + geom_sf(color = "red")
#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
states_map %>% st_anti_join(tx_extent) %>% ggplot() + geom_sf() + geom_sf(data = tx_extent, fill = NA)
#> although coordinates are longitude/latitude, st_intersects assumes that they are planar