Skip to content

Commit 63ca8aa

Browse files
committed
add internal .get_fia_plot_geom()
1 parent 3f18cc7 commit 63ca8aa

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(.get_fia_plot_geom)
34
export(.get_tree_list_xy)
45
export(DEFAULT_TREE_COLUMNS)
56
export(create_fia_owin)

R/utils.R

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,63 @@
4848

4949
list(x = x, y = y)
5050
}
51+
52+
#' Get a WKB or WKT geometry for an FIA plot
53+
#'
54+
#' `.get_fia_plot_geom()` returns a MultiPolygon geometry for the FIA 4-point
55+
#' cluster design.
56+
#'
57+
#' @param center_x Numeric x coordinate of plot center (center of the center
58+
#' subplot).
59+
#' @param center_y Numeric y coordinate of plot center (center of the center
60+
#' subplot).
61+
#' @param macroplot A logical value, `TRUE` to use the FIA optional "macroplot"
62+
#' dimension. Default is `FALSE`.
63+
#' @param linear_unit An optional character string specifying the linear
64+
#' distance unit. Defaults to the native FIA unit of `"ft"`, but may be set to
65+
#' `"m"` instead (or `"meter"` / `"metre"`).
66+
#' @param quad_segs Integer number of segments used to define a 90 degree curve
67+
#' (quadrant of a circle). Passed to `gdalraster::g_buffer()`. Defaults to `30`.
68+
#' @param as_wkb A logical value, `TRUE` to return the geometry as a `"raw"`
69+
#' vector of WKB (the default). Can be set to `FALSE` to return a `"character"`
70+
#' string of WKT instead.
71+
#' @return
72+
#' A MultiPolygon geometry as a raw vector of WKB by default, or as a character
73+
#' string of WKT if `as_wkb = FALSE`.
74+
#' @noRd
75+
#' @export
76+
.get_fia_plot_geom <- function(center_x = 0, center_y = 0, macroplot = FALSE,
77+
linear_unit = "ft", quad_segs = 30L,
78+
as_wkb = TRUE) {
79+
80+
subp_radius <- 24
81+
if (macroplot)
82+
subp_radius <- 59.8
83+
84+
unit_conv <- 1 # FIA native unit ft
85+
if (linear_unit %in% c("m", "meter", "metre")) {
86+
unit_conv <- 0.3048 # ft to m
87+
subp_radius <- subp_radius * unit_conv
88+
}
89+
90+
sub_geoms <- vector(mode = "list", length = 4)
91+
92+
sub_geoms[[1]] <- gdalraster::g_create("POINT", c(center_x, center_y)) |>
93+
gdalraster::g_buffer(subp_radius, quad_segs = quad_segs)
94+
95+
s2_y <- center_y + (120 * unit_conv)
96+
sub_geoms[[2]] <- gdalraster::g_create("POINT", c(center_x, s2_y)) |>
97+
gdalraster::g_buffer(subp_radius, quad_segs = quad_segs)
98+
99+
s3_x <- center_x + (103.92 * unit_conv)
100+
s3_y <- center_y + (-60 * unit_conv)
101+
sub_geoms[[3]] <- gdalraster::g_create("POINT", c(s3_x, s3_y)) |>
102+
gdalraster::g_buffer(subp_radius, quad_segs = quad_segs)
103+
104+
s4_x <- center_x + (-103.92 * unit_conv)
105+
s4_y <- s3_y
106+
sub_geoms[[4]] <- gdalraster::g_create("POINT", c(s4_x, s4_y)) |>
107+
gdalraster::g_buffer(subp_radius, quad_segs = quad_segs)
108+
109+
gdalraster::g_build_collection(sub_geoms, "MULTIPOLYGON", as_wkb)
110+
}

0 commit comments

Comments
 (0)