-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* tidy generation of crossing table * fix crossings summary views and restore upstr/dnstr observation columns to output views * move crossings admin query to materialized view but do not run until source data are loaded
- Loading branch information
Showing
14 changed files
with
314 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
-- crossing feature type | ||
drop view if exists bcfishpass.crossings_feature_type_vw; | ||
create view bcfishpass.crossings_feature_type_vw as | ||
select | ||
aggregated_crossings_id, | ||
case | ||
when crossing_subtype_code = 'WEIR' then 'WEIR' | ||
when crossing_subtype_code = 'DAM' then 'DAM' | ||
-- RAIL, pscis crossings within 50m of rail line and with RAIL in the road name | ||
when | ||
rail_owner_name is not null | ||
and aggregated_crossings_id in ( | ||
select | ||
aggregated_crossings_id | ||
from bcfishpass.crossings c | ||
inner join whse_basemapping.gba_railway_tracks_sp r | ||
on st_dwithin(c.geom, r.geom, 50) | ||
where crossing_source = 'PSCIS' | ||
and upper(pscis_road_name) like '%RAIL%' and upper(pscis_road_name) not like '%TRAIL%' | ||
) | ||
then 'RAIL' | ||
-- RAIL, pscis crossings within 10m of rail line | ||
when | ||
rail_owner_name is not null | ||
and aggregated_crossings_id in ( | ||
select | ||
aggregated_crossings_id | ||
from bcfishpass.crossings c | ||
inner join whse_basemapping.gba_railway_tracks_sp r | ||
on st_dwithin(c.geom, r.geom, 10) | ||
where crossing_source = 'PSCIS' | ||
) | ||
then 'RAIL' | ||
-- modelled rail crossings | ||
when | ||
rail_owner_name is not null | ||
and crossing_source = 'MODELLED CROSSINGS' | ||
then 'RAIL' | ||
-- tenured roads | ||
when | ||
ften_forest_file_id is not NULL OR | ||
ogc_proponent is not NULL | ||
then 'ROAD, RESOURCE/OTHER' | ||
-- demographic roads | ||
when | ||
transport_line_type_description IN ( | ||
'Road alleyway', | ||
'Road arterial major', | ||
'Road arterial minor', | ||
'Road collector major', | ||
'Road collector minor', | ||
'Road freeway', | ||
'Road highway major', | ||
'Road highway minor', | ||
'Road lane', | ||
'Road local', | ||
'Private driveway demographic', | ||
'Road pedestrian mall', | ||
'Road runway non-demographic', | ||
'Road recreation demographic', | ||
'Road ramp', | ||
'Road restricted', | ||
'Road strata', | ||
'Road service', | ||
'Road yield lane' | ||
) | ||
then 'ROAD, DEMOGRAPHIC' | ||
-- trails | ||
when | ||
upper(transport_line_type_description) LIKE 'TRAIL%' | ||
then 'TRAIL' | ||
-- everything else (DRA) | ||
when | ||
transport_line_type_description is not NULL | ||
then 'ROAD, RESOURCE/OTHER' | ||
-- in the absence of any of the above info, assume a PSCIS crossing is on a resource/other road | ||
when | ||
stream_crossing_id is not NULL | ||
then 'ROAD, RESOURCE/OTHER' | ||
end as crossing_feature_type | ||
from bcfishpass.crossings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
-- below datasets are not guaranteed to exist | ||
|
||
--drop materialized view if exists bcfishpass.crossings_admin; | ||
--create materialized view bcfishpass.crossings_admin; | ||
--SELECT DISTINCT ON (c.aggregated_crossings_id) -- some of the admin areas are not clean/distinct, make sure to select just one | ||
-- c.aggregated_crossings_id, | ||
-- rd.admin_area_abbreviation as abms_regional_district, | ||
-- muni.admin_area_abbreviation as abms_municipality, | ||
-- ir.english_name as clab_indian_reserve_name, | ||
-- ir.band_name as clab_indian_reserve_band_name, | ||
-- np.english_name as clab_national_park_name, | ||
-- pp.protected_lands_name as bc_protected_lands_name, | ||
-- pmbc.owner_type as pmbc_owner_type, | ||
-- nr.region_org_unit_name as adm_nr_region, | ||
-- nr.district_name as adm_nr_district | ||
--FROM bcfishpass.crossings c | ||
--LEFT OUTER JOIN whse_legal_admin_boundaries.abms_regional_districts_sp rd | ||
--ON ST_Intersects(c.geom, rd.geom) | ||
--LEFT OUTER JOIN whse_legal_admin_boundaries.abms_municipalities_sp muni | ||
--ON ST_Intersects(c.geom, muni.geom) | ||
--LEFT OUTER JOIN whse_admin_boundaries.adm_indian_reserves_bands_sp ir | ||
--ON ST_Intersects(c.geom, ir.geom) | ||
--LEFT OUTER JOIN whse_admin_boundaries.clab_national_parks np | ||
--ON ST_Intersects(c.geom, np.geom) | ||
--LEFT OUTER JOIN whse_tantalis.ta_park_ecores_pa_svw pp | ||
--ON ST_Intersects(c.geom, pp.geom) | ||
--LEFT OUTER JOIN whse_cadastre.pmbc_parcel_fabric_poly_svw pmbc | ||
--ON ST_Intersects(c.geom, pmbc.geom) | ||
--LEFT OUTER JOIN whse_admin_boundaries.adm_nr_districts_sp nr | ||
--ON ST_Intersects(c.geom, pmbc.geom) | ||
--ORDER BY c.aggregated_crossings_id, rd.admin_area_abbreviation, muni.admin_area_abbreviation, ir.english_name, pp.protected_lands_name, pmbc.owner_type, nr.district_name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
-- downstream observations ***within the same watershed group*** | ||
drop materialized view if exists bcfishpass.crossings_dnstr_observations; | ||
|
||
create materialized view bcfishpass.crossings_dnstr_observations as | ||
select | ||
aggregated_crossings_id, | ||
array_agg(species_code) as observedspp_dnstr | ||
FROM | ||
( | ||
select distinct | ||
a.aggregated_crossings_id, | ||
unnest(species_codes) as species_code | ||
from bcfishpass.crossings a | ||
left outer join bcfishobs.fiss_fish_obsrvtn_events fo | ||
on FWA_Downstream( | ||
a.blue_line_key, | ||
a.downstream_route_measure, | ||
a.wscode_ltree, | ||
a.localcode_ltree, | ||
fo.blue_line_key, | ||
fo.downstream_route_measure, | ||
fo.wscode_ltree, | ||
fo.localcode_ltree | ||
) | ||
and a.watershed_group_code = fo.watershed_group_code | ||
order by a.aggregated_crossings_id, species_code | ||
) AS f | ||
group by aggregated_crossings_id; | ||
|
||
create index on bcfishpass.crossings_dnstr_observations (aggregated_crossings_id); | ||
|
||
|
||
-- upstream observations ***within the same watershed group*** | ||
drop materialized view if exists bcfishpass.crossings_upstr_observations; | ||
|
||
create materialized view bcfishpass.crossings_upstr_observations as | ||
select | ||
aggregated_crossings_id, | ||
array_agg(species_code) as observedspp_upstr | ||
FROM | ||
( | ||
select distinct | ||
a.aggregated_crossings_id, | ||
unnest(species_codes) as species_code | ||
from bcfishpass.crossings a | ||
left outer join bcfishobs.fiss_fish_obsrvtn_events fo | ||
on FWA_Upstream( | ||
a.blue_line_key, | ||
a.downstream_route_measure, | ||
a.wscode_ltree, | ||
a.localcode_ltree, | ||
fo.blue_line_key, | ||
fo.downstream_route_measure, | ||
fo.wscode_ltree, | ||
fo.localcode_ltree | ||
) | ||
and a.watershed_group_code = fo.watershed_group_code | ||
order by a.aggregated_crossings_id, species_code | ||
) AS f | ||
group by aggregated_crossings_id; | ||
|
||
create index on bcfishpass.crossings_upstr_observations (aggregated_crossings_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.