osm_find: Query OpenStreetMap (OSM) for features

View source: R/osm_helpers.R

osm_findR Documentation

Query OpenStreetMap (OSM) for features

Description

Get the SF details for each requested feature. The list of OSM features is here. Use in conjunction with osm_bind_features.

Usage

osm_find(bb, feature_key, feature_values)

Arguments

bb

(bounding box) the area to be queried

feature_key

(character) the feature key to query. Feature keys can be found here osmdata::available_features()

feature_values

(character) a vector of feature values to query, passed to osmdata::add_osm_feature(). Use NULL to return all values of your feature.

Value

a list of sf objects, technically an osmdata object

Examples

## Not run: 
bs <- sf::st_read("data/fires_storage/burnscar/lga_bs/lga_burnscar.shp") %>%
    sf::st_transform(crs = 7844) %>%
    sak::normalise_geo_names() %>%
    dplyr::filter(stringr::str_detect(lga_name, "Kangaroo Island"))

# KI BS bounding box
bb <- expand_bbox(bs, exp_factor = 0)

# Query for main roads
features_raw <- osm_query_features(bb,
    feature_key = "highway",
    feature_values = c("motorway", "primary")
)

# Collapse all the returned sfs into one
features <- osm_bind_features(features_raw,
    types = c("lines", "multilines")
)

# Take a look if you're curious
mapview::mapview(features,
    zcol = "highway" # nolint
)

# Intersect with the burnscar
burnscar_features <- features %>%
    sak::st_intersection_quicker(bs)

# Summarise the potential effect
osm_summarise_features(burnscar_features,
    highway,
    .f = "length",
    units = "km"
)

## End(Not run)

baslat/sak documentation built on April 14, 2025, 4:14 p.m.