|
2 | 2 | #' |
3 | 3 | #' `.get_tree_list_xy()` returns a named list with two elements each containing |
4 | 4 | #' a numeric vector of the x and y coordinates for trees within the FIA |
5 | | -#' 4-subplot configuration. |
| 5 | +#' 4-subplot configuration. The origin is the center of the center subplot. |
6 | 6 | #' |
7 | 7 | #' @param tree_list A data frame containing the standard tree list columns for |
8 | 8 | #' a plot. This input generally has been pre-filtered, e.g., to live trees with |
9 | 9 | #' `DIA >= 5.0`. |
| 10 | +#' @param linear_unit An optional character string specifying the linear |
| 11 | +#' distance unit. Defaults to the native FIA unit of `"ft"`, but may be set to |
| 12 | +#' `"m"` instead (or `"meter"` / `"metre"`). Specifies units of the input |
| 13 | +#' `tree_list$DIST`. |
10 | 14 | #' @return |
11 | 15 | #' A named list with elements `x` and `y` containing numeric vectors of stem |
12 | 16 | #' coordinates. |
13 | 17 | #' @noRd |
14 | 18 | #' @export |
15 | | -.get_tree_list_xy <- function(tree_list) { |
| 19 | +.get_tree_list_xy <- function(tree_list, linear_unit = "ft") { |
| 20 | + unit_conv <- 1 # FIA native unit ft |
| 21 | + if (linear_unit %in% c("m", "meter", "metre")) { |
| 22 | + unit_conv <- 0.3048 # ft to m |
| 23 | + } |
| 24 | + |
16 | 25 | x <- rep(NA_real_, nrow(tree_list)) |
17 | 26 | y <- rep(NA_real_, nrow(tree_list)) |
18 | 27 |
|
|
24 | 33 |
|
25 | 34 | # subplot 2 - offsets from plot center |
26 | 35 | xoff2 <- 0.0 |
27 | | - yoff2 <- 120.0 |
| 36 | + yoff2 <- 120.0 * unit_conv |
28 | 37 | dist <- tree_list$DIST[tree_list$SUBP == 2] |
29 | 38 | azimuth <- tree_list$AZIMUTH[tree_list$SUBP == 2] |
30 | 39 | x[tree_list$SUBP == 2] <- dist * sin(azimuth * (pi / 180)) + xoff2 |
31 | 40 | y[tree_list$SUBP == 2] <- dist * cos(azimuth * (pi / 180)) + yoff2 |
32 | 41 |
|
33 | 42 | # subplot 3 - offsets from plot center |
34 | | - xoff3 <- 103.92 |
35 | | - yoff3 <- -60.0 |
| 43 | + xoff3 <- 103.92 * unit_conv |
| 44 | + yoff3 <- -60.0 * unit_conv |
36 | 45 | dist <- tree_list$DIST[tree_list$SUBP == 3] |
37 | 46 | azimuth <- tree_list$AZIMUTH[tree_list$SUBP == 3] |
38 | 47 | x[tree_list$SUBP == 3] <- dist * sin(azimuth * (pi / 180)) + xoff3 |
39 | 48 | y[tree_list$SUBP == 3] <- dist * cos(azimuth * (pi / 180)) + yoff3 |
40 | 49 |
|
41 | 50 | # subplot 4 - offsets from plot center |
42 | | - xoff4 <- -103.92 |
43 | | - yoff4 <- -60.0 |
| 51 | + xoff4 <- -103.92 * unit_conv |
| 52 | + yoff4 <- -60.0 * unit_conv |
44 | 53 | dist <- tree_list$DIST[tree_list$SUBP == 4] |
45 | 54 | azimuth <- tree_list$AZIMUTH[tree_list$SUBP == 4] |
46 | 55 | x[tree_list$SUBP == 4] <- dist * sin(azimuth * (pi / 180)) + xoff4 |
|
0 commit comments