Learn R Programming

nominatimlite (version 0.1.6)

bbox_to_poly: Create a bounding box sf object

Description

Create a sf polygon object from the coordinates of a bounding box

Usage

bbox_to_poly(bbox = NA, xmin = NA, ymin = NA, xmax = NA, ymax = NA, crs = 4326)

Arguments

bbox

numeric vector of 4 elements representing the coordinates of the bounding box. Values should be c(xmin, ymin, xmax, ymax)

xmin, ymin, xmax, ymax

alternatively, you can use these named parameters instead of bbox

crs

coordinate reference system, something suitable as input to st_crs

Value

A sf object

Details

Bounding boxes can be located using different online tools, as Bounding Box Tool.

See Also

sf::st_as_sfc()

Other spatial: geo_address_lookup_sf(), geo_amenity_sf(), geo_lite_sf(), reverse_geo_lite_sf()

Other amenity: geo_amenity_sf(), geo_amenity(), osm_amenities

Examples

Run this code
# NOT RUN {
# bounding box of Germany
bbox_GER <- c(5.86631529, 47.27011137, 15.04193189, 55.09916098)

bbox_GER_sf <- bbox_to_poly(bbox_GER)


library(ggplot2)

ggplot(bbox_GER_sf) +
  geom_sf()
# }
# NOT RUN {
# Extract the bounding box of a sf object
Texas <- geo_lite_sf("Texas", points_only = FALSE)
bbox <- sf::st_bbox(Texas)

bbox

bbox_Texas <- bbox_to_poly(bbox)

ggplot(bbox_Texas) +
  geom_sf(col = "red") +
  geom_sf(data = Texas)
# }

Run the code above in your browser using DataLab