{"payload":{"allShortcutsEnabled":true,"fileTree":{"redcedar/analyses/distance-to-waterways":{"items":[{"name":"web-explorer","path":"redcedar/analyses/distance-to-waterways/web-explorer","contentType":"directory"},{"name":".gitignore","path":"redcedar/analyses/distance-to-waterways/.gitignore","contentType":"file"},{"name":".nvmrc","path":"redcedar/analyses/distance-to-waterways/.nvmrc","contentType":"file"},{"name":"Makefile","path":"redcedar/analyses/distance-to-waterways/Makefile","contentType":"file"},{"name":"common.js","path":"redcedar/analyses/distance-to-waterways/common.js","contentType":"file"},{"name":"common.json","path":"redcedar/analyses/distance-to-waterways/common.json","contentType":"file"},{"name":"create-hydrography-db.js","path":"redcedar/analyses/distance-to-waterways/create-hydrography-db.js","contentType":"file"},{"name":"failed-index.Rmd","path":"redcedar/analyses/distance-to-waterways/failed-index.Rmd","contentType":"file"},{"name":"fcode-period-map.js","path":"redcedar/analyses/distance-to-waterways/fcode-period-map.js","contentType":"file"},{"name":"fetch-hydrography.js","path":"redcedar/analyses/distance-to-waterways/fetch-hydrography.js","contentType":"file"},{"name":"index.Rmd","path":"redcedar/analyses/distance-to-waterways/index.Rmd","contentType":"file"},{"name":"index.html","path":"redcedar/analyses/distance-to-waterways/index.html","contentType":"file"},{"name":"map.qgz","path":"redcedar/analyses/distance-to-waterways/map.qgz","contentType":"file"},{"name":"nconn-to-epsg-4326.js","path":"redcedar/analyses/distance-to-waterways/nconn-to-epsg-4326.js","contentType":"file"},{"name":"nearest-hydrography-csv.js","path":"redcedar/analyses/distance-to-waterways/nearest-hydrography-csv.js","contentType":"file"},{"name":"nearest-hydrography.js","path":"redcedar/analyses/distance-to-waterways/nearest-hydrography.js","contentType":"file"},{"name":"package-lock.json","path":"redcedar/analyses/distance-to-waterways/package-lock.json","contentType":"file"},{"name":"package.json","path":"redcedar/analyses/distance-to-waterways/package.json","contentType":"file"},{"name":"redcedar-poi-epsg-4326.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-epsg-4326.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-by-period-tabular-archive-config.mjs","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-by-period-tabular-archive-config.mjs","contentType":"file"},{"name":"redcedar-poi-nearest-by-period.csv","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-by-period.csv","contentType":"file"},{"name":"redcedar-poi-nearest-by-period.ta","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-by-period.ta","contentType":"file"},{"name":"redcedar-poi-nearest-period-all-nconn-epsg-4326.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-all-nconn-epsg-4326.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-all-nconn.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-all-nconn.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-all-npoint.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-all-npoint.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-eph-nconn-epsg-4326.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-eph-nconn-epsg-4326.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-eph-nconn.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-eph-nconn.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-eph-npoint.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-eph-npoint.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-int-nconn-epsg-4326.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-int-nconn-epsg-4326.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-int-nconn.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-int-nconn.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-int-npoint.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-int-npoint.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-min-eph-nconn-epsg-4326.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-min-eph-nconn-epsg-4326.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-min-eph-nconn.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-min-eph-nconn.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-min-eph-npoint.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-min-eph-npoint.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-min-int-nconn-epsg-4326.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-min-int-nconn-epsg-4326.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-min-int-nconn.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-min-int-nconn.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-min-int-npoint.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-min-int-npoint.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-per-nconn-epsg-4326.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-per-nconn-epsg-4326.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-per-nconn.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-per-nconn.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-per-npoint.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-per-npoint.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-unk-nconn-epsg-4326.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-unk-nconn-epsg-4326.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-unk-nconn.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-unk-nconn.geojson","contentType":"file"},{"name":"redcedar-poi-nearest-period-unk-npoint.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi-nearest-period-unk-npoint.geojson","contentType":"file"},{"name":"redcedar-poi.geojson","path":"redcedar/analyses/distance-to-waterways/redcedar-poi.geojson","contentType":"file"},{"name":"redcedar-poi.js","path":"redcedar/analyses/distance-to-waterways/redcedar-poi.js","contentType":"file"},{"name":"results-db.js","path":"redcedar/analyses/distance-to-waterways/results-db.js","contentType":"file"},{"name":"spatial-db.js","path":"redcedar/analyses/distance-to-waterways/spatial-db.js","contentType":"file"},{"name":"summarize-hydrography.js","path":"redcedar/analyses/distance-to-waterways/summarize-hydrography.js","contentType":"file"},{"name":"summarized-hydrography.json","path":"redcedar/analyses/distance-to-waterways/summarized-hydrography.json","contentType":"file"},{"name":"symbology--nhd-courses.qml","path":"redcedar/analyses/distance-to-waterways/symbology--nhd-courses.qml","contentType":"file"},{"name":"symbology--poi.qml","path":"redcedar/analyses/distance-to-waterways/symbology--poi.qml","contentType":"file"}],"totalCount":51},"redcedar/analyses":{"items":[{"name":"distance-to-waterways--wa-dnr","path":"redcedar/analyses/distance-to-waterways--wa-dnr","contentType":"directory"},{"name":"distance-to-waterways","path":"redcedar/analyses/distance-to-waterways","contentType":"directory"},{"name":"random-forests","path":"redcedar/analyses/random-forests","contentType":"directory"},{"name":"index.Rmd","path":"redcedar/analyses/index.Rmd","contentType":"file"},{"name":"index.html","path":"redcedar/analyses/index.html","contentType":"file"}],"totalCount":5},"redcedar":{"items":[{"name":"analyses","path":"redcedar/analyses","contentType":"directory"},{"name":"data","path":"redcedar/data","contentType":"directory"},{"name":"images","path":"redcedar/images","contentType":"directory"},{"name":"instructions","path":"redcedar/instructions","contentType":"directory"},{"name":"index.Rmd","path":"redcedar/index.Rmd","contentType":"file"},{"name":"index.html","path":"redcedar/index.html","contentType":"file"}],"totalCount":6},"":{"items":[{"name":"redcedar","path":"redcedar","contentType":"directory"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"index.Rmd","path":"index.Rmd","contentType":"file"},{"name":"index.html","path":"index.html","contentType":"file"},{"name":"open.Rproj","path":"open.Rproj","contentType":"file"}],"totalCount":6}},"fileTreeProcessingTime":8.674067,"foldersToFetch":[],"reducedMotionEnabled":"system","repo":{"id":625638133,"defaultBranch":"main","name":"open","ownerLogin":"jmhulbert","currentUserCanPush":true,"isFork":false,"isEmpty":false,"createdAt":"2023-04-09T11:19:44.000-07:00","ownerAvatar":"https://avatars.githubusercontent.com/u/13762325?v=4","public":true,"private":false,"isOrgOwned":false},"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"main","listCacheKey":"v0:1681069744.0","canEdit":true,"refType":"branch","currentOid":"d31017c41d22623114a59e9dc4e544a86e95e9a4"},"path":"redcedar/analyses/distance-to-waterways/index.html","currentUser":{"id":13762325,"login":"jmhulbert","userEmail":"josephmichaelhulbert@gmail.com"},"blob":{"rawLines":["","","","","
","","","","","","","","","","Redcedar | ","Data | ","Analyses | ","Instructions | ","
"," | "," | "," | "," |
library(knitr)
","Previously this analysis was completed against WA DNR hydrography, but we","found that the number of streams that were of Unknown
","period to didn’t assist in proving or disproving this hypothesis. The","same analysis is carried out using WA NDH data below.
This analysis will take as input the redcedar observations from","iNaturalist, reduce the set of observations to those that intersect WA","NHD watersheds and calculate the distance to the WA NHD hydrography","using both NHD","line and area features. Metadata for these are captured in the Feature","Classes and Feature","Domain documents.
","Water courses and water bodies data carry periodicity metadata stored","under the fcode
attribute. Values include","Unknown
, Ephemeral
, Intermittent
,","Perennial
. These are encoded across values described in the","fcode-period-map
. The","distance to hydrography features analysis is carried out for","subsequently more strict criteria, starting with including hydrography","features with any periodicity value, all the way down to seeking","distance to only Perennial
hydrography features.
cat(readLines('fcode-period-map.js'), sep = '\\n')
","// Domain values mapped to hydrography categories","// https://www.usgs.gov/ngp-standards-and-specifications/national-hydrography-dataset-nhd-data-dictionary-feature-domains","","export const lineFCodeToPeriod = {"," 46000: 'Unknown',"," 46003: 'Intermittent',"," 46006: 'Perennial',"," 46007: 'Ephemeral',"," 56600: 'Perennial',","}","","export const areaFCodeToPeriod = {"," // water bodies"," 39000: 'Unknown',"," 39001: 'Intermittent',"," 39004: 'Perennial',"," 39005: 'Intermittent',"," 39006: 'Intermittent',"," 39009: 'Perennial',"," 39010: 'Perennial',"," 39011: 'Perennial',"," 43600: 'Unknown',"," 43601: 'Unknown',"," 43603: 'Unknown',"," 43604: 'Unknown',"," 43605: 'Unknown',"," 43606: 'Unknown',"," 43607: 'Unknown',"," 43608: 'Unknown',"," 43609: 'Unknown',"," 43610: 'Unknown',"," 43611: 'Unknown',"," 43612: 'Unknown',"," 43613: 'Unknown',"," 43614: 'Intermittent',"," 43617: 'Unknown',"," 43618: 'Unknown',"," 43619: 'Unknown',"," 43621: 'Perennial',"," 43624: 'Unknown',"," 43625: 'Unknown',"," 46600: 'Unknown',"," 46601: 'Intermittent',"," 46602: 'Perennial',"," 49300: 'Perennial',","}","export const fcodeToPeriod = {"," ...lineFCodeToPeriod,"," ...areaFCodeToPeriod,","}
","The result will be series of geo files that represents where on","hydrography features is the closest point, carrying the metadata as to","which redcedar observation is responsible for the point, and which","hydrography feature the point sits on. This is all stitched together in","a final CSV, redcedar-poi-nearest-by-period.csv
.
I (rubén) found that I was not able to do this analysis in R, since","the hydrography shapefiles accumualte to >5GB of data. For that","reason, the analysis is carried out in node.js using streaming","interfaces.
","To setup node.js, install nvm.
","Run nvm install 18.13.0
to get the correct engine.
From this directory, run nvm use
to ensure the node","18.31.0 is active in your terminal.
Run npm install
to get the dependencies.
Given the large file size of the hydrography shapefiles they are","omitted from this repository, but can be downloaded by running node fetch-hydrography.js
.","This is saved to a hydrography
directory.
ls -R hydrography | grep .shp
","NHDArea.shp","NHDAreaEventFC.shp","NHDFlowline_0.shp","NHDFlowline_1.shp","NHDFlowline_2.shp","NHDLine.shp","NHDLineEventFC.shp","NHDPoint.shp","NHDPointEventFC.shp","NHDWaterbody.shp","WBDHU10.shp","WBDHU12.shp","WBDHU14.shp","WBDHU16.shp","WBDHU2.shp","WBDHU4.shp","WBDHU6.shp","WBDHU8.shp","WBDLine.shp
","Then run node create-hydrography-db.js
","in order to create the database of hydrography features including a","spatial indicies. This will produce affordances for querying nearest","neighbors, as well as the ability to access any one feature based on the","nearest neighbor query. This database is saved to a","hydrography-db
directory. This can take some time as there","are >1 million hydrography features. Run the command prefixed with","DEBUG=*
to log out progress of every 10,000th item being","processed. Water body polygon features are converted to line features so","that they can be queried alongside water course line features.
Only hydrography features that intersect watershed’s that also","intersect a redcedar obervation are included in the summary and in the","following analysis.
","Water Courses Summary","Then run node redcedar-poi.js
in order","to create a geojson point feature collection of the observation data,","filtering out observations without valid [longitude, latitude]","attributes, and that reside outside of the watershed boundaries. This","file is saved as redcedar-poi.geojson. Hydrography data","is downloaded with the projection EPSG:4269, so the redcedar POI data is","reprojected into the same coordinate system.
Counts for each Tree Symptom value
","Then run node nearest-hydrography.js
","to do the analysis, using the specifications described in the common.json file.
cat(readLines('common.json'), sep = '\\n')
","{"," "analysisSpecs": ["," {"," "name": "period-all","," "include": ["Unknown", "Ephemeral", "Intermittent", "Perennial"]"," },"," {"," "name": "period-min-eph","," "include": ["Ephemeral", "Intermittent", "Perennial"]"," },"," {"," "name": "period-min-int","," "include": ["Intermittent", "Perennial"]"," },"," {"," "name": "period-unk","," "include": ["Unknown"]"," },"," {"," "name": "period-eph","," "include": ["Ephemeral"]"," },"," {"," "name": "period-int","," "include": ["Intermittent"]"," },"," {"," "name": "period-per","," "include": ["Perennial"]"," }"," ]","}
","This will produce two geojson files for each subanalysis.
","A point feature collection of the points on hydrography features","that represent the closest point to them. Internally this is known as","the npoint
(nearest point) feature. The distance between","observation and hydrography feature is stored in meters in the field","npoint-dist
. The observation attributes are prefixed with","opoint
. The closest hydrography feature attributes are","prefixed with nfeat
. If the observation sits within a water","body, it will have an npoint-dist
of 0.
A line feature collection that shows the connections between","observations and the closest point on a hydrography feature. This is","useful to visually spot check results. Internally this known as the","nconn
(nearest connection) feature.
# npoint result files","ls *npoint.geojson
","redcedar-poi-nearest-period-all-npoint.geojson","redcedar-poi-nearest-period-eph-npoint.geojson","redcedar-poi-nearest-period-int-npoint.geojson","redcedar-poi-nearest-period-min-eph-npoint.geojson","redcedar-poi-nearest-period-min-int-npoint.geojson","redcedar-poi-nearest-period-per-npoint.geojson","redcedar-poi-nearest-period-unk-npoint.geojson
","# nconn result files","ls *nconn.geojson
","redcedar-poi-nearest-period-all-nconn.geojson","redcedar-poi-nearest-period-eph-nconn.geojson","redcedar-poi-nearest-period-int-nconn.geojson","redcedar-poi-nearest-period-min-eph-nconn.geojson","redcedar-poi-nearest-period-min-int-nconn.geojson","redcedar-poi-nearest-period-per-nconn.geojson","redcedar-poi-nearest-period-unk-nconn.geojson
","To display the results on a web map, we can convert the above","nconn
result files from EPSG:3857 to EPSG:4326 by running","node nconn-to-epsg-4326.js
.
# nconn result files for web map display","ls *nconn-epsg-4326.geojson
","redcedar-poi-nearest-period-all-nconn-epsg-4326.geojson","redcedar-poi-nearest-period-eph-nconn-epsg-4326.geojson","redcedar-poi-nearest-period-int-nconn-epsg-4326.geojson","redcedar-poi-nearest-period-min-eph-nconn-epsg-4326.geojson","redcedar-poi-nearest-period-min-int-nconn-epsg-4326.geojson","redcedar-poi-nearest-period-per-nconn-epsg-4326.geojson","redcedar-poi-nearest-period-unk-nconn-epsg-4326.geojson
","The following charts summarize the data produced. Each subanalysis","has a box plot to show the distribution of distance to waterways by tree","symptom classification. Followed by a bar chart to count the number of","tree observations associated with each hydrography classification. If","there are significant statistical outliers in the box plot, another one","is produced with outliers removed and a count of tree observations for","each hydrography classification.
","Distribution of distance to hydrography
","A supplementary map can be found in this same directory","(map.qgz
). It carries all data used for this analysis.
redcedar-poi-nearest-by-period.csv
","is also available in this directory. This is a merger of the all the","npoint
and nconn
geojson files created for","each subanalysis, but merged into a single file for reporting. The","distance to hydrography features is stored in","{analysis-spec-name}-dist
, and the period value of that","feature is stored under {analysis-spec-name}-nfeat-period
.","This was produced by running node nearest-hydrography-csv.js
.
Below is a split pane interface to look at the tabular results of the","redcedar-poi-nearest-by-period.csv
","alongside a map of the redcedar observations and their nearest","connection (nconn
) to hydrography features. Clicking a","feature on the map will highlight the associated tabular row, and vice","versa.
knitr::include_url("./web-explorer/dist/index.html")
","","","