From d6112431d290f02babc57d9b452b98a2e3e7a4c9 Mon Sep 17 00:00:00 2001 From: Joaquim Nallar Date: Mon, 30 Sep 2024 11:21:51 +0200 Subject: [PATCH] fix: display mailles --- atlas/modeles/entities/vmObservations.py | 3 +- .../vmObservationsMaillesRepository.py | 8 ++-- atlas/static/mapGenerator.js | 3 +- .../13.atlas.vm_observations_mailles.sql | 40 ++++++++++--------- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/atlas/modeles/entities/vmObservations.py b/atlas/modeles/entities/vmObservations.py index 141fd751..319f3aa5 100644 --- a/atlas/modeles/entities/vmObservations.py +++ b/atlas/modeles/entities/vmObservations.py @@ -1,6 +1,6 @@ # coding: utf-8 from geoalchemy2.types import Geometry -from sqlalchemy import Column, Date, Integer, MetaData, String, Table, Text +from sqlalchemy import Column, Date, Integer, MetaData, String, Table, Text, ARRAY from sqlalchemy.ext.declarative import declarative_base from atlas.env import db @@ -40,6 +40,7 @@ class VmObservationsMailles(Base): Column("annee", String(1000), primary_key=True, index=True), Column("id_maille", Integer, primary_key=True, index=True), Column("nbr", Integer), + Column("id_observations", ARRAY(Integer)), schema="atlas", autoload=True, autoload_with=db.engine, diff --git a/atlas/modeles/repositories/vmObservationsMaillesRepository.py b/atlas/modeles/repositories/vmObservationsMaillesRepository.py index f6edb9ba..c6385515 100644 --- a/atlas/modeles/repositories/vmObservationsMaillesRepository.py +++ b/atlas/modeles/repositories/vmObservationsMaillesRepository.py @@ -58,11 +58,13 @@ def lastObservationsMailles(connection, mylimit, idPhoto): sql = """ SELECT obs.*, tax.lb_nom, tax.nom_vern, tax.group2_inpn, - o.dateobs, o.altitude_retenue, - medias.url, medias.chemin, medias.id_media + o.dateobs, o.altitude_retenue, o.id_observation, + medias.url, medias.chemin, medias.id_media, + m.geojson_maille FROM atlas.vm_observations_mailles obs JOIN atlas.vm_taxons tax ON tax.cd_ref = obs.cd_ref - JOIN atlas.vm_observations o ON o.id_observation=obs.id_observation + JOIN atlas.vm_observations o ON o.id_observation=ANY(obs.id_observations) + JOIN atlas.t_mailles_territoire m ON m.id_maille=obs.id_maille LEFT JOIN atlas.vm_medias medias ON medias.cd_ref = obs.cd_ref AND medias.id_type = :thisID WHERE o.dateobs >= (CURRENT_TIMESTAMP - INTERVAL :thislimit) diff --git a/atlas/static/mapGenerator.js b/atlas/static/mapGenerator.js index 0628d170..54cc3086 100644 --- a/atlas/static/mapGenerator.js +++ b/atlas/static/mapGenerator.js @@ -334,7 +334,7 @@ function generateGeojsonGridArea(observations) { } function displayGridLayerArea(observations) { - myGeoJson = generateGeojsonGridArea(observations); + myGeoJson = generateGeojsonGridArea(observations); currentLayer = L.geoJson(myGeoJson, { onEachFeature: onEachFeatureMaille, style: styleMaille, @@ -585,6 +585,7 @@ function generateGeoJsonMailleLastObs(observations) { geometry: obs.geojson_maille, properties: { meshId: obs.id_maille, + list_id_observation: [obs.id_observation], taxons: [ { cdRef: obs.cd_ref, diff --git a/data/atlas/13.atlas.vm_observations_mailles.sql b/data/atlas/13.atlas.vm_observations_mailles.sql index 557bfa75..757c69dd 100644 --- a/data/atlas/13.atlas.vm_observations_mailles.sql +++ b/data/atlas/13.atlas.vm_observations_mailles.sql @@ -1,21 +1,25 @@ -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 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, + ARRAY_AGG(o.id_observation) AS id_observations + 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 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 (annee); -CREATE INDEX ON atlas.vm_observations_mailles - USING btree (id_maille, cd_ref); + CREATE INDEX ON atlas.vm_observations_mailles + USING gin (id_observations); + + CREATE INDEX ON atlas.vm_observations_mailles + USING btree (id_maille, cd_ref);