diff --git a/inst/reports/national/NASIS-site-export/NEWS.md b/inst/reports/national/NASIS-site-export/NEWS.md new file mode 100644 index 0000000..69a3177 --- /dev/null +++ b/inst/reports/national/NASIS-site-export/NEWS.md @@ -0,0 +1,2 @@ +# NASIS-site-export v 1.0 +- A basic Rmd report for creating spatial layer from sites in NASIS local database \ No newline at end of file diff --git a/inst/reports/national/NASIS-site-export/README.md b/inst/reports/national/NASIS-site-export/README.md new file mode 100644 index 0000000..6963b71 --- /dev/null +++ b/inst/reports/national/NASIS-site-export/README.md @@ -0,0 +1,19 @@ +# Export Site Locations from NASIS + +This is a report to create a spatial point layer for NASIS sites in your local database. + +This report has {aqp} and {soilDB} off CRAN and GitHub as dependencies. Also, the {sf} package is used for writing spatial outputs. + +To use the report: + +1. Load desired sites into NASIS local database and selected set. Default behavior is to pull from selected set, you can also pull all sites in the local database by customizing report parameters. + +2. Run `soilReports::reportSetup("national/NASIS-site-export")` to install dependencies + +3. Run `soilReports::reportInit("national/NASIS-site-export", outputDir = "NASIS-site-export")` to install a report instance in `outputDir`. Specify `overwrite` argument as needed. Use `reportUpdate` if an existing older report instance is being updated and you want to preserve _config.R_ contents. + +4. Navigate to `"NASIS-site-export"` directory. Open _report.Rmd_ in RStudio and click "Knit" drop-down menu, select "Knit with Parameters...". You can also `render()` with {rmarkdown} manually. + +5. Specify Soil Survey Areas of interest (optional, comma-delimited), and toggle selected set or "null fragments are zero" behavior as needed. + +6. Specify output path, default will create a GeoPackage in the working directory called _NASIS-sites.gpkg_ diff --git a/inst/reports/national/NASIS-site-export/report.Rmd b/inst/reports/national/NASIS-site-export/report.Rmd new file mode 100644 index 0000000..54c8701 --- /dev/null +++ b/inst/reports/national/NASIS-site-export/report.Rmd @@ -0,0 +1,58 @@ +--- +title: "NASIS Site Location Export" +output: html_document +params: + ssa_filter: + label: "Soil Survey Area (comma-delimited)" + input: text + value: "" + selected_set: + label: "Selected Set?" + input: checkbox + value: TRUE + null_frags_are_zero: + label: "Treat NULL rock fragments as zero?" + input: checkbox + value: TRUE + output_path: + label: "Output dataset:" + value: NASIS-sites.gpkg + input: text +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE, results = 'asis') +``` + +```{r} +library(sf) +library(soilDB, quietly = TRUE) + +sf::sf_use_s2(FALSE) + +x <- soilDB::get_site_data_from_NASIS_db(SS = params$selected_set, + nullFragsAreZero = params$null_frags_are_zero) +f <- sf::st_as_sf( + x, + crs = "OGC:CRS84", + na.fail = FALSE, + coords = c("longstddecimaldegrees", "latstddecimaldegrees") +) + +cat("Loaded", nrow(f), "sites from NASIS", paste0("(selected set: ", params$selected_set, ")")) + +if (nchar(params$ssa_filter) > 0) { + ssas <- toupper(trimws(strsplit(params$ssa_filter, ",")[[1]])) + + ssa_b <- soilDB::fetchSDA_spatial(ssas, by.col = "areasymbol", geom.src = "sapolygon") + + if (!is.null(ssa_b) && !inherits(ssa_b, 'try-error')) { + f <- subset(f, as.logical(sf::st_intersects(f, ssa_b))) + } + cat("\n\nFiltered to", nrow(f), "sites in ", params$ssa_filter) +} +``` + +```{r, results='markup'} +st_write(f, params$output_path, append = FALSE) +``` diff --git a/inst/reports/national/NASIS-site-export/setup.R b/inst/reports/national/NASIS-site-export/setup.R new file mode 100644 index 0000000..57d55d0 --- /dev/null +++ b/inst/reports/national/NASIS-site-export/setup.R @@ -0,0 +1,28 @@ +## +## Internal setup file for report -- +## change values as needed but ensure all `.variable.names` are defined for each report +## + +## packages from CRAN +.packages.to.get <- c('aqp', 'soilDB', 'sf') + +## packages from GitHub, installed with no dependencies +.gh.packages.to.get <- c('ncss-tech/soilDB') + +# name of report (matches parent folder name; e.g. `inst/reports/templates/minimal`) +.report.name <- 'NASIS-site-export' + +# version of report +.report.version <- '1.0' + +# brief description for `soilReports::listReports()` +.report.description <- 'Export NASIS Sites to Spatial Layer' + +# these are the files to copy on initial installation with copyReport/reportInit +.paths.to.copy <- c('report.Rmd', 'NEWS.md') + +# these are the files to copy on reportUpdate +.update.paths.to.copy <- .paths.to.copy + +# this is a flag to denote whether `shiny.Rmd` is main entrypoint to report +.has.shiny.interface <- FALSE \ No newline at end of file