-
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.
restore range table and view refresh
- Loading branch information
Showing
3 changed files
with
56 additions
and
1 deletion.
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
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); |
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