Skip to content

Commit 3684b3e

Browse files
authored
Merge pull request #373 from ncss-tech/vegtransect-groundsurface
Vegplot Transect: Add support for Transect Ground Surface Cover
2 parents 8a1a90a + 72903ff commit 3684b3e

6 files changed

+94
-31
lines changed

.github/workflows/R-CMD-check.yml

+2-7
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ jobs:
5757
- uses: r-lib/actions/setup-r@v2
5858
with:
5959
r-version: ${{ matrix.config.r }}
60-
extra-repositories: "https://rspatial.r-universe.dev/"
60+
extra-repositories: "https://ncss-tech.r-universe.dev/"
6161

6262
- uses: r-lib/actions/setup-pandoc@v2
6363

6464
- uses: r-lib/actions/setup-r-dependencies@v2
6565
with:
66-
extra-packages: any::rcmdcheck, any::remotes, RSQLite=?ignore-before-r=4.0.0, testthat=?ignore-before-r=4.0.0, local::.
66+
extra-packages: any::rcmdcheck, any::remotes, any::soilDBdata, RSQLite=?ignore-before-r=4.0.0, testthat=?ignore-before-r=4.0.0, local::.
6767
# upgrade: 'TRUE' ## NB: required to force building of source packages
6868
cache: always
6969
cache-version: 1
@@ -75,11 +75,6 @@ jobs:
7575
remotes::install_github("ncss-tech/aqp", dependencies = NA, build = FALSE)
7676
shell: Rscript {0}
7777

78-
- name: Install soilDBdata off GitHub
79-
run: |
80-
remotes::install_github("brownag/soilDBdata", dependencies = NA, build = FALSE)
81-
shell: Rscript {0}
82-
8378
- uses: r-lib/actions/check-r-package@v2
8479
with:
8580
upload-snapshots: true

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export(get_veg_from_NPS_PLOTS_db)
134134
export(get_veg_other_from_MT_veg_db)
135135
export(get_veg_species_from_MT_veg_db)
136136
export(get_vegplot_from_NASIS_db)
137+
export(get_vegplot_groundsurface_from_NASIS_db)
137138
export(get_vegplot_location_from_NASIS_db)
138139
export(get_vegplot_prodquadrats_from_NASIS_db)
139140
export(get_vegplot_species_from_NASIS_db)

R/fetchVegdata.R

+15-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#' @param dsn Optional: path to local SQLite database containing NASIS table structure; default:
1313
#' `NULL`
1414
#'
15-
#' @return A named list containing: "vegplot", "vegplotlocation", "vegplotrhi", "vegplotspecies",
15+
#' @return `fetchVegdata()`: A named list containing: "vegplot", "vegplotlocation", "vegplotrhi", "vegplotspecies",
1616
#' "vegtransect", "vegtransplantsum", 'vegsiteindexsum', "vegsiteindexdet", "vegbasalarea", and
1717
#' "vegplottext" tables
1818
#'
@@ -29,26 +29,31 @@ fetchVegdata <- function(SS = TRUE, include_pedon = TRUE, stringsAsFactors = NUL
2929
NASISDomainsAsFactor(stringsAsFactors)
3030
}
3131

32-
3332
# check if NASIS local DB instance/ODBC data source is available
3433
.soilDB_test_NASIS_connection(dsn = dsn)
3534

3635
# 1. load data in pieces
37-
site <- get_site_data_from_NASIS_db(SS = SS, include_pedon = ifelse(include_pedon == "assocuserpedonid", TRUE, include_pedon), dsn = dsn)
36+
site <- get_site_data_from_NASIS_db(
37+
SS = SS,
38+
include_pedon = ifelse(include_pedon == "assocuserpedonid", TRUE, include_pedon),
39+
dsn = dsn
40+
)
3841
vegplot <- get_vegplot_from_NASIS_db(SS = SS, dsn = dsn)
39-
vegplotlocation <- get_vegplot_location_from_NASIS_db(SS = SS, dsn = dsn)
42+
vegplotlocation <- get_vegplot_location_from_NASIS_db(SS = SS, dsn = dsn)
4043
vegplotrhi <- get_vegplot_trhi_from_NASIS_db(SS = SS, dsn = dsn)
4144
vegplotspecies <- get_vegplot_species_from_NASIS_db(SS = SS, dsn = dsn)
4245
vegtransect <- get_vegplot_transect_from_NASIS_db(SS = SS, dsn = dsn)
4346
vegtransplantsum <- get_vegplot_transpecies_from_NASIS_db(SS = SS, dsn = dsn)
4447
vegtranspoint <- get_vegplot_transpoints_from_NASIS_db(SS = SS, dsn = dsn)
48+
veggroundsurface <- get_vegplot_groundsurface_from_NASIS_db(SS = SS, dsn = dsn)
4549
vegprodquadrat <- get_vegplot_prodquadrats_from_NASIS_db(SS = SS, dsn = dsn)
46-
vegsiteindexsum <- get_vegplot_tree_si_summary_from_NASIS_db(SS = SS, dsn = dsn)
47-
vegsiteindexdet <- get_vegplot_tree_si_details_from_NASIS_db(SS = SS, dsn = dsn)
50+
vegsiteindexsum <- get_vegplot_tree_si_summary_from_NASIS_db(SS = SS, dsn = dsn)
51+
vegsiteindexdet <- get_vegplot_tree_si_details_from_NASIS_db(SS = SS, dsn = dsn)
4852
vegbasalarea <- get_vegplot_speciesbasalarea_from_NASIS(SS = SS, dsn = dsn)
49-
vegplottext <- get_vegplot_textnote_from_NASIS_db(SS = SS, fixLineEndings = TRUE, dsn = dsn)
50-
51-
53+
vegplottext <- get_vegplot_textnote_from_NASIS_db(SS = SS,
54+
fixLineEndings = TRUE,
55+
dsn = dsn)
56+
5257
# test to see if the selected set is loaded
5358
if (nrow(site) == 0 || nrow(vegplot) == 0) {
5459
message('Selected set is missing either the vegplot, pedon or site table, please load and try again :)')
@@ -78,6 +83,7 @@ fetchVegdata <- function(SS = TRUE, include_pedon = TRUE, stringsAsFactors = NUL
7883
vegtransect = vegtransect,
7984
vegtransplantsum = vegtransplantsum,
8085
vegtranspoint = vegtranspoint,
86+
veggroundsurface = veggroundsurface,
8187
vegprodquadrat = vegprodquadrat,
8288
vegsiteindexsum = vegsiteindexsum,
8389
vegsiteindexdet = vegsiteindexdet,

R/get_NASIS_table_name_by_purpose.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ get_NASIS_table_name_by_purpose <- function(purpose = c("metadata", "lookup", "n
170170
"pointplantcoverdetails",
171171
"plantprodquadratdetails",
172172
"plotspeciesbasalarea",
173-
"basalareatreescounted"
173+
"basalareatreescounted",
174+
"transectgroundsurfcover"
174175
),
175176
project = c(
176177
"project",

R/get_vegplot_data_from_NASIS_db.R

+39-13
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ get_vegplot_from_NASIS_db <- function(SS = TRUE,
8080
}
8181

8282

83-
# get location data from the corresponding record in the site table
8483
#' @export
84+
#' @return `get_vegplot_location_from_NASIS_db()`: a data.frame containing location data from the corresponding record in the site table
8585
#' @rdname fetchVegdata
8686
get_vegplot_location_from_NASIS_db <- function(SS = TRUE,
8787
stringsAsFactors = NULL,
@@ -149,7 +149,7 @@ get_vegplot_location_from_NASIS_db <- function(SS = TRUE,
149149

150150

151151

152-
# get Rangeland Health Indicator(RHI) associated fields in the vegplot table
152+
#' @return `get_vegplot_trhi_from_NASIS_db()`: a data.frame containing Rangeland Health Indicator (RHI) data from the `vegplot` table
153153
#' @export
154154
#' @rdname fetchVegdata
155155
get_vegplot_trhi_from_NASIS_db <- function(SS = TRUE,
@@ -195,8 +195,7 @@ get_vegplot_trhi_from_NASIS_db <- function(SS = TRUE,
195195
return(d)
196196
}
197197

198-
199-
# get vegplot species - this is a reconstruction of a site existing species list
198+
#' @return `get_vegplot_species_from_NASIS_db()`: a data.frame containing Plot Plant Inventory data
200199
#' @export
201200
#' @rdname fetchVegdata
202201
get_vegplot_species_from_NASIS_db <- function(SS = TRUE,
@@ -251,7 +250,7 @@ get_vegplot_species_from_NASIS_db <- function(SS = TRUE,
251250
}
252251

253252

254-
# get vegplot transect data
253+
#' @return `get_vegplot_transect_from_NASIS_db()`: a data.frame containing Vegetation Transect data
255254
#' @export
256255
#' @rdname fetchVegdata
257256
get_vegplot_transect_from_NASIS_db <- function(SS = TRUE,
@@ -318,7 +317,7 @@ get_vegplot_transect_from_NASIS_db <- function(SS = TRUE,
318317
}
319318

320319

321-
# get vegplot transect species data
320+
#' @return `get_vegplot_transect_from_NASIS_db()`: a data.frame containing Vegetation Transect Plant Summary data
322321
#' @export
323322
#' @rdname fetchVegdata
324323
get_vegplot_transpecies_from_NASIS_db <- function(SS = TRUE,
@@ -390,7 +389,7 @@ get_vegplot_transpecies_from_NASIS_db <- function(SS = TRUE,
390389
return(d)
391390
}
392391

393-
# get point plant cover details for vegtransect plant summary
392+
#' @return `get_vegplot_transpoints_from_NASIS_db()`: a data.frame containing Vegetation Transect Point Plant Cover Details
394393
#' @export
395394
#' @rdname fetchVegdata
396395
get_vegplot_transpoints_from_NASIS_db <- function(SS = TRUE, dsn = NULL) {
@@ -418,8 +417,7 @@ get_vegplot_transpoints_from_NASIS_db <- function(SS = TRUE, dsn = NULL) {
418417
uncode(res)
419418
}
420419

421-
422-
# get vegplot transect production quadrats
420+
#' @return `get_vegplot_prodquadrats_from_NASIS_db()`: a data.frame containing Vegetation Transect Production Quadrat data
423421
#' @export
424422
#' @rdname fetchVegdata
425423
get_vegplot_prodquadrats_from_NASIS_db <- function(SS = TRUE, dsn = NULL) {
@@ -448,7 +446,35 @@ get_vegplot_prodquadrats_from_NASIS_db <- function(SS = TRUE, dsn = NULL) {
448446
uncode(res)
449447
}
450448

451-
# get vegplot tree site index summary data
449+
450+
#' @return `get_vegplot_groundsurface_from_NASIS_db()`: a data.frame containing summary data for line point intercept ground surface cover hits by cover type.
451+
#' @export
452+
#' @rdname fetchVegdata
453+
#' @examplesIf local_NASIS_defined()
454+
#' \donttest{
455+
#' vsurf <- get_vegplot_groundsurface_from_NASIS_db()
456+
#' }
457+
get_vegplot_groundsurface_from_NASIS_db <- function(SS = TRUE, dsn = NULL) {
458+
q <- "SELECT siteiid, siteobsiid, vegplotid, vegplotname, vegtransectid, vt.totalpointssampledcount, vt.transectlength, groundsurfcovtype, groundcoverptcount, groundcoverptpct, quadratsize, quadratshape, groundcoverquadpctave
459+
FROM site_View_1 AS s
460+
INNER JOIN siteobs_View_1 AS so ON so.siteiidref=s.siteiid
461+
INNER JOIN vegplot_View_1 AS v ON v.siteobsiidref=so.siteobsiid
462+
INNER JOIN vegtransect_View_1 AS vt
463+
ON vt.vegplotiidref = v.vegplotiid
464+
LEFT JOIN transectgroundsurfcover_View_1 AS vtps
465+
ON vtps.vegtransectiidref = vt.vegtransectiid"
466+
# LEFT JOIN groundsurfcovdetails_View_1 AS vtpsd
467+
# ON vtpsd.transectgrsurfcoviidref = vtps.transectgroundsurfcoveriid
468+
469+
if (!SS) {
470+
q <- gsub("_View_1", "", q)
471+
}
472+
473+
res <- dbQueryNASIS(NASIS(dsn = dsn), q)
474+
uncode(res)
475+
}
476+
477+
#' @return `get_vegplot_tree_si_summary_from_NASIS_db()`: a data.frame containing Vegetation Plot Tree Site Index Summary data
452478
#' @export
453479
#' @rdname fetchVegdata
454480
get_vegplot_tree_si_summary_from_NASIS_db <- function(SS = TRUE,
@@ -495,7 +521,7 @@ get_vegplot_tree_si_summary_from_NASIS_db <- function(SS = TRUE,
495521
return(d)
496522
}
497523

498-
# get vegplot species basal area
524+
#' @return `get_vegplot_speciesbasalarea_from_NASIS()`: a data.frame containing Vegetation Plot Species Basal Area and Trees Counted data
499525
#' @export
500526
#' @rdname fetchVegdata
501527
get_vegplot_speciesbasalarea_from_NASIS <- function(SS = TRUE, dsn = NULL) {
@@ -524,7 +550,7 @@ get_vegplot_speciesbasalarea_from_NASIS <- function(SS = TRUE, dsn = NULL) {
524550
uncode(dbQueryNASIS(channel, q), dsn = dsn)
525551
}
526552

527-
# get vegplot tree site index details data
553+
#' @return `get_vegplot_tree_si_details_from_NASIS_db()`: a data.frame containing Vegetation Plot Tree Site Index Details data
528554
#' @export
529555
#' @rdname fetchVegdata
530556
get_vegplot_tree_si_details_from_NASIS_db <- function(SS = TRUE,
@@ -573,7 +599,7 @@ get_vegplot_tree_si_details_from_NASIS_db <- function(SS = TRUE,
573599
}
574600

575601

576-
# get vegplot textnotes
602+
#' @return `get_vegplot_textnote_from_NASIS_db()`: a data.frame containing Vegetation Plot text notes
577603
#' @param fixLineEndings Replace `'\r\n'` with `'\n'`; Default: `TRUE`
578604
#' @export
579605
#' @rdname fetchVegdata

man/fetchVegdata.Rd

+35-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)