- Install
direnv
, Node.js, GDAL, gettext (forenvsubst
), and PostgreSQL with PostGIS:
brew bundle
- Install Node.js dependencies:
npm install
- Copy
sample.env
to.env
(and update it if necessary):
cp sample.env .env
- Enable
direnv
(to set environment variables and to updatePATH
):
direnv allow
- Obtain and load AW
reaches
table - Load Watershed Boundary Dataset (WBD) 4-digit hydrologic units
- Pick a 4-digit hydrologic unit from the WBD Subregions Map, e.g.
1709
(the Willamette). - Create an HU4
reaches
table by intersecting WBD withreaches
to filter for access points in that HU4 - Download and import
nhdflowline
nhdarea
,nhdwaterbody
, andnhdplusflowlinevaa
for the selected 4-digit hydrologic unit. - Import
nhdfcode
(if not already imported). - Create snapped reach put-ins (
snapped_putins
) withnhdplusid
,fdate
, number of candidate flowlines, point on closest flowline, point on associated polygon, original point, and link from original to snapped location. - Create snapped reach take-outs (
snapped_takeouts
) withnhdplusid
,fdate
, number of candidate flowlines, point on closest flowline, point on associated polygon, original point, and link from original to snapped location. - Adjust put-in locations for reaches immediately downstream from other reaches so that they match the upstream reach's take-out location. (Take-outs are snapped to downstream NHD segments using put-in information.)
- Generate candidate reach geometries based on put-in and take-out locations (if take-outs were incorrectly snapped, these geometries will be capped by distance)
- Re-snap take-outs to candidate reach geometries (to ensure that they don't involve traveling upstream)
- Stitch linework together and crop between put-ins and take-outs to form
reach_segments
.
These steps can be executed for a given HU4 (e.g. 1709
) using:
make -j $(nproc) wbd/1709
This will download 3GB or more of data from USGS, depending on the hydrologic units processed.
Step 9 can be repeated as necessary:
make db/correct_putins
Steps 10-12 can also be repeated, in case snapped put-in or take-out locations have been corrected:
make db/reach_segments.1709
Questionable reach segments (i.e. where the segment is something other than a
LineString, where snapped flowline points are not on the generated
segment, or where snapped put-ins are downstream of take-outs) are marked
using the questionable
column on reach_segments
.
- Report generation, e.g. # of points that didn't snap per watershed, distance breakdowns