soilgrids_soilC_extract function A function to extract total soil organic carbon for a single or group of lat/long locationsbased on user-defined site location from SoilGrids250m version 2.0 : https://soilgrids.org

soilgrids_soilC_extract(site_info, outdir = NULL, verbose = TRUE)

Arguments

site_info

A dataframe of site info containing the BETYdb site ID, site name, latitude, and longitude, e.g. (site_id, site_name, lat, lon)

outdir

Optional. Provide the results as a CSV file (soilgrids_soilC_data.csv)

verbose

Provide progress feedback to the terminal? TRUE/FALSE

Value

a dataframe containing the total soil carbon values and the corresponding standard deviation values (uncertainties) for each location Output column names are c("Site_ID","Site_Name","Latitude","Longitude", "Total_soilC","Std_soilC")

Author

Qianyu Li, Shawn P. Serbin

Examples

if (FALSE) { # \dontrun{

# Example 1 - using the modex.bnl.gov BETYdb and site IDs to extract data
db <- 'betydb'
host_db <- 'modex.bnl.gov'
db_port <- '5432'
db_user <- 'bety'
db_password <- 'bety'

bety <- list(user='bety', password='bety', host=host_db,
dbname='betydb', driver=RPostgres::Postgres(),write=FALSE)

con <- DBI::dbConnect(drv=bety$driver, dbname=bety$dbname, host=bety$host, 
password=bety$password, user=bety$user)

suppressWarnings(site_qry <- glue::glue_sql("SELECT *, ST_X(ST_CENTROID(geometry)) AS lon,
ST_Y(ST_CENTROID(geometry)) AS lat FROM sites WHERE id IN ({ids*})",
ids = c("676","622","678","766","764"), .con = con))

suppressWarnings(qry_results.1 <- DBI::dbSendQuery(con,site_qry))
suppressWarnings(qry_results.2 <- DBI::dbFetch(qry_results.1))
DBI::dbClearResult(qry_results.1)
DBI::dbDisconnect(con)

site_info <- qry_results.2
verbose <- TRUE
system.time(result_soc <- PEcAn.data.land::soilgrids_soilC_extract(site_info=site_info, 
verbose=verbose))
result_soc

} # }