Skip to content

Commit

Permalink
Merge branch 'main' into tracking-table-views
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewp-CWF authored Nov 8, 2024
2 parents 269a31a + fd7a2e2 commit f8c3200
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 30 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/production-load-monthly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ on:
workflow_dispatch:
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
DRAPWD: ${{ secrets.DRAPWD }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_ENDPOINT_URL: https://nrs.objectstore.gov.bc.ca
AWS_S3_ENDPOINT: nrs.objectstore.gov.bc.ca
AWS_VIRTUAL_HOSTING: FALSE
AWS_EC2_METADATA_DISABLED: True
CPL_VSISTDIN_BUFFER_LIMIT: -1
jobs:
data-refresh:
runs-on: ubuntu-latest
Expand All @@ -15,4 +23,6 @@ jobs:
- name: Check out repository code
uses: actions/checkout@v4
- name: Run the jobs
run: jobs/load_monthly
run: |
jobs/replicate_dra
jobs/load_monthly
30 changes: 14 additions & 16 deletions data/user_modelled_crossing_fixes.csv
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@ modelled_crossing_id,structure,watershed_group_code,reviewer_name,review_date,so
4602803,NONE,ELKR,AL,2021-01-01,Bing/Google/ESRI imagery,no road/structure
4602864,NONE,ELKR,AL,2021-01-01,Bing/Google/ESRI imagery,no road/structure
4602883,OBS,ELKR,AL,2021-01-01,Bing/Google/ESRI imagery,
4602974,OBS,ELKR,AI,2021-01-01,Bing/Google/ESRI imagery,bridge
4603111,OBS,ELKR,AL,2021-01-01,Bing/Google/ESRI imagery,
4603133,NONE,ELKR,AL,2021-01-01,Bing/Google/ESRI imagery,no road/structure
4603202,OBS,ELKR,AL,2021-01-01,Bing/Google/ESRI imagery,
Expand Down Expand Up @@ -7862,7 +7861,6 @@ modelled_crossing_id,structure,watershed_group_code,reviewer_name,review_date,so
2300212,,CARR,KK,2022-01-28,Bing/Google/ESRI imagery,
2300235,,CARR,KK,2022-01-28,Bing/Google/ESRI imagery,
2300260,,CARR,KK,2022-01-28,Bing/Google/ESRI imagery,
2300291,,CARR,KK,2022-01-27,Bing/Google/ESRI imagery,
2300378,,CARR,KK,2022-01-27,Bing/Google/ESRI imagery,
2300391,,CARR,KK,2022-01-27,Bing/Google/ESRI imagery,
2300643,,CARR,KK,2022-01-27,Bing/Google/ESRI imagery,
Expand Down Expand Up @@ -15764,7 +15762,6 @@ modelled_crossing_id,structure,watershed_group_code,reviewer_name,review_date,so
17100095,,QUES,KK,2022-03-10,Bing/Google/ESRI imagery,
17100096,,QUES,KK,2022-03-10,Bing/Google/ESRI imagery,
17100097,,QUES,KK,2022-03-10,Bing/Google/ESRI imagery,
17100098,,QUES,KK,2022-03-10,Bing/Google/ESRI imagery,
17100106,,QUES,KK,2022-03-02,Bing/Google/ESRI imagery,
17100108,,QUES,KK,2022-03-10,Bing/Google/ESRI imagery,
17100114,,QUES,KK,2022-03-11,Bing/Google/ESRI imagery,
Expand Down Expand Up @@ -21060,19 +21057,19 @@ modelled_crossing_id,structure,watershed_group_code,reviewer_name,review_date,so
23800103,NONE,USHU,LS,2024-06-26,Bing/Google/ESRI imagery,duplicate crossing - removed in favour of d/s location
18300160,NONE,SHUL,LS,2024-06-26,Bing/Google/ESRI imagery,redundant mulit-lane highway crossing - removed in favour of most d/s location
23800079,OBS,USHU,LS,2025-06-28,Bing/Google/ESRI imagery,bridge visible
17104186,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessments,No channel or water. Culvert on side road connecting manmade ditch line along road.
1501277,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessments,"No culvert, Low marshy ground on either side of road. No Channel. Small lake to south, wetland to north. Depression in road possibly from culvert removal."
1501283,NONE,BOWR,MC,2024-07-08,Lhtako Dene WCRP Field Assessments,"No sign of a crossing, but old grown in road nearby. Wetland downstream. "
1501281,NONE,BOWR,MC,2024-07-08,Lhtako Dene WCRP Field Assessments,"No culvert. Old road crossing pulled 10+ years ago. Alder, large cobbles. "
1501282,NONE,BOWR,MC,2024-07-08,Lhtako Dene WCRP Field Assessments,"No crossing, no passage issues. Fish in stream."
17103908,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessments,No Barrier or culvert. No water/wetland.
17100487,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessments,"In bush off Horsefly/Likely FSR. Very old road, overgrown. No water or channel seen, slightly wet corridor."
17100488,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessments,"In bush off Horsefly/Likely FSR. Very old road, overgrown. No water or channel seen, slightly wet corridor."
17103896,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessments,"Old clear area, may be part of mine. Cleared in the last 1-3 years. Small (2x2m) wetland with cattails seen, but no water or streams. No culverts. "
17102208,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessments,"Very old road, overgrown. No crossing found. Slightly wet area but no water seen. "
17102191,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessments,"No water or wetland. Possible culvert removed at old road, shallow overgrown ditch. No culvert seen. "
17100098,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessments,No wetland/water. No culvert seen on road. Private property on either side of road.
17102374,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessments,Cannot find inlet. Bottom of culvert disintegrated where it touches ground. No water.
17104186,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessment 2023,No channel or water. Culvert on side road connecting manmade ditch line along road.
1501277,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessment 2023,"No culvert, Low marshy ground on either side of road. No Channel. Small lake to south, wetland to north. Depression in road possibly from culvert removal."
1501283,NONE,BOWR,MC,2024-07-08,Lhtako Dene WCRP Field Assessment 2023,"No sign of a crossing, but old grown in road nearby. Wetland downstream. "
1501281,NONE,BOWR,MC,2024-07-08,Lhtako Dene WCRP Field Assessment 2023,"No culvert. Old road crossing pulled 10+ years ago. Alder, large cobbles. "
1501282,NONE,BOWR,MC,2024-07-08,Lhtako Dene WCRP Field Assessment 2023,"No crossing, no passage issues. Fish in stream."
17103908,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessment 2023,No Barrier or culvert. No water/wetland.
17100487,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessment 2023,"In bush off Horsefly/Likely FSR. Very old road, overgrown. No water or channel seen, slightly wet corridor."
17100488,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessment 2023,"In bush off Horsefly/Likely FSR. Very old road, overgrown. No water or channel seen, slightly wet corridor."
17103896,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessment 2023,"Old clear area, may be part of mine. Cleared in the last 1-3 years. Small (2x2m) wetland with cattails seen, but no water or streams. No culverts. "
17102208,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessment 2023,"Very old road, overgrown. No crossing found. Slightly wet area but no water seen. "
17102191,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessment 2023,"No water or wetland. Possible culvert removed at old road, shallow overgrown ditch. No culvert seen. "
17100098,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessment 2023,No wetland/water. No culvert seen on road. Private property on either side of road.
17102374,NONE,QUES,MC,2024-07-08,Lhtako Dene WCRP Field Assessment 2023,Cannot find inlet. Bottom of culvert disintegrated where it touches ground. No water.
17104186,NONE,QUES,MC,2024-07-08,WCRP partner field assessments,No channel or water. Culvert on side road connecting manmade ditch line along road.
1400691,OBS,BONP,LB,2024-07-11,imagery,
1404128,OBS,BONP,LB,2024-07-11,imagery,
Expand All @@ -21089,3 +21086,4 @@ modelled_crossing_id,structure,watershed_group_code,reviewer_name,review_date,so
1405747,FORD,BONP,LB,2024-07-11,imagery,
11302064,NONE,LNIC,LB,2024-07-16,imagery,Ortho image indicates the stream has likely migrated/been redirected to the north and no longer crosses this road.
11301333,OBS,LNIC,LB,2024-07-16,imagery,Appears to be a bridge on sat imagery- stream goes to north of where it's mapped
2300291,NONE,CARR,LB,2024-11-04,Lhtako Dene WCRP Field Assessment 2023,"River left has an old concrete, log, and metal cribbing structure located on the bank immediately adjacent to the stream, perhaps used to draft water from stream. Large angle iron driven vertically into stream bed and intake pipe visible in stream bed. No manmade barrier to fish passage at this location but there is a beaver dam present immediately downstream of structure"
8 changes: 4 additions & 4 deletions db/v0.5.3/sql/join_tracking_table_crossings_vw.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ as
$$
begin
execute format('create or replace view wcrp_%I.combined_tracking_table_crossings_wcrp_vw_%I as
select
tt.barrier_id,
cv.crossing_source,
select
tt.barrier_id,
cv.crossing_source,
cv.crossing_feature_type,
cv.pscis_status,
cv.crossing_type_code,
Expand Down Expand Up @@ -85,7 +85,7 @@ begin
cv.rank_combined,
cv.tier_combined,
cv.geom,
tt.internal_name,
tt.internal_name,
tt.watercourse_name,
tt.road_name,
tt.structure_type,
Expand Down
8 changes: 8 additions & 0 deletions db/v0.5.4/migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -euxo pipefail

# update DRA table
psql $DATABASE_URL -v ON_ERROR_STOP=1 -f sql/dra.sql

# note version
psql $DATABASE_URL -v ON_ERROR_STOP=1 -c "update bcfishpass.db_version set tag = '${PWD##*/}'"
81 changes: 81 additions & 0 deletions db/v0.5.4/sql/dra.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
-- drop non public columns from dra transport line
BEGIN;

ALTER TABLE whse_basemapping.transport_line
drop column create_integration_session_id,
drop column create_integration_date,
drop column modify_integration_session_id,
drop column modify_integration_date,
drop column create_partner_org_id,
drop column create_partner_org,
drop column modify_partner_org_id,
drop column modify_partner_org,
drop column custodian_partner_org_id,
drop column z_value_derived_ind,
drop column deactivation_date,
drop column transport_line_divided_code,
drop column travel_direction_code,
drop column speed_limit,
drop column left_number_of_lanes,
drop column right_number_of_lanes,
drop column under_construction_ind,
drop column virtual_ind,
drop column disaster_route_ind,
drop column truck_route_ind,
drop column left_locality_id,
drop column left_locality,
drop column right_locality_id,
drop column right_locality,
drop column left_regional_district_id,
drop column right_regional_district_id,
drop column structured_name_1_id,
drop column structured_name_2_id,
drop column structured_name_3_id,
drop column structured_name_4_id,
drop column structured_name_5_id,
drop column structured_name_6_id,
drop column structured_name_6,
drop column structured_name_7_id,
drop column structured_name_7,
drop column highway_route_2,
drop column highway_route_3,
drop column industry_name_1,
drop column industry_name_2,
drop column industry_name_3,
drop column single_house_number,
drop column left_house_num_scheme_code,
drop column from_left_house_number,
drop column to_left_house_number,
drop column right_house_num_scheme_code,
drop column from_right_house_number,
drop column to_right_house_number,
drop column lane_restriction_code,
drop column access_restriction_code,
drop column from_traffic_impactor_code,
drop column to_traffic_impactor_code,
drop column from_left_turn_time_code,
drop column from_centre_turn_time_code,
drop column from_right_turn_time_code,
drop column to_left_turn_time_code,
drop column to_centre_turn_time_code,
drop column to_right_turn_time_code,
drop column from_vehicle_max_weight_kg,
drop column to_vehicle_max_weight_kg,
drop column from_vehicle_max_width_metre,
drop column to_vehicle_max_width_metre,
drop column from_vehicle_max_height_metre,
drop column to_vehicle_max_height_metre,
drop column ministry_of_transport_id,
drop column ministry_of_transport_name,
drop column integration_notes,
drop column excluded_rules,
drop column demographic_ind,
drop column extended_data,
drop column ministry_of_transport_data,
drop column from_navigation_rules,
drop column along_navigation_rules,
drop column to_navigation_rules,
drop column from_transport_node_point_id,
drop column to_transport_node_point_id;

COMMIT;
48 changes: 39 additions & 9 deletions jobs/load_monthly
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ bcdata bc2pg -r whse_mineral_tenure.og_petrlm_dev_rds_pre06_pub_sp
bcdata bc2pg -r whse_tantalis.ta_conservancy_areas_svw
bcdata bc2pg -r whse_tantalis.ta_park_ecores_pa_svw

# DRA
mkdir -p tmp
# **
# ** note temp dra data cache, to be replaced with new download location or a bc2pg download **
# **
#curl ftp://ftp.geobc.gov.bc.ca/sections/outgoing/bmgs/DRA_Public/dgtl_road_atlas.gdb.zip \
# -o tmp/dgtl_road_atlas.gdb.zip
# load DRA from bchamp bucket (with public portion of source transport_line schema)
$PSQL -c "drop table if exists bcdata.transport_line" # in case of any failed loads
ogr2ogr \
-f PostgreSQL \
Expand All @@ -40,10 +34,46 @@ ogr2ogr \
-lco GEOMETRY_NAME=geom \
-lco FID=transport_line_id \
-nln bcdata.transport_line \
/vsizip//vsicurl/https://bcfishpass.s3.us-west-2.amazonaws.com/dgtl_road_atlas.gdb.zip \
/vsizip//vsicurl/https://nrs.objectstore.gov.bc.ca/bchamp/transport_line.gpkg.zip \
TRANSPORT_LINE
$PSQL -c "truncate whse_basemapping.transport_line;
insert into whse_basemapping.transport_line select * from bcdata.transport_line"
insert into whse_basemapping.transport_line
(
transport_line_id,
custodian_partner_org,
capture_date,
data_capture_method_code,
total_number_of_lanes,
structured_name_1,
structured_name_2,
structured_name_3,
structured_name_4,
structured_name_5,
highway_route_1,
highway_exit_number,
transport_line_type_code,
transport_line_surface_code,
transport_line_structure_code,
geom
)
select
transport_line_id,
custodian_partner_org,
capture_date,
data_capture_method_code,
total_number_of_lanes,
structured_name_1,
structured_name_2,
structured_name_3,
structured_name_4,
structured_name_5,
highway_route_1,
highway_exit_number,
transport_line_type_code,
transport_line_surface_code,
transport_line_structure_code,
geom
from bcdata.transport_line"
$PSQL -c "drop table bcdata.transport_line"

# parcel fabric, renaming download so it can be read without unzipping
Expand Down
47 changes: 47 additions & 0 deletions jobs/replicate_dra
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -euxo pipefail

# We do not use the official public DRA data because it no longer matches our db schema
# Replicate public portion of password protected DRA distribution to publicly accessible file
# (requires $DRAPWD)

# download
curl \
-o /tmp/transport_line.gdb.zip \
https://nrs.objectstore.gov.bc.ca/itqlyp/GBA/PROVINCE/transport_line.gdb.zip

# extract password protected zipfile
unzip \
-P $DRAPWD \
-d /tmp \
-o \
/tmp/transport_line.gdb.zip

# post public portion of dataset to bchamp object storage
ogr2ogr \
-f GPKG \
/tmp/transport_line.gpkg.zip \
/tmp/transport_line.gdb \
-sql "select
TRANSPORT_LINE_ID,
CUSTODIAN_PARTNER_ORG,
CAPTURE_DATE,
DATA_CAPTURE_METHOD_CODE,
TOTAL_NUMBER_OF_LANES,
STRUCTURED_NAME_1,
STRUCTURED_NAME_2,
STRUCTURED_NAME_3,
STRUCTURED_NAME_4,
STRUCTURED_NAME_5,
HIGHWAY_ROUTE_1,
HIGHWAY_EXIT_NUMBER,
TRANSPORT_LINE_TYPE_CODE,
TRANSPORT_LINE_SURFACE_CODE,
TRANSPORT_LINE_STRUCTURE_CODE,
GEOMETRY
from TRANSPORT_LINE"

aws s3 cp /tmp/transport_line.gpkg.zip s3://bchamp --acl public-read

rm /tmp/transport_line.gdb.zip
rm /tmp/transport_line.gpkg.zip

0 comments on commit f8c3200

Please sign in to comment.