Skip to content

Commit

Permalink
fix(data): improve the creation of t_mailles_territoire
Browse files Browse the repository at this point in the history
  • Loading branch information
jpm-cbna committed Dec 7, 2023
1 parent 87879e5 commit 43a51f2
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions data/atlas/12.atlas.t_mailles_territoire.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@ 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(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 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
AND EXISTS (
SELECT 'X'
FROM atlas.vm_subdivided_area AS sa
WHERE sa.code = 'territory'
AND st_intersects(c.geom, st_transform(sa.geom, find_srid('ref_geo', 'l_areas', 'geom')))
);
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);

0 comments on commit 43a51f2

Please sign in to comment.