Skip to content

Commit d1e2a54

Browse files
committed
load_tree_data() initial commit
1 parent 75fb8e1 commit d1e2a54

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
export(.get_tree_list_xy)
44
export(create_fia_owin)
55
export(create_fia_ppp)
6+
export(load_tree_data)
67
export(overlay_crowns)
78
export(predict_crwidth)

R/load_tree_data.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#' @noRd
2+
#' @export
3+
load_tree_data <- function(src, table = NULL, columns = NULL, sql = NULL) {
4+
5+
default_cols <- c("PLT_CN", "SUBP", "TREE", "AZIMUTH", "DIST", "STATUSCD",
6+
"SPCD", "DIA", "HT", "ACTUALHT", "CCLCD", "TPA_UNADJ")
7+
8+
if (is.null(columns))
9+
columns <- default_cols
10+
11+
if (!is.null(sql) && !is.null(table))
12+
stop("'table' and 'sql' are mutually exclusive", call. = FALSE)
13+
14+
ds <- NULL
15+
if (is.null(table) && is.null(sql)) {
16+
ds <- try(methods::new(gdalraster::GDALVector, src), silent = TRUE)
17+
} else if (!is.null(table)) {
18+
ds <- try(methods::new(gdalraster::GDALVector, src, table), silent = TRUE)
19+
} else if (!is.null(sql)) {
20+
ds <- try(methods::new(gdalraster::GDALVector, src, sql), silent = TRUE)
21+
}
22+
23+
if (!methods::is(ds, "Rcpp_GDALVector"))
24+
stop("failed to establish a connection to 'src'", call. = FALSE)
25+
26+
if (!is.null(table) && !is.null(columns) && columns != "")
27+
ds$setSelectedFields(columns)
28+
29+
30+
31+
ds$close()
32+
}

0 commit comments

Comments
 (0)