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
library(sf) | |
library(RSQLite) | |
library(USAboundaries) | |
library(FedData) | |
label <- "ca109" | |
raw.dir <- "RAW/SSURGO" | |
extraction.dir <- "EXTRACTIONS" | |
output.file <- "ca109.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
## Example: Fetch SSURGO data for arbitrarily large/complex areas with the FedData package | |
#@author: Andrew Brown | |
# sf package for USAboundaries | |
library(sf) | |
# USAboundaries for getting county geometry | |
library(USAboundaries) | |
# FedData for routines for accessing/stitching multi-SSA SSURGO data |
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
chunkApply <- function(object, FUN, | |
simplify = TRUE, | |
frameify = FALSE, | |
chunk.size = 100, | |
column.names = NULL, | |
...) { | |
if(simplify & frameify) { | |
message("simplify and frameify are both TRUE -- ignoring simplify argument", .call=FALSE) | |
simplify <- 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
library(microbenchmark) | |
library(data.table) | |
library(plyr) | |
# make some test data -- 200k records | |
# we will try rbind-filling two of these | |
test.data <- vector('list', length = 200) | |
test.data[] <- lapply(1:200, rnorm, n = 1000) | |
test.data <- as.data.frame(test.data, stringsAsFactors = 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
#' Calculate quasi-Gower's Distance for all profiles in a SoilProfileCollection | |
#' | |
#' @description This experimental function calculates pairwise distances between profiles in a SoilProfileCollection by a method related to Gower's Distance metric. One or more site or horizon level attributes are supplied as arguments for use in the distance calculation. Both numeric and categorical attributes are allowed -- with "difference" values calculated for numeric values and for "different" and "equal" categories \code{1} and \code{0} are assigned respectively. | |
#' | |
#' This is a SoilProfileCollection-specific implementation of the concept. The distance calculations specified in the method are first applied to horizon data, and then to the site data, to produce a "final" distance matrix. | |
#' | |
#' The pairwise distance of all horizons in the collection is reduced to a single value for each profile-level comparison. The horizon data distance matrix is scaled by both the range within individual variables (first), and the to |
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
library(aqp) | |
data(sp2) | |
depths(sp2) <- id ~ top + bottom | |
site(sp2) <- ~ surface | |
hzdesgnname(sp2) <- "name" | |
# update soil colors that we have data for plot | |
sp2$soil_color <- munsell2rgb(sp2$hue, sp2$value, sp2$chroma) |
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
## add support for ecosite-based queries in fetchSDA_Component / get_component_from_SDA; | |
## only uses NRCS forest/range sites; test for possible many:one duplication issues | |
## brownag committed on Jun 3, 2019 | |
## https://github.com/ncss-tech/soilDB/commit/4ad25e7b628e854fe0d1d21bdd2484022acfa922 | |
devtools::install_github('ncss-tech/soilDB@4ad25e7b628e854fe0d1d21bdd2484022acfa922', | |
dependencies = FALSE) | |
library(soilDB) |
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
# making use of @obrl-soil's new mpspline2 package [soon to be on CRAN!] | |
# | |
# author: andrew g brown; 2020/07/12 | |
# | |
# this is an attempt at creating a generic method for mass-preserving / equal-area splines | |
# on aqp SoilProfileCollection (SPC) data that may contain a large amount of missing values. | |
# | |
# it also provides an avenue to get 1cm continuous spline output back in a handy form (1cm sliced SPC). | |
# | |
# In the presence of missing values, getting the result back into the SPC is not always easy. |
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
ogc_fun <- function(x,y,theta) { | |
sqrt(x^2 + y^2)*cos(theta - atan(y / x)) | |
} | |
x <- y <- -100:100 | |
plot(x, y, | |
type="n", | |
xlim=c(0,200), | |
ylim=c(-150,150)) |
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
# I just named this "munsell2rgb2"... but there is no reason why it cant be | |
# "munsell2rgb,SoilProfileCollection-method" in aqp | |
munsell2rgb2 <- function(object, | |
hue = "hue", value = "value", chroma = "chroma", | |
as.spc = TRUE) { | |
h <- horizons(object) | |
# makes a data.frame | |
drgb <- munsell2rgb(h[[hue]], h[[value]], h[[chroma]], returnLAB = TRUE) |
OlderNewer