Skip to content

Instantly share code, notes, and snippets.

@NewGraphEnvironment
Last active May 18, 2020 15:17
Show Gist options
  • Save NewGraphEnvironment/6b39f24b20400ec6cff45abbe1903146 to your computer and use it in GitHub Desktop.
Save NewGraphEnvironment/6b39f24b20400ec6cff45abbe1903146 to your computer and use it in GitHub Desktop.
get details of railway crossing in PARS. Plagiarized from Simon Norris - https://gist.github.com/65c3db70eccfed9cf0d7f2bc10b3d058
-- modelled crossings
SELECT
pmc.pscis_model_combined_id,
x.crossing_id as model_crossing_id,
pmc.pscis_stream_crossing_id,
x.track_name,
x.track_classification,
x.use_type,
x.gauge,
x.status,
x.operator_english_name,
x.owner_name,
x.fish_habitat,
pmc.uphab_gross_sub15,
pmc.uphab_gross_sub22,
pmc.dnstr_crossing_ids,
pmc.upstr_crossing_ids,
pmc.lake_area_ha,
pmc.manmadewb_area_ha,
pmc.wetland_area_ha,
0 as distance_to_railway,
x.geom
FROM fish_passage.modelled_crossings_closed_bottom x
INNER JOIN fish_passage.pscis_model_combined pmc
ON x.crossing_id = pmc.model_crossing_id
AND x.track_segment_id is not null
AND x.fish_habitat NOT IN ('NON FISH HABITAT', 'FISH HABITAT - INFERRED - 220-300PCT')
UNION ALL
-- pscis crossings not included in above and within 25m of a railway
SELECT
pmc.pscis_model_combined_id,
pmc.model_crossing_id,
pmc.pscis_stream_crossing_id,
r.track_name,
r.track_classification,
r.use_type,
r.gauge,
r.status,
r.operator_english_name,
r.owner_name,
pmc.fish_habitat,
pmc.uphab_gross_sub15,
pmc.uphab_gross_sub22,
pmc.dnstr_crossing_ids,
pmc.upstr_crossing_ids,
pmc.lake_area_ha,
pmc.manmadewb_area_ha,
pmc.wetland_area_ha,
r.distance_to_railway,
pmc.geom
FROM fish_passage.pscis_model_combined pmc
CROSS JOIN LATERAL
(SELECT
track_name,
track_classification,
use_type,
gauge,
status,
operator_english_name,
owner_name,
ST_Distance(rwy.geom, pmc.geom) as distance_to_railway
FROM whse_basemapping.gba_railway_tracks_sp AS rwy
ORDER BY rwy.geom <-> pmc.geom
LIMIT 1) as r
WHERE pmc.model_crossing_id IS NULL
AND r.distance_to_railway < 25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment