-
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.
feat: improve the display time of meshes on the species map
- Loading branch information
Showing
7 changed files
with
134 additions
and
44 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
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,22 @@ | ||
# coding: utf-8 | ||
from geoalchemy2.types import Geometry | ||
from sqlalchemy import Column, Integer, MetaData, Table, Text | ||
from sqlalchemy.ext.declarative import declarative_base | ||
|
||
from atlas.utils import engine | ||
|
||
metadata = MetaData() | ||
Base = declarative_base() | ||
|
||
|
||
class TMaillesTerritoire(Base): | ||
__table__ = Table( | ||
"t_mailles_territoire", | ||
metadata, | ||
Column("id_maille", Integer, primary_key=True, unique=True), | ||
Column("the_geom", Geometry()), | ||
Column("geojson_maille", Text), | ||
schema="atlas", | ||
autoload=True, | ||
autoload_with=engine, | ||
) |
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
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,19 @@ | ||
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 | ||
SELECT | ||
st_transform(a.geom, 4326) AS the_geom, | ||
st_asgeojson(st_transform(a.geom, 4326)) 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 ; | ||
|
||
CREATE UNIQUE INDEX t_mailles_territoire_id_maille_idx ON atlas.t_mailles_territoire USING btree (id_maille); | ||
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,13 +1,21 @@ | ||
CREATE MATERIALIZED VIEW atlas.vm_observations_mailles | ||
AS SELECT obs.cd_ref, | ||
obs.id_observation, | ||
m.id_maille, | ||
m.geojson_maille, | ||
date_part('year', dateobs) as annee | ||
FROM atlas.vm_observations obs | ||
JOIN atlas.t_mailles_territoire m ON st_intersects(obs.the_geom_point, m.the_geom) | ||
CREATE MATERIALIZED VIEW atlas.vm_observations_mailles AS | ||
SELECT | ||
o.cd_ref, | ||
date_part('year', o.dateobs) AS annee, | ||
m.id_maille, | ||
COUNT(o.id_observation) AS nbr | ||
FROM atlas.vm_observations AS o | ||
JOIN atlas.t_mailles_territoire AS m | ||
ON (o.the_geom_point && m.the_geom) | ||
GROUP BY o.cd_ref, date_part('year', o.dateobs), m.id_maille | ||
ORDER BY o.cd_ref, annee | ||
WITH DATA; | ||
|
||
create unique index on atlas.vm_observations_mailles (id_observation); | ||
create index on atlas.vm_observations_mailles (id_maille); | ||
create index on atlas.vm_observations_mailles (cd_ref); | ||
CREATE UNIQUE INDEX ON atlas.vm_observations_mailles | ||
USING btree (cd_ref, annee, id_maille); | ||
|
||
CREATE INDEX ON atlas.vm_observations_mailles | ||
USING btree (annee); | ||
|
||
CREATE INDEX ON atlas.vm_observations_mailles | ||
USING btree (id_maille, cd_ref); |
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 @@ | ||
DROP MATERIALIZED VIEW IF EXISTS atlas.vm_observations_mailles; | ||
DROP TABLE IF EXISTS atlas.t_mailles_territoire; | ||
|
||
|
||
CREATE TABLE atlas.t_mailles_territoire AS | ||
SELECT | ||
st_transform(a.geom, 4326) AS the_geom, | ||
st_asgeojson(st_transform(a.geom, 4326)) 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 ; | ||
|
||
CREATE UNIQUE INDEX ON atlas.t_mailles_territoire | ||
USING btree (id_maille); | ||
|
||
CREATE INDEX ON atlas.t_mailles_territoire | ||
USING spgist (the_geom); | ||
|
||
|
||
CREATE MATERIALIZED VIEW atlas.vm_observations_mailles AS | ||
SELECT | ||
o.cd_ref, | ||
date_part('year', o.dateobs) AS annee, | ||
m.id_maille, | ||
COUNT(o.id_observation) AS nbr | ||
FROM atlas.vm_observations AS o | ||
JOIN atlas.t_mailles_territoire AS m | ||
ON (o.the_geom_point && m.the_geom) | ||
GROUP BY o.cd_ref, date_part('year', o.dateobs), m.id_maille | ||
ORDER BY o.cd_ref, annee | ||
WITH DATA; | ||
|
||
CREATE UNIQUE INDEX ON atlas.vm_observations_mailles | ||
USING btree (cd_ref, annee, id_maille); | ||
|
||
CREATE INDEX ON atlas.vm_observations_mailles | ||
USING btree (annee); | ||
|
||
CREATE INDEX ON atlas.vm_observations_mailles | ||
USING btree (id_maille, cd_ref); |