addbuff: Add a uniform buffer around a bounding box

Description Usage Arguments Value See Also Examples

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
add_bbox_buffer(data, distance, distance_unit = "meters", error_crs = NULL)

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

## S3 method for class '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 class 'sf'
set_bbox_side_length(
  data,
  distance,
  distance_unit = "meters",
  error_crs = NULL
)

## S3 method for class '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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
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)

terrainr documentation built on Feb. 23, 2021, 9:06 a.m.