-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix data/vm_communes: add VM for subdivided areas
Improve the creation of t_mailles_territoire. Fix #372. fix(data): improve the creation of t_mailles_territoire
- Loading branch information
Showing
4 changed files
with
118 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
DROP TABLE IF EXISTS atlas.t_mailles_territoire; | ||
|
||
-- MV for having only meshs of the territory | ||
CREATE TABLE atlas.t_mailles_territoire | ||
AS SELECT | ||
st_transform(c.geom, 4326) AS the_geom, | ||
st_asgeojson(st_transform(c.geom, 4326)) AS geojson_maille, | ||
c.id_area AS id_maille | ||
FROM ref_geo.l_areas c | ||
JOIN ref_geo.bib_areas_types t ON t.id_type = c.id_type | ||
JOIN atlas.t_layer_territoire mt ON ST_intersects(c.geom,st_transform(mt.the_geom, find_srid('ref_geo', 'l_areas', 'geom'))) | ||
WHERE c.enable = true AND t.type_code = :type_maille; | ||
CREATE TABLE atlas.t_mailles_territoire AS | ||
WITH areas AS ( | ||
SELECT | ||
id_area, | ||
st_transform(c.geom, 4326) AS geom, | ||
geojson_4326 AS geojson | ||
FROM ref_geo.l_areas AS c | ||
JOIN ref_geo.bib_areas_types AS t | ||
ON t.id_type = c.id_type | ||
WHERE c.enable = true | ||
AND t.type_code = :type_maille | ||
) | ||
SELECT | ||
a.geom AS the_geom, | ||
a.geojson AS geojson_maille, | ||
a.id_area AS id_maille | ||
FROM areas AS a | ||
WHERE EXISTS ( | ||
SELECT 'X' | ||
FROM atlas.vm_subdivided_area AS sa | ||
WHERE sa.code = 'territory' | ||
AND st_intersects(a.geom, sa.geom) | ||
); | ||
|
||
CREATE UNIQUE INDEX t_mailles_territoire_id_maille_idx ON atlas.t_mailles_territoire USING btree (id_maille); | ||
CREATE UNIQUE INDEX t_mailles_territoire_id_maille_idx ON atlas.t_mailles_territoire USING btree (id_maille); |
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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
-- Communes contenues entièrement dans le territoire | ||
|
||
CREATE MATERIALIZED VIEW atlas.vm_communes AS | ||
SELECT c.insee, | ||
c.commune_maj, | ||
c.the_geom, | ||
st_asgeojson(st_transform(c.the_geom, 4326)) as commune_geojson | ||
FROM atlas.l_communes c | ||
JOIN atlas.t_layer_territoire t ON ST_CONTAINS(ST_BUFFER(t.the_geom,200), c.the_geom); | ||
SELECT | ||
c.insee, | ||
c.commune_maj, | ||
c.the_geom, | ||
st_asgeojson(st_transform(c.the_geom, 4326)) AS commune_geojson | ||
FROM atlas.l_communes AS c | ||
WHERE EXISTS ( | ||
SELECT 'X' | ||
FROM atlas.vm_subdivided_area AS sa | ||
WHERE sa.code = 'territory_buffer-200' | ||
AND st_intersects(sa.geom, c.the_geom) | ||
) | ||
WITH DATA; | ||
|
||
CREATE UNIQUE INDEX ON atlas.vm_communes (insee) ; | ||
CREATE INDEX index_gist_vm_communes_the_geom ON atlas.vm_communes USING gist (the_geom) ; | ||
|
||
CREATE UNIQUE INDEX ON atlas.vm_communes (insee); | ||
CREATE INDEX index_gist_vm_communes_the_geom ON atlas.vm_communes USING gist (the_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
BEGIN; | ||
|
||
CREATE MATERIALIZED VIEW atlas.vm_subdivided_area AS | ||
SELECT | ||
random() AS gid, | ||
'territory' AS code, | ||
st_subdivide(t.the_geom, 255) AS geom | ||
FROM atlas.t_layer_territoire AS t | ||
|
||
UNION | ||
|
||
SELECT | ||
random() AS gid, | ||
'territory_buffer-200' AS code, | ||
st_subdivide(st_buffer(t.the_geom::geography, -200)::geometry, 255) AS geom | ||
FROM atlas.t_layer_territoire AS t | ||
WITH DATA; | ||
|
||
CREATE UNIQUE INDEX ON atlas.vm_subdivided_area USING btree (gid); | ||
CREATE INDEX ON atlas.vm_subdivided_area USING btree (code); | ||
CREATE INDEX ON atlas.vm_subdivided_area USING gist (geom); | ||
|
||
|
||
DROP FUNCTION IF EXISTS atlas.refresh_materialized_view_ref_geo; | ||
|
||
CREATE OR REPLACE FUNCTION atlas.refresh_materialized_view_ref_geo() | ||
RETURNS VOID AS $$ | ||
BEGIN | ||
|
||
REFRESH MATERIALIZED VIEW atlas.t_layer_territoire; | ||
REFRESH MATERIALIZED VIEW atlas.vm_subdivided_area; | ||
REFRESH MATERIALIZED VIEW atlas.l_communes; | ||
REFRESH MATERIALIZED VIEW atlas.vm_communes; | ||
|
||
END | ||
$$ LANGUAGE plpgsql; | ||
|
||
|
||
-- TODO : ajouter ce script au futur script d'update de GeoNature Atlas. | ||
-- TODO : trouver une solution pour pouvoir regénérer les VMs et table via les scripts présent dans data/atlas/. | ||
-- TODO : il faudrait aussi relancer la génération de la VM vm_communes à l'aide du script '7.atlas.vm_communes.sql | ||
-- TODO : il faudrait aussi relancer la génération de la table t_mailles_territoire à l'aide du script '12.atlas.t_mailles_teritoire.sql' | ||
|
||
|
||
COMMIT; |