Skip to content

Commit

Permalink
fix: detail observation when display mailles (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
juggler31 authored Oct 11, 2024
1 parent 5cfa411 commit 647c441
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
3 changes: 2 additions & 1 deletion atlas/modeles/entities/vmObservations.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions atlas/modeles/repositories/vmObservationsMaillesRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion atlas/static/mapGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ function generateGeojsonGridArea(observations) {
}

function displayGridLayerArea(observations) {
myGeoJson = generateGeojsonGridArea(observations);
myGeoJson = generateGeojsonGridArea(observations);
currentLayer = L.geoJson(myGeoJson, {
onEachFeature: onEachFeatureMaille,
style: styleMaille,
Expand Down Expand Up @@ -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,
Expand Down
40 changes: 22 additions & 18 deletions data/atlas/13.atlas.vm_observations_mailles.sql
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 647c441

Please sign in to comment.