Skip to content

Commit

Permalink
restore range table and view refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
smnorris committed Mar 4, 2024
1 parent 779701f commit 821e417
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
52 changes: 52 additions & 0 deletions db/views/bcdata.ften_range_poly_carto_vw.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- remove range overlap for mapping
drop materialized view if exists bcdata.ften_range_poly_carto_vw;
create materialized view bcdata.ften_range_poly_carto_vw as

-- dump poly rings and convert to lines
with rings as
(
SELECT
ST_Exteriorring((ST_DumpRings((st_dump(geom)).geom)).geom) AS geom
FROM whse_forest_tenure.ften_range_poly_svw
),

-- node the lines with st_union and dump to singlepart lines
lines as
(
SELECT
(st_dump(st_union(geom, .1))).geom as geom
FROM rings
),

-- polygonize the resulting noded lines
flattened AS
(
SELECT
(ST_Dump(ST_Polygonize(geom))).geom AS geom
FROM lines
),

sorted AS
(
SELECT
d.objectid,
d.forest_file_id,
d.client_number,
d.client_name,
f.geom
FROM flattened f
LEFT OUTER JOIN whse_forest_tenure.ften_range_poly_svw d
ON ST_Contains(d.geom, ST_PointOnSurface(f.geom))
ORDER BY d.objectid
)

SELECT
row_number() over() as id,
array_agg(forest_file_id ORDER BY objectid) as forest_file_id,
array_agg(client_number ORDER BY objectid) as client_number,
array_agg(client_name ORDER BY objectid) as client_name,
geom::geometry(polygon, 3005)
FROM sorted
GROUP BY geom;

create index on bcdata.ften_range_poly_carto_vw using gist (geom);
4 changes: 3 additions & 1 deletion jobs/load_monthly
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bcdata bc2pg -r whse_basemapping.gba_transmission_lines_sp
bcdata bc2pg -r whse_basemapping.gns_geographical_names_sp
bcdata bc2pg -r whse_environmental_monitoring.envcan_hydrometric_stn_sp
bcdata bc2pg -r whse_fish.fiss_stream_sample_sites_sp
bcdata bc2pg -r whse_forest_tenure.ften_range_poly_svw
bcdata bc2pg -r whse_imagery_and_base_maps.mot_road_structure_sp
bcdata bc2pg -r whse_legal_admin_boundaries.abms_municipalities_sp
bcdata bc2pg -r whse_mineral_tenure.og_petrlm_dev_rds_pre06_pub_sp
Expand All @@ -27,4 +28,5 @@ bcdata bc2pg -r whse_tantalis.ta_park_ecores_pa_svw
jobs/whse_cadastre.pmbc_parcel_fabric_poly_svw

# additional processing
$PSQL -c "refresh materialized view bcdata.parks"
$PSQL -c "refresh materialized view bcdata.parks"
$PSQL -c "refresh materialized view bcdata.ften_range_poly_carto_vw"
1 change: 1 addition & 0 deletions jobs/setup
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ for table in whse_admin_boundaries.clab_indian_reserves \
whse_fish.pscis_design_proposal_svw \
whse_fish.pscis_habitat_confirmation_svw \
whse_fish.pscis_remediation_svw \
whse_forest_tenure.ften_range_poly_svw \
whse_forest_tenure.ften_road_section_lines_svw \
whse_imagery_and_base_maps.mot_road_structure_sp \
whse_legal_admin_boundaries.abms_municipalities_sp \
Expand Down

0 comments on commit 821e417

Please sign in to comment.