Skip to content

Commit

Permalink
get_vegplot_from_NASIS_db: remove peiid and pedon join in base query;…
Browse files Browse the repository at this point in the history
… merge in from "site" query

 - prevents unintended duplication with multiple pedon per site
  • Loading branch information
brownag committed Dec 3, 2024
1 parent 4631401 commit f3f1a38
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/fetchVegdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fetchVegdata <- function(SS=TRUE, stringsAsFactors = NULL, dsn = NULL) {
}

# add ecosite id, corrdate, selection method to vegplot
vegplot <- merge(site[,c("siteiid", "ecositeid", "ecositecorrdate", "siteecositehistory.classifier", "es_selection_method")],
vegplot <- merge(site[,c("siteiid", "ecositeid", "peiid", "ecositecorrdate", "siteecositehistory.classifier", "es_selection_method")],
vegplot, by = "siteiid", all.x = TRUE, sort = FALSE)

# done
Expand Down
32 changes: 30 additions & 2 deletions R/get_vegplot_data_from_NASIS_db.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,40 @@ get_vegplot_from_NASIS_db <- function(SS = TRUE,
NASISDomainsAsFactor(stringsAsFactors)
}

q.vegplot <- "SELECT siteiid, so.siteobsiid, p.peiid, usiteid as site_id, assocuserpedonid as pedon_id, v.vegplotid as vegplot_id, vegplotiid, vegplotname, obsdate, primarydatacollector, datacollectionpurpose, vegdataorigin, vegplotsize, soilprofileindicator, soil232idlegacy, ahorizondepth, alkalinesalineindicator, alkalineaffected, salinityclass, restrictivelayerdepthlegacy, legacysoilcompname, legacysoilphase, legacylocalsoilphase, legacysoilsurftext, legacysurftextmod, legacyterminlieu, erosionclasslegacy, landformgrouplegacy, cryptogamcovcllegacy, rangelandusehistory, cancovpctplotave, cancovtotalpct, cancovtotalclass, overstorycancontotalpct, overstorycancovtotalclass, dblsampannualprodave, compyieldproductionave, abovegroundbiomasstotave, understoryreprodabundance, woodyunderstoryabundance, herbundertoryabundance, lichensunderstoryabundance, crowncanclosurepct, crowncancloseassessmethod, crowncompfactorlpp, crowncomplppavedbh, basalcoverpctave, basalareaplottotal, basalareaassessmethod, constreeshrubgrp, windbreakrowonedirection, windbreaktrappedsoildepth, windbreaktrappedsoiltexture, understorydescindicator, mensurationdataindicator, vigorclasslegacy, siteconditionlegacy, overstoryspecieslegacy, plantmoiststate, currenttreedensity, currenttreespacing, currentdxspacing, currentplotavedbh, plotbasalareafactor, currentbasalarea, foreststandtype, foreststratainventoried, foreststandregen, foreststandquality, desiredtreedensity, desireddxspacing, desiredbasalarea, excessbasalarea, excesstreedensity, stockingchangepct, treepctgoodcondition, treepctfaircondition, treepctpoorcondition, treecounttotal, treesnagdensityhard, treesnagdensitysoft, pastureforagetype, pasturestanddensityave, pastureplanthtave, pastureprodave, pcidesirableplants, pciplantcover, pciplantdiversity, pcigroundcovresidue, pcistandingdeadforage, pciplantresiduecompscore, pciplantvigor, pcilegumepctclass, pciuseuniformity, pcilivestockconcareas, pcisoilcompaction, pcisheetrillerosion, pciwinderosion, pcistreamshoreerosion, pcigullyerosion, pcierosioncompscore, pcipastureconditionscore, refplantcommunity, repannualprod, totestannualprod, totallowableannualprod, totpalatableannualprod, similarityindex, annualuseableprod, harvesteffpct, takehalfleavehalf, acresperaum, aumperacre, audperacre, desirableplantvigor, desirableseedlingabundance, decadentplantabundance, plantresidueadequacy, undesirableinvadingspecies, majorinvadingspecies, invadingspeciescancovpct, soilsurferosion, soilcrusting, soilcompaction, baregroundpct, gullyrillpresence, soildegradationrating, rangetrendcurrent, rangetrendplanned, qcreviewperson, qcreviewdate, qareviewperson, qareviewdate, swcdlegacy, fieldofficelegacy, nrcsarealegacy, aktotallichencoverpct, aktotallitter1coverpct, aktotallitter2coverpct, aktotalmosscoverpct, aktotalrockcoverpct, aktotalsoilcoverpct, aktotalwatercoverpct, akecologicalsitestatus, aktotalbedrockcoverpct, akfieldecositeid
q.vegplot <- "SELECT siteiid, so.siteobsiid, usiteid as site_id, assocuserpedonid as pedon_id,
v.vegplotid as vegplot_id, vegplotiid, vegplotname, obsdate, primarydatacollector, datacollectionpurpose,
vegdataorigin, vegplotsize, soilprofileindicator, soil232idlegacy, ahorizondepth, alkalinesalineindicator,
alkalineaffected, salinityclass, restrictivelayerdepthlegacy, legacysoilcompname, legacysoilphase,
legacylocalsoilphase, legacysoilsurftext, legacysurftextmod, legacyterminlieu, erosionclasslegacy,
landformgrouplegacy, cryptogamcovcllegacy, rangelandusehistory, cancovpctplotave, cancovtotalpct,
cancovtotalclass, overstorycancontotalpct, overstorycancovtotalclass, dblsampannualprodave,
compyieldproductionave, abovegroundbiomasstotave, understoryreprodabundance, woodyunderstoryabundance,
herbundertoryabundance, lichensunderstoryabundance, crowncanclosurepct, crowncancloseassessmethod,
crowncompfactorlpp, crowncomplppavedbh, basalcoverpctave, basalareaplottotal, basalareaassessmethod,
constreeshrubgrp, windbreakrowonedirection, windbreaktrappedsoildepth, windbreaktrappedsoiltexture,
understorydescindicator, mensurationdataindicator, vigorclasslegacy, siteconditionlegacy,
overstoryspecieslegacy, plantmoiststate, currenttreedensity, currenttreespacing, currentdxspacing,
currentplotavedbh, plotbasalareafactor, currentbasalarea, foreststandtype, foreststratainventoried,
foreststandregen, foreststandquality, desiredtreedensity, desireddxspacing, desiredbasalarea,
excessbasalarea, excesstreedensity, stockingchangepct, treepctgoodcondition, treepctfaircondition,
treepctpoorcondition, treecounttotal, treesnagdensityhard, treesnagdensitysoft, pastureforagetype,
pasturestanddensityave, pastureplanthtave, pastureprodave, pcidesirableplants, pciplantcover,
pciplantdiversity, pcigroundcovresidue, pcistandingdeadforage, pciplantresiduecompscore, pciplantvigor,
pcilegumepctclass, pciuseuniformity, pcilivestockconcareas, pcisoilcompaction, pcisheetrillerosion,
pciwinderosion, pcistreamshoreerosion, pcigullyerosion, pcierosioncompscore, pcipastureconditionscore,
refplantcommunity, repannualprod, totestannualprod, totallowableannualprod, totpalatableannualprod,
similarityindex, annualuseableprod, harvesteffpct, takehalfleavehalf, acresperaum, aumperacre,
audperacre, desirableplantvigor, desirableseedlingabundance, decadentplantabundance,
plantresidueadequacy, undesirableinvadingspecies, majorinvadingspecies, invadingspeciescancovpct,
soilsurferosion, soilcrusting, soilcompaction, baregroundpct, gullyrillpresence, soildegradationrating,
rangetrendcurrent, rangetrendplanned, qcreviewperson, qcreviewdate, qareviewperson,
qareviewdate, swcdlegacy, fieldofficelegacy, nrcsarealegacy, aktotallichencoverpct,
aktotallitter1coverpct, aktotallitter2coverpct, aktotalmosscoverpct, aktotalrockcoverpct,
aktotalsoilcoverpct, aktotalwatercoverpct, akecologicalsitestatus, aktotalbedrockcoverpct, akfieldecositeid
FROM
site_View_1 AS s
INNER JOIN siteobs_View_1 AS so ON so.siteiidref=s.siteiid
INNER JOIN vegplot_View_1 AS v ON v.siteobsiidref=so.siteobsiid
LEFT OUTER JOIN pedon_View_1 AS p ON p.siteobsiidref=so.siteobsiid
ORDER BY s.siteiid;"

channel <- dbConnectNASIS(dsn)
Expand Down

0 comments on commit f3f1a38

Please sign in to comment.