expand_bbox: Expand bbox

View source: R/expand_bbox.R

expand_bboxR Documentation

Expand bbox

Description

A function to take a bounding box (generated using st_bbox) and expand it by x meters in the X direction and y meters in the Y direction.

Usage

expand_bbox(bbox, X, Y, X2 = X, Y2 = Y, crs_out = 4326)

Arguments

bbox

a bounding box generated by sf::st_bbox() or named numeric vector with xmin, ymin, xmax, ymax.

X

the distance in metres that we want to expand the bounding box by in the X direction

Y

the distance in metres that we want to expand the bounding box by in the Y direction

X2

if specified, the meters in the Easterly direction and metresX becomes metres in the Westerly direction.

Y2

if specified, the metres to the South. metresY becomes metres to the North.

crs_out

what epsg coordinate system to return the bbox in. Defaults to lat/lng (4326).

Value

a named numeric vector of bbox extents. This can be converted into an sf object using sf::st_as_sfc(). Coordinates are in lat/lng (4326).

Examples

library(sf)
camden <- dplyr::filter(localauth_data, Name == "Camden") %>%
  st_transform(4326)
bbox <- expand_bbox(st_bbox(camden), 5000, 5000)

library(ggplot2)
ggplot() +
  base_map(bbox, increase_zoom = 2) +
  geom_sf(data = camden, fill = NA) +
  coord_sf(
    xlim = c(bbox["xmin"], bbox["xmax"]),
    ylim = c(bbox["ymin"], bbox["ymax"]), crs = 4326
  )

Chrisjb/basemapR documentation built on April 1, 2022, 6:21 p.m.