fwapg
Extends British Columbia's Freshwater Atlas with PostgreSQL/PostGIS.
https://github.com/smnorris/fwapg
Category: Hydrosphere
Sub Category: Freshwater and Hydrology
Keywords
british-columbia freshwater-atlas fwa lakes linear-referencing postgis rivers streams watersheds
Last synced: about 24 hours ago
JSON representation
Repository metadata
PostgreSQL tools for working with British Columbia's Freshwater Atlas
- Host: GitHub
- URL: https://github.com/smnorris/fwapg
- Owner: smnorris
- License: mit
- Created: 2019-05-07T15:07:42.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2026-01-16T22:53:25.000Z (about 2 months ago)
- Last Synced: 2026-02-10T13:50:03.443Z (28 days ago)
- Topics: british-columbia, freshwater-atlas, fwa, lakes, linear-referencing, postgis, rivers, streams, watersheds
- Language: PLpgSQL
- Homepage: https://smnorris.github.io/fwapg
- Size: 9.55 MB
- Stars: 10
- Watchers: 2
- Forks: 5
- Open Issues: 33
- Releases: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.txt
- License: LICENSE.txt
README.md
fwapg
fwapg extends British Columbia's Freshwater Atlas (FWA) with PostgreSQL/PostGIS. fwapg provides additional tables, indexes and functions to:
- quickly translate arbitrary point locations (
X,Y) to a linear reference positions (blue_line_key, measure) on the stream network - enable speedy upstream/downstream queries throughout BC
- quickly and cleanly generate watershed boundaries upstream of arbitrary locations
- enable cross-boundary queries by combining FWA data with data from neighbouring jurisdictions
- enable querying of FWA features via spatial SQL
- provide
gradientvalues for every FWA stream - enable quickly serving FWA features as vector tiles (MVT)
- enable quickly serving FWA features and custom fwapg functions
- link additional data to FWA streams (PCIC mean annual discharge, modelled channel width, upstream precipitation)
See documentation for setup and usage details, plus table and function references.
Quickstart
- Ensure all requirements/dependencies are met/installed.
- access to a PostgreSQL (>13) database with the PostGIS extension
- GDAL >=3.6
- Python 3
bcdata
See the Dockerfile for the full list of dependencies.
-
Ensure you have a
DATABASE_URLenvironment variable set to point to your database, for example:export DATABASE_URL=postgresql://username:password@localhost:5432/fwapg -
Get scripts, load and optimize the data:
git clone https://github.com/smnorris/fwapg.git cd fwapg cd db && ./create.sh && cd .. # load extensions, create schemas/tables ./load.sh # load the data
The full load takes some time - but once complete, you can run fwapg enabled queries with your favorite sql client. For example:
Locate the nearest point on the FWA stream network to a X,Y location on Highway 14:
SELECT
gnis_name,
blue_line_key,
downstream_route_measure
FROM FWA_IndexPoint(ST_Transform(ST_GeomFromText('POINT(-123.7028 48.3858)', 4326), 3005));
gnis_name | blue_line_key | downstream_route_measure
-------------+---------------+--------------------------
Sooke River | 354153927 | 350.2530543284006
Generate the watershed upstream of this location:
SELECT ST_ASText(geom) FROM FWA_WatershedAtMeasure(354153927, 350);
st_astext
--------------
POLYGON((...
Select all stream upstream of this location:
SELECT ST_ASText(geom)
FROM FWA_UpstreamTrace(354153927, 350);
st_astext
--------------
LINESTRINGZM((...
See Usage for more examples.
Tile and feature services
fwapg features and functions are served from hillcrestgeo.ca as GeoJSON or vector tiles via these web services and wrappers:
- features.hillcrestgeo.ca/fwa: tables and functions served as GeoJSON
- fwapgr (R): an R wrapper around the
features.hillcrestgeo.ca/fwafeature service - fwatlasbc (R): an R package for higher level queries
- tiles.hillcrestgeo.ca/bcfishpass: FWA features (and others) served as vector tiles (MVT)
Source data
-
BC Freshwater Atlas documentation and license
-
BC stream contributing areas (watershed boundaries) outside of BC were provided by Dan Weller, DFO
Development and testing
Extremely basic tests are included for selected functions.
If changing a covered function, run the individual test. For example:
psql -f tests/test_fwa_upstream.sql
All results should be true.
Documentation
Documentation is built from the markdown files in /docs.
Info in the table reference page (02_tables_views.md) can be autogenerated from comments in the database. To dump the text to stdout:
cd docs
./table_reference.sh
Owner metadata
- Name: Simon Norris
- Login: smnorris
- Email:
- Kind: user
- Description:
- Website: www.hillcrestgeo.ca
- Location: British Columbia
- Twitter:
- Company: Hillcrest Geographics
- Icon url: https://avatars.githubusercontent.com/u/1323293?v=4
- Repositories: 52
- Last ynced at: 2025-10-10T16:35:26.744Z
- Profile URL: https://github.com/smnorris
GitHub Events
Total
- Delete event: 6
- Pull request event: 10
- Issues event: 17
- Issue comment event: 17
- Push event: 77
- Create event: 11
Last Year
- Delete event: 2
- Pull request event: 4
- Issues event: 11
- Issue comment event: 11
- Push event: 58
- Create event: 5
Committers metadata
Last synced: 8 days ago
Total Commits: 476
Total Committers: 2
Avg Commits per committer: 238.0
Development Distribution Score (DDS): 0.029
Commits in past year: 30
Committers in past year: 1
Avg Commits per committer in past year: 30.0
Development Distribution Score (DDS) in past year: 0.0
| Name | Commits | |
|---|---|---|
| Simon Norris | s****s@h****a | 462 |
| franTarkenton | k****n@g****a | 14 |
Committer domains:
- gov.bc.ca: 1
- hillcrestgeo.ca: 1
Issue and Pull Request metadata
Last synced: 24 days ago
Total issues: 115
Total pull requests: 31
Average time to close issues: 2 months
Average time to close pull requests: 3 days
Total issue authors: 6
Total pull request authors: 2
Average comments per issue: 1.13
Average comments per pull request: 0.03
Merged pull request: 27
Bot issues: 0
Bot pull requests: 0
Past year issues: 11
Past year pull requests: 8
Past year average time to close issues: 18 days
Past year average time to close pull requests: about 9 hours
Past year issue authors: 1
Past year pull request authors: 1
Past year average comments per issue: 1.18
Past year average comments per pull request: 0.13
Past year merged pull request: 7
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- smnorris (108)
- joethorley (3)
- paddleman (1)
- NewGraphEnvironment (1)
- daimoriwaki (1)
- heckstra (1)
Top Pull Request Authors
- smnorris (30)
- franTarkenton (1)
Top Issue Labels
- bug (24)
- enhancement (9)
- data (2)
- advertising (1)
Top Pull Request Labels
Dependencies
- myst_parser *
- sphinx_rtd_theme *
- actions/checkout v3 composite
- docker/build-push-action f2a1d5e99d037542a71f64918e516c093c6f3fc4 composite
- docker/login-action 65b78e6e13532edd9afa3aa52ac7964289d1a9c1 composite
- docker/metadata-action 9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 composite
- actions/checkout master composite
- ad-m/github-push-action master composite
- erpcya/sphinx-action feature/#update-sphinx-base-image composite
- ghcr.io/osgeo/gdal ubuntu-small-3.8.0 build
- postgis/postgis 16-3.4
- pramsey/pg_featureserv latest
- pramsey/pg_tileserv latest
Score: 4.454347296253507