Luca Server ‐ Watershed - RopeWiki/app GitHub Wiki

Example Query:

https://ropewiki.com/luca/rwr?waterflow=&winfo=47.00909819695672,-121.7019696665819

Response:

{ "list": [ "West Fork White River O3 L3 Drainage:79km2 AvgFlow:121cfs AvgPrecip:1676mm AvgTemp:6C [Full Report]" ] }


Step-by-Step Process:

  1. Request Handler (Waterflow.cpp:6420)

if (q = ucheck(query, "winfo=")) WaterflowInfo(q, request->out);

  1. Parse Coordinates (Waterflow.cpp:6367)

int WaterflowInfo(const char *q, FCGX_Stream *stream) { vara coords(q); // ["47.00909819695672", "-121.7019696665819"]

  // Swap to lng;lat format
  sum = GetRiversPointSummary(coords[1] + ";" + coords[0]);
  // = "-121.7019696665819;47.00909819695672"

}

  1. Find River at Point (Elevation.cpp:9736)

int RiverListPoint(const char *param, CSym *sym, ...) { // Parse lat/lng LLE lle; // lat=47.009, lng=-121.702

  // Determine which 1°x1° tile contains this point
  // floor(47) = 47, floor(-121) = -121
  // File: "n47w121"

  CRiverCache obj(lle);
  // Loads cached river network from: RIVERS/n47w121.csv

  // Find closest river segment within 500m
  r = obj.rlist->FindPoint(lle.lat, lle.lng, MINRIVERPOINT);

  // Return river metadata
  *sym = *r->sym;

}

  1. Load River Tile Data

CBox::file(47, -121) → "n47w121"

Loads: RIVERS/n47w121.csv

CSV contains: id,desc,lat,lng,lat2,lng2,coords,watershed West Fork White River,EPA Link http://ofmpub.epa.gov/waters10/watershed_characterization.control?pComID=23980965,47.0,121.7,47.1,-121.6,"lat;lng lat;lng...",3;3;121;79;1676;6

Where watershed field = "3;3;121;79;1676;6" contains:

  • Order: 3
  • Level: 3
  • AvgFlow: 121 cfs
  • Drainage: 79 km²
  • AvgPrecip: 1676 mm
  • AvgTemp: 6°C
  1. Format Response (Elevation.cpp:16838)

CString WatershedString(CSym &sym) { // Parse watershed data CString desc = WatershedSummary(sym).join(";"); // Returns: ["O3", "L3", "Drainage:79km2", "AvgFlow:121cfs", "AvgPrecip:1676mm", "AvgTemp:6C"]

  // Get EPA link from description
  CString url = WatershedURL(sym);
  // = "http://ofmpub.epa.gov/waters10/watershed_characterization.control?pComID=23980965"

  // Build final string
  desc = sym.id + " " + desc + " " + alink(url, "[Full Report]");
  // = "West Fork White River O3 L3 Drainage:79km2 AvgFlow:121cfs AvgPrecip:1676mm AvgTemp:6C <a href='...'>[Full Report]</a>"

}


Where Does the Data Come From?

Pre-Processing (One-Time Setup):

  1. Download NHDPlus Dataset - Contains river network polylines for entire US - Each river segment has a ComID (Catchment ID) - Example: West Fork White River = ComID 23980965
  2. Process DEM Data (-getwatershed command) - Loads river network from NHDPlus - For each river segment:
  3. Tile and Store - Divides US into 1°x1° tiles (n47w121, n48w122, etc.) - Stores river segments in CSV: RIVERS/n47w121.csv - Each river has: name, coordinates, watershed stats, EPA link

Runtime (Query Processing):

  1. Client queries: winfo=47.009,-121.702
  2. Server determines tile: n47w121
  3. Loads RIVERS/n47w121.csv into cache
  4. Finds nearest river within 500m
  5. Returns pre-computed watershed data
  6. Fast response (~10ms) - no real-time computation!

Key Insight:

The system doesn't calculate watershed data on-the-fly. Instead:

  1. Pre-processing (runs once, takes days): - Queries EPA/USGS APIs for all US river segments - Stores results in tile-based CSV files
  2. Query time (milliseconds): - Simple spatial lookup in cached tile - Returns pre-fetched data

The AvgPrecip comes from EPA's NHDPlus watershed characterization service, which has pre-computed climate statistics for every river segment in the US using PRISM climate data overlaid on NHDPlus catchments.