terrainr (version 0.3.1)

addbuff: Add a uniform buffer around a bounding box

Description

[add_bbox_buffer] calculates the great circle distance both corners of your bounding box are from the centroid and extends those by a set distance. Due to using Haversine/great circle distance, latitude/longitude calculations will not be exact.

[set_bbox_side_length] is a thin wrapper around [add_bbox_buffer] which sets all sides of the bounding box to (approximately) a specified length.

Usage

add_bbox_buffer(data, distance, distance_unit = "meters", error_crs = NULL)

# S3 method for sf add_bbox_buffer(data, distance, distance_unit = "meters", error_crs = NULL)

# S3 method for Raster add_bbox_buffer(data, distance, distance_unit = "meters", error_crs = NULL)

set_bbox_side_length( data, distance, distance_unit = "meters", error_crs = NULL )

# S3 method for sf set_bbox_side_length( data, distance, distance_unit = "meters", error_crs = NULL )

# S3 method for Raster set_bbox_side_length( data, distance, distance_unit = "meters", error_crs = NULL )

Arguments

data

The original data to add a buffer around. Must be either an `sf` or `Raster` object.

distance

The distance to add or to set side lengths equal to.

distance_unit

The units of the distance to add to the buffer, passed to [units::as_units].

error_crs

Logical: Should this function error if `data` has no CRS? If `TRUE`, function errors; if `FALSE`, function quietly assumes EPSG:4326. If `NULL`, the default, function assumes EPSG:4326 with a warning.

Value

An `sfc` object (from [sf::st_as_sfc]).

See Also

Other utilities: calc_haversine_distance(), deg_to_rad(), get_centroid(), rad_to_deg()

Examples

Run this code
# NOT RUN {
df <- data.frame(
  lat = c(44.04905, 44.17609),
  lng = c(-74.01188, -73.83493)
  )

df_sf <- sf::st_as_sf(df, coords = c("lng", "lat"))
df_sf <- sf::st_set_crs(df_sf, 4326)

add_bbox_buffer(df_sf, 10)


df <- data.frame(
  lat = c(44.04905, 44.17609),
  lng = c(-74.01188, -73.83493)
  )

df_sf <- sf::st_as_sf(df, coords = c("lng", "lat"))
df_sf <- sf::st_set_crs(df_sf, 4326)

set_bbox_side_length(df_sf, 4000)

# }

Run the code above in your browser using DataLab