Aggregates CONDPROP_UNADJ variable or other continuous condition variables to plot level with option to apply condition filters. If condition variable is not CONDPROP_UNADJ the variable is multiplied by CONDPROP_UNADJ for weighted sum.

datSumCond(
  cond = NULL,
  datsource = "obj",
  data_dsn = NULL,
  plt = NULL,
  subp_cond = NULL,
  subplot = NULL,
  cuniqueid = "PLT_CN",
  puniqueid = "CN",
  condid = "CONDID",
  bycond = FALSE,
  bysubp = FALSE,
  subpid = "SUBP",
  csumvar = NULL,
  csumvarnm = NULL,
  cfilter = NULL,
  getadjplot = FALSE,
  adjcond = FALSE,
  NAto0 = FALSE,
  cround = 5,
  returnDT = TRUE,
  savedata = FALSE,
  savedata_opts = NULL,
  dbconn = NULL,
  dbconnopen = FALSE,
  gui = FALSE
)

Arguments

cond

Data frame or comma-delimited file (*.csv). Condition-level table with aggregate variable and CONDPROP_UNADJ.

datsource

String. Source of data ('obj', 'csv', 'sqlite', 'gdb').

data_dsn

String. If datsource='sqlite', the name of SQLite database (*.sqlite).

plt

Data frame, comma-delimited file (*.csv), shapefile (*.shp), or database file. Plot-level table to join the aggregated tree data to (if bycond=FALSE). Nonsampled plots (PLOT_STATUS_CD = 3) are removed. Optional.

subp_cond

Dataframe, comma-delimited file (*.csv), or shapefile (*.shp). Subplot condition-level table to use to sum condition proportions, if bysubp=TRUE.

subplot

Dataframe, comma-delimited file (*.csv), or shapefile (*.shp). Subplot-level table to used to calculate adjustment factors, to remove nonsampled conditions (SUBP_STATUS_CD = 3). This table is optional.

cuniqueid

String. Unique identifier of cond (default = "PLT_CN").

puniqueid

String. Unique identifier of plt (default = "CN").

condid

String. Unique identifier for conditions.

bycond

Logical. If TRUE, the data are aggregated to the condition level (by: cuniqueid, condid). If FALSE, the data are aggregated to the plot level (by: puniqueid).

bysubp

Logical. If TRUE, data are aggregated to the subplot level.

subpid

String. Unique identifier of each subplot.

csumvar

String. One or more variable names to sum to plot level.

csumvarnm

String. Name of the resulting aggregated plot-level variable(s). Default = csumvar + '_PLT'.

cfilter

String. A filter to subset the cond data before aggregating (e.g., "COND_STATUS_CD == 1"). Must be R syntax.

getadjplot

Logical. If TRUE, adjustments are calculated for nonsampled conditions on plot.

adjcond

Logical. If TRUE, csumvar condition variables are adjusted for nonsampled conditions by plot.

NAto0

Logical. If TRUE, convert NA values to 0.

cround

Number. The number of digits to round to. If NULL, default=5.

returnDT

Logical. If TRUE, returns data.table object(s). If FALSE, returns data.frame object(s).

savedata

Logical. If TRUE, saves data to outfolder.

savedata_opts

List. See help(savedata_options()) for a list of options. Only used when savedata = TRUE. If out_layer = NULL, default = 'condsum'.

dbconn

Open database connection.

dbconnopen

Logical. If TRUE, keep database connection open.

gui

Logical. If gui, user is prompted for parameters.

Value

A list of the following items:

condsum

Data frame. Plot-level table with aggregated condition attribute.

cfilter

Condition filter.

If savedata=TRUE, condsum is saved to the outfolder.

Details

If variable = NULL, then it will prompt user for input.

Note

Nonsampled plots are removed from table.

Author

Tracey S. Frescino

Examples

# Aggregate LIVE_CANOPY_CVR_PCT to plot, weighted by CONDPROP_UNADJ
condsum <- datSumCond(cond = FIESTA::WYcond,
                      csumvar = "LIVE_CANOPY_CVR_PCT")$condsum

# Check results
condsum[condsum$PLT_CN == 40404737010690,]
#>            PLT_CN LIVE_CANOPY_CVR_PCT_PLT
#>            <char>                   <num>
#> 1: 40404737010690                      16
FIESTA::WYcond[FIESTA::WYcond$PLT_CN == 40404737010690,]
#>            PLT_CN CONDID COND_NONSAMPLE_REASN_CD CONDPROP_UNADJ SUBPPROP_UNADJ
#> 9  40404737010690      1                      NA           0.75           0.75
#> 10 40404737010690      2                      NA           0.25           0.25
#>    MICRPROP_UNADJ MACRPROP_UNADJ OWNCD OWNGRPCD RESERVCD SITECLCD STDORGCD
#> 9            0.75             NA    11       10        0       NA       NA
#> 10           0.25             NA    11       10        0        7        0
#>    ADFORCD LIVE_CANOPY_CVR_PCT COND_STATUS_CD NF_COND_STATUS_CD FORTYPCD
#> 9      206                   6              2                NA       NA
#> 10     206                  10              1                NA      999
#>    STDSZCD STDAGE GSSTKCD DSTRBCD1 DSTRBYR1 DSTRBCD2 DSTRBYR2 FORTYPGRPCD
#> 9       NA     NA      NA       NA       NA       NA       NA          NA
#> 10       5      0       5        0       NA        0       NA         999
#>    TIMBERCD
#> 9        NA
#> 10        2