Skip to content

Commit 3c43bdd

Browse files
authored
Xborder (#185)
* fix #182 * add xborder polys table, load from s3 * remove xborder warning from upstream lookup readme, update cw script and fix issue in measured cw query * update discharge processing to use shell script (instead of make) and remove xborder caveat * upgrade gdal, downgrade awscli, document climr download for transborder precip * document xborder source and load, fix readme path to db create, start precip update * tidy * add jq to docker image, do not load nhd or hydrosheds, get precip for wsds not covered by climatebc grid from climr grid * update fwa_watershedatmeasure to use new xborder data, update docs * add xborder load query
1 parent ceb65ea commit 3c43bdd

30 files changed

+847
-782
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ghcr.io/osgeo/gdal:ubuntu-full-3.10.3
1+
FROM ghcr.io/osgeo/gdal:ubuntu-full-3.12.1
22

33
RUN apt-get update && apt-get --assume-yes upgrade \
44
&& apt-get -qq install -y --no-install-recommends postgresql-common \
@@ -16,9 +16,10 @@ RUN apt-get update && apt-get --assume-yes upgrade \
1616
&& apt-get -qq install -y --no-install-recommends python3-dev \
1717
&& apt-get -qq install -y --no-install-recommends python3-venv \
1818
&& apt-get -qq install -y --no-install-recommends python3-psycopg2 \
19+
&& apt-get -qq install -y --no-install-recommends jq \
1920
&& rm -rf /var/lib/apt/lists/*
2021

21-
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
22+
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.22.21.zip" -o "awscliv2.zip" \
2223
&& unzip awscliv2.zip \
2324
&& ./aws/install
2425

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ See [documentation](https://smnorris.github.io/fwapg/) for setup and usage detai
1717

1818
## Quickstart
1919

20-
1. Ensure all requirements/dependencies are met/installed:
20+
1. Ensure all requirements/dependencies are met/installed.
2121
- access to a PostgreSQL (>13) database with the PostGIS extension
2222
- GDAL >=3.6
2323
- Python 3
2424
- [`bcdata`](https://github.com/smnorris/bcdata)
25-
- [`make`](https://www.gnu.org/software/make/)/`unzip`/`curl`/`awscli`/ etc (see Dockerfile)
25+
26+
See the Dockerfile for the full list of dependencies.
27+
2628

2729
2. Ensure you have a `DATABASE_URL` environment variable set to point to your database, for example:
2830

@@ -32,7 +34,7 @@ See [documentation](https://smnorris.github.io/fwapg/) for setup and usage detai
3234

3335
git clone https://github.com/smnorris/fwapg.git
3436
cd fwapg
35-
cd data && ./create.sh && cd .. # load extensions, create schemas/tables
37+
cd db && ./create.sh && cd .. # load extensions, create schemas/tables
3638
./load.sh # load the data
3739

3840
The full load takes some time - but once complete, you can run `fwapg` enabled queries with your favorite sql client. For example:
@@ -67,7 +69,7 @@ The full load takes some time - but once complete, you can run `fwapg` enabled q
6769
LINESTRINGZM((...
6870

6971

70-
See [Usage](https://smnorris.github.io/fwapg/02_usage.html) for more examples.
72+
See [Usage](https://smnorris.github.io/fwapg/01_usage.html) for more examples.
7173

7274

7375
## Tile and feature services
@@ -84,10 +86,7 @@ See [Usage](https://smnorris.github.io/fwapg/02_usage.html) for more examples.
8486

8587
- BC Freshwater Atlas [documentation](https://www2.gov.bc.ca/gov/content/data/geographic-data-services/topographic-data/freshwater) and [license](https://www2.gov.bc.ca/gov/content/data/open-data/open-government-licence-bc)
8688

87-
- USGS Watershed Boundary Dataset (WBD) [Metadata](https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/WBD/National/GDB/WBD_National_GDB.xml)
88-
89-
- Hydrosheds [License and citation](https://www.hydrosheds.org/page/license)
90-
89+
- BC stream contributing areas (watershed boundaries) outside of BC were provided by Dan Weller, DFO
9190

9291
## Development and testing
9392

@@ -101,7 +100,7 @@ All results should be true.
101100
## Documentation
102101

103102
Documentation is built from the markdown files in `/docs`.
104-
Info in the table reference page (`03_tables.md`) can be autogenerated from comments in the database. To dump the text to stdout:
103+
Info in the table reference page (`02_tables_views.md`) can be autogenerated from comments in the database. To dump the text to stdout:
105104
```
106105
cd docs
107106
./table_reference.sh

db/sql/FWA_WatershedAtMeasure.sql

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -283,22 +283,6 @@ begin
283283
FROM FWA_SliceWatershedAtPoint(v_blkey, v_measure) slice
284284
),
285285

286-
-- find any upstream contributing area outside of BC (but not including Alaska panhandle)
287-
exbc AS
288-
(
289-
SELECT hydrosheds.hydroshed(h.hybas_id) AS geom
290-
FROM ref_point s
291-
INNER JOIN hydrosheds.hybas_lev12_v1c h
292-
ON ST_Intersects(h.geom, s.geom_pt)
293-
WHERE FWA_UpstreamBorderCrossings(s.blue_line_key, s.measure_pt) IN ('AB_120','YTNWT_60')
294-
UNION ALL
295-
SELECT FWA_Huc12(h.huc12) AS geom
296-
FROM ref_point s
297-
INNER JOIN usgs.wbdhu12 h
298-
ON ST_intersects(h.geom, s.geom_pt)
299-
WHERE FWA_UpstreamBorderCrossings(s.blue_line_key, s.measure_pt) = 'USA_49'
300-
),
301-
302286
-- aggregate the result and dump to singlepart
303287
agg as
304288
(

db/sql/schema.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,34 @@ create index fwa_watersheds_geom_idx on whse_basemapping.fwa_watersheds_poly usi
504504

505505
-- ---------------------------------------------------------------------------------------------------------------------
506506

507+
-- cross border watershed polygons, provided by DFO
508+
create table whse_basemapping.fwa_watersheds_xborder_poly (
509+
watershed_feature_id integer primary key ,
510+
watershed_group_id integer not null ,
511+
watershed_key integer not null ,
512+
fwa_watershed_code character varying(143) not null,
513+
local_watershed_code character varying(143) not null,
514+
watershed_group_code character varying(4) not null,
515+
watershed_order integer ,
516+
watershed_magnitude integer ,
517+
local_watershed_order integer ,
518+
local_watershed_magnitude integer ,
519+
feature_code character varying(10) ,
520+
wscode_ltree ltree generated always as (replace(replace(fwa_watershed_code, '-000000', ''), '-', '.')::ltree) stored,
521+
localcode_ltree ltree generated always as (replace(replace(local_watershed_code, '-000000', ''), '-', '.')::ltree) stored,
522+
geom public.geometry(multipolygon,3005)
523+
);
524+
create index fwa_wsd_xborder_watershed_key_idx on whse_basemapping.fwa_watersheds_xborder_poly (watershed_key);
525+
create index fwa_wsd_xborder_watershed_group_code_idx on whse_basemapping.fwa_watersheds_xborder_poly (watershed_group_code);
526+
create index fwa_wsd_xborder_watershed_group_id_idx on whse_basemapping.fwa_watersheds_xborder_poly (watershed_group_id);
527+
create index fwa_wsd_xborder_wsc_gist_idx on whse_basemapping.fwa_watersheds_xborder_poly using gist (wscode_ltree);
528+
create index fwa_wsd_xborder_wsc_btree_idx on whse_basemapping.fwa_watersheds_xborder_poly using btree (wscode_ltree);
529+
create index fwa_wsd_xborder_lc_gist_idx on whse_basemapping.fwa_watersheds_xborder_poly using gist (localcode_ltree);
530+
create index fwa_wsd_xborder_lc_btree_idx on whse_basemapping.fwa_watersheds_xborder_poly using btree (localcode_ltree);
531+
create index fwa_wsd_xborder_geom_idx on whse_basemapping.fwa_watersheds_xborder_poly using gist (geom);
532+
533+
-- ---------------------------------------------------------------------------------------------------------------------
534+
507535
create table whse_basemapping.fwa_wetlands_poly (
508536
waterbody_poly_id integer primary key,
509537
watershed_group_id integer,

docker-compose.yml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,6 @@ services:
2929
- PGUSER=postgres
3030
- PGPASSWORD=postgres
3131
- DATABASE_URL=postgresql://postgres:postgres@db:5432/fwapg
32-
depends_on:
33-
db:
34-
condition: service_healthy
35-
featureserv:
36-
image: pramsey/pg_featureserv:latest
37-
container_name: fwapg-fs
38-
ports:
39-
- ${FS_PORT}:9000
40-
volumes:
41-
- "./:/home/fwapg"
42-
environment:
43-
- DATABASE_URL=postgresql://postgres:postgres@db:5432/fwapg
44-
depends_on:
45-
db:
46-
condition: service_healthy
47-
tileserv:
48-
image: pramsey/pg_tileserv:latest
49-
container_name: fwapg-ts
50-
ports:
51-
- ${TS_PORT}:7800
52-
volumes:
53-
- "./:/home/fwapg"
54-
environment:
55-
- DATABASE_URL=postgresql://postgres:postgres@db:5432/fwapg
5632
depends_on:
5733
db:
5834
condition: service_healthy

docs/01_setup.md

Lines changed: 0 additions & 64 deletions
This file was deleted.

docs/02_usage.md renamed to docs/01_usage.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
This document presumes a working familiarity with FWA data and spatial SQL queries with PostgreSQL/PostGIS.
44

5+
## Installation / setup
6+
7+
See the README
58

69
## Upstream / downstream analysis
710

File renamed without changes.
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -910,10 +910,7 @@ watershed in which it falls, then that fundamental watershed is not included in
910910
4. If the point is < 50 m upstream from the bottom of the fundamental
911911
watershed in which it falls, then that watershed is included in the aggregation
912912

913-
For cross-boundary watersheds, the function returns non-BC areas using these data sources:
914-
915-
- USGS [huc12 watersheds](https://www.usgs.gov/core-science-systems/ngp/national-hydrography/watershed-boundary-dataset?qt-science_support_page_related_con=4#qt-science_support_page_related_con) for USA (WA, ID, MT only)
916-
- [hydrosheds](https://www.hydrosheds.org) watersheds for other neighbouring jurisdictions
913+
For trans-boundary watersheds, the results include non-BC areas (not present in the FWA) thanks to data [provided by DFO](https://github.com/smnorris/fwapg/tree/main/extras/xborder).
917914

918915
The table returned includes these columns:
919916

@@ -981,7 +978,7 @@ The `refine_method` field in the output table has several possible values:
981978
100.064535.057628 | 100.064535.057628.634957 | 33478.28 | LAKE |
982979
```
983980

984-
Mapped, the geometry looks like this - FWA heights of land in BC, HUC12 heights of land in the USA:
981+
Mapped, the geometry looks like this - the USA portion of the watershed is included:
985982

986983
![watershed](images/watershed6.png)
987984

docs/index.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ fwapg
2323
:maxdepth: 2
2424
:caption: Contents:
2525

26-
01_setup
27-
02_usage
28-
03_tables_views
29-
04_functions
26+
01_usage
27+
02_tables_views
28+
03_functions

0 commit comments

Comments
 (0)