add_buffer_variable: Identify trees in the buffer region

Description Usage Arguments Value See Also Examples

View source: R/spatial_functions.R

Description

Identify trees in the buffer region

Usage

1
add_buffer_variable(growth_df, direction = "in", size, region)

Arguments

growth_df

sf data frame

direction

"in" for buffers that are contained within region (default), "out" for buffers that contain region.

size

Distance to determine which neighboring trees to a focal tree are competitors. The units are assumed to be the same as the geometry variables in growth_df.

region

An sf polygon object of region to be buffered

Value

The same growth_df data frame but with a new boolean variable buffer indicating if a tree is in the study region buffer area. This uses compute_buffer_region() to define the boundary of the buffer region.

See Also

Other spatial functions: compute_buffer_region(), focal_vs_comp_distance()

Examples

 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
31
32
33
34
35
36
library(tibble)
library(sfheaders)
library(ggplot2)

# Example square region to be buffered
region <- tibble(
  x = c(0, 0, 1, 1),
  y = c(0, 1, 1, 0)
) %>%
  sf_polygon()

# Example points
study_points <- tibble(
  x = runif(50),
  y = runif(50)
) %>%
  sf_point()

# Size of buffer
size <- 0.05

# Identify whether points are within size of boundary
study_points <- study_points %>%
  add_buffer_variable(direction = "in", size = size, region = region)

# Plot study points coded by whether they are within size of boundary
p <- ggplot() +
  geom_sf(data = region, fill = "transparent") +
  geom_sf(data = study_points, aes(col = buffer))
p

# Additionally, show buffer boundary in red
buffer_boundary <- region %>%
  compute_buffer_region(direction = "in", size = size)
p +
  geom_sf(data = buffer_boundary, col = "red", fill = "transparent")

forestecology documentation built on Oct. 2, 2021, 5:07 p.m.