-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# NASIS-site-export v 1.0 | ||
- A basic Rmd report for creating spatial layer from sites in NASIS local database |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |