-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix data: fix and improve vm_communes #402
Open
jpm-cbna
wants to merge
2
commits into
develop
Choose a base branch
from
feat/improve-vm-communes
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,19 +1,29 @@ | ||
DROP TABLE IF EXISTS atlas.t_mailles_territoire; | ||
|
||
-- MV for having only meshs of the territory | ||
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 | ||
st_transform(a.geom, 4326) AS the_geom, | ||
st_asgeojson(st_transform(a.geom, 4326)) AS geojson_maille, | ||
a.geom AS the_geom, | ||
a.geojson AS geojson_maille, | ||
a.id_area AS id_maille | ||
FROM ref_geo.l_areas AS a | ||
JOIN ref_geo.bib_areas_types AS t | ||
ON t.id_type = a.id_type | ||
JOIN atlas.t_layer_territoire AS l | ||
ON ST_intersects(a.geom, st_transform(l.the_geom, find_srid('ref_geo', 'l_areas', 'geom'))) | ||
WHERE a.enable = true | ||
AND t.type_code = :type_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 ON atlas.t_mailles_territoire | ||
USING btree (id_maille); | ||
CREATE INDEX ON atlas.t_mailles_territoire | ||
USING spgist (the_geom); | ||
CREATE UNIQUE INDEX ON atlas.t_mailles_territoire USING btree (id_maille); | ||
CREATE INDEX ON atlas.t_mailles_territoire USING spgist (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
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' | ||
Comment on lines
+39
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Point à traiter suite au merge avec la branche develop. |
||
|
||
|
||
COMMIT; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
atlas.t_mailles_territoire
est une table. Le rafraichissement dessus ne marche pas. J'ai donc supprimé cette ligne. Mais, il faudrait peut être transformer cette table en VM ?