Skip to content
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

feat: Add blurring observations #586

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions atlas/atlasRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ def ficheEspece(cd_nom):
altitudes = vmAltitudesRepository.getAltitudesChilds(connection, cd_ref)
months = vmMoisRepository.getMonthlyObservationsChilds(connection, cd_ref)
synonyme = vmTaxrefRepository.getSynonymy(connection, cd_ref)
communes = vmCommunesRepository.getCommunesObservationsChilds(connection, cd_ref)
if current_app.config["AFFICHAGE_MAILLE"]:
communes = vmCommunesRepository.getCommunesObservationsChildsMailles(connection, cd_ref)
else:
communes = vmCommunesRepository.getCommunesObservationsChilds(connection, cd_ref)
taxonomyHierarchy = vmTaxrefRepository.getAllTaxonomy(db_session, cd_ref)
firstPhoto = vmMedias.getFirstPhoto(connection, cd_ref, current_app.config["ATTR_MAIN_PHOTO"])
photoCarousel = vmMedias.getPhotoCarousel(
Expand Down Expand Up @@ -292,7 +295,6 @@ def ficheCommune(insee):
session = db.session
connection = db.engine.connect()

listTaxons = vmTaxonsRepository.getTaxonsCommunes(connection, insee)
commune = vmCommunesRepository.getCommuneFromInsee(connection, insee)
if current_app.config["AFFICHAGE_MAILLE"]:
observations = vmObservationsMaillesRepository.lastObservationsCommuneMaille(
Expand All @@ -304,7 +306,7 @@ def ficheCommune(insee):
)

surroundingAreas = []

listTaxons = vmTaxonsRepository.getTaxonsCommunes(connection, insee)
observers = vmObservationsRepository.getObserversCommunes(connection, insee)

session.close()
Expand Down
10 changes: 10 additions & 0 deletions atlas/configuration/settings.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ metropole=true
# Choisissez alors la taille de vos mailles à utiliser (en km) / Valeurs possibles 1, 5 ou 10
taillemaille=5

# Choisissez alors la taille de vos mailles à utiliser
# Valeurs possibles M1, M5, COM, 10, COM, DEP ou REG

sensibility0="M1" # sensibilité de niveau 0
sensibility1="M1" # sensibilité de niveau 1
sensibility2="COM" # sensibilité de niveau 2
sensibility3="M10" # sensibilité de niveau 3

# A noter que la sensibilité de niveau 4 sera ignoré afin de ne pas afficher les observations correspondant a ces espèces.

# Si 'metropole=false', rajoutez dans le dossier /data/ref un SHP des mailles de votre territoire et renseignez son chemin
chemin_custom_maille=/home/`whoami`/atlas/data/ref/custom_maille.shp

Expand Down
3 changes: 2 additions & 1 deletion atlas/modeles/entities/vmObservations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ class VmObservations(Base):
Column("id_observation", Integer, primary_key=True, unique=True),
Column("insee", String(5), index=True),
Column("dateobs", Date, index=True),
Column("type_code", Integer),
Column("observateurs", String(255)),
Column("altitude_retenue", Integer, index=True),
Column("cd_ref", Integer, index=True),
Column("the_geom_point", Geometry(geometry_type="POINT", srid=4326)),
Column("geojson_point", Text),
Column("diffusion_level"),
Column("sensitivity"),
schema="atlas",
autoload=True,
autoload_with=db.engine,
Expand Down
20 changes: 20 additions & 0 deletions atlas/modeles/repositories/vmCommunesRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,23 @@ def getCommunesObservationsChilds(connection, cd_ref):
municipality = {"insee": r.insee, "commune_maj": r.commune_maj}
municipalities.append(municipality)
return municipalities


def getCommunesObservationsChildsMailles(connection, cd_ref):
sql = """
SELECT DISTINCT (com.insee) AS insee, com.commune_maj
FROM atlas.vm_communes com
JOIN atlas.t_mailles_territoire m ON st_intersects(m.the_geom, com.the_geom)
JOIN atlas.vm_observations_mailles obs ON m.id_maille=obs.id_maille
WHERE obs.cd_ref in (
SELECT * from atlas.find_all_taxons_childs(:thiscdref)
)
OR obs.cd_ref = :thiscdref
ORDER BY com.commune_maj ASC
"""
req = connection.execute(text(sql), thiscdref=cd_ref)
listCommunes = list()
for r in req:
temp = {"insee": r.insee, "commune_maj": r.commune_maj}
listCommunes.append(temp)
return listCommunes
72 changes: 43 additions & 29 deletions atlas/modeles/repositories/vmObservationsMaillesRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
from atlas.modeles.utils import deleteAccent, findPath


def format_taxon_name(observation):
if observation.nom_vern:
inter = observation.nom_vern.split(",")
taxon_name_formated = inter[0] + " | <i>" + observation.lb_nom + "</i>"
else:
taxon_name_formated = "<i>" + observation.lb_nom + "</i>"
return taxon_name_formated


def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None):
"""
Retourne les mailles et le nombre d'observation par maille pour un taxon et ses enfants
Expand All @@ -23,6 +32,7 @@ def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None):
TMaillesTerritoire.geojson_maille,
func.max(VmObservationsMailles.annee).label("last_obs_year"),
func.sum(VmObservationsMailles.nbr).label("obs_nbr"),
VmObservationsMailles.type_code,
)
.join(
TMaillesTerritoire,
Expand All @@ -32,6 +42,7 @@ def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None):
.group_by(
VmObservationsMailles.id_maille,
TMaillesTerritoire.geojson_maille,
VmObservationsMailles.type_code,
)
)
if year_min and year_max:
Expand All @@ -44,6 +55,7 @@ def getObservationsMaillesChilds(session, cd_ref, year_min=None, year_max=None):
geometry=json.loads(o.geojson_maille),
properties={
"id_maille": o.id_maille,
"type_code": o.type_code,
"nb_observations": int(o.obs_nbr),
"last_observation": o.last_obs_year,
},
Expand All @@ -60,13 +72,13 @@ def lastObservationsMailles(connection, mylimit, idPhoto):
tax.lb_nom, tax.nom_vern, tax.group2_inpn,
o.dateobs, o.altitude_retenue, o.id_observation,
medias.url, medias.chemin, medias.id_media,
m.geojson_maille
m.geojson_4326 AS geom
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=ANY(obs.id_observations)
JOIN atlas.t_mailles_territoire m ON m.id_maille=obs.id_maille
JOIN atlas.vm_cor_area_synthese m ON m.id_synthese=o.id_observation AND m.is_blurred_geom IS TRUE
LEFT JOIN atlas.vm_medias medias
ON medias.cd_ref = obs.cd_ref AND medias.id_type = :thisID
ON medias.cd_ref = obs.cd_ref AND medias.id_type = 1
WHERE o.dateobs >= (CURRENT_TIMESTAMP - INTERVAL :thislimit)
ORDER BY o.dateobs DESC
"""
Expand All @@ -82,11 +94,12 @@ def lastObservationsMailles(connection, mylimit, idPhoto):
temp = {
"id_observation": o.id_observation,
"id_maille": o.id_maille,
"type_code": o.type_code,
"cd_ref": o.cd_ref,
"dateobs": o.dateobs,
"altitude_retenue": o.altitude_retenue,
"taxon": taxon,
"geojson_maille": json.loads(o.geojson_maille),
"geojson_maille": json.loads(o.geom),
"group2_inpn": deleteAccent(o.group2_inpn),
"pathImg": findPath(o),
"id_media": o.id_media,
Expand All @@ -97,38 +110,33 @@ def lastObservationsMailles(connection, mylimit, idPhoto):

def lastObservationsCommuneMaille(connection, obs_limit, insee_code):
sql = """
WITH last_obs AS (
SELECT
obs.id_observation, obs.cd_ref, obs.dateobs,
obs.id_observations, obs.cd_ref, obs.type_code, obs.nbr, c.insee,
COALESCE(t.nom_vern || ' | ', '') || t.lb_nom AS display_name,
obs.the_geom_point AS l_geom
FROM atlas.vm_observations AS obs
m.the_geom AS l_geom,
t.nom_vern, m.the_geom as l_geom,
m.geojson_maille, obs.id_maille
FROM atlas.vm_observations_mailles obs
JOIN atlas.t_mailles_territoire m ON m.id_maille = obs.id_maille
JOIN atlas.vm_communes AS c
ON ST_Intersects(obs.the_geom_point, c.the_geom)
ON ST_Intersects(m.the_geom, c.the_geom) AND NOT ST_Touches(m.the_geom, c.the_geom)
JOIN atlas.vm_taxons AS t
ON obs.cd_ref = t.cd_ref
WHERE c.insee = :inseeCode
ORDER BY obs.dateobs DESC
LIMIT :obsLimit
)
SELECT
l.id_observation, l.cd_ref, l.display_name, m.id_maille, m.geojson_maille
FROM atlas.t_mailles_territoire AS m
JOIN last_obs AS l
ON st_intersects(m.the_geom, l.l_geom)
GROUP BY l.id_observation, l.cd_ref, l.display_name, m.id_maille, m.geojson_maille
ORDER BY l.display_name
"""
results = connection.execute(text(sql), inseeCode=insee_code, obsLimit=obs_limit)
observations = list()
for r in results:
# taxon = (r.nom_vern + " | " + r.lb_nom) if r.nom_vern else r.lb_nom
infos = {
"cd_ref": r.cd_ref,
"insee": r.insee,
"taxon": r.display_name,
"geojson_maille": json.loads(r.geojson_maille),
"id_maille": r.id_maille,
"id_observation": r.id_observation,
"id_observation": r.id_observations,
"nb_observations": r.nbr,
"type_code": r.type_code,
}
observations.append(infos)
return observations
Expand All @@ -139,23 +147,29 @@ def getObservationsTaxonCommuneMaille(connection, insee, cd_ref):
sql = """
SELECT
o.cd_ref,
t.id_maille,
t.geojson_maille,
extract(YEAR FROM o.dateobs)::INT AS annee
FROM atlas.vm_observations AS o
JOIN atlas.vm_communes AS c
ON ST_INTERSECTS(o.the_geom_point, c.the_geom)
JOIN atlas.t_mailles_territoire AS t
ON ST_INTERSECTS(t.the_geom, o.the_geom_point)
o.id_maille,
o.type_code,
o.annee,
m.geojson_maille,
m.the_geom,
t.cd_ref,
t.nom_vern,
t.lb_nom
FROM atlas.vm_observations_mailles AS o
JOIN atlas.vm_taxons AS t ON t.cd_ref = o.cd_ref
JOIN atlas.t_mailles_territoire m ON m.id_maille = o.id_maille
JOIN atlas.vm_communes AS c ON c.insee = :thisInsee AND st_intersects(c.the_geom, m.the_geom) AND NOT st_touches(c.the_geom, m.the_geom)
WHERE o.cd_ref = :thiscdref
AND c.insee = :thisInsee
ORDER BY id_maille
"""
observations = connection.execute(text(sql), thisInsee=insee, thiscdref=cd_ref)
tabObs = list()
for o in observations:
temp = {
"id_maille": o.id_maille,
"cd_ref": o.cd_ref,
"taxon": format_taxon_name(o),
"type_code": o.type_code,
"nb_observations": 1,
"annee": o.annee,
"geojson_maille": json.loads(o.geojson_maille),
Expand Down
4 changes: 2 additions & 2 deletions atlas/modeles/repositories/vmObservationsRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def lastObservations(connection, mylimit, idPhoto):
temp.pop("the_geom_point", None)
temp["geojson_point"] = json.loads(o.geojson_point or "{}")
temp["dateobs"] = o.dateobs
temp["type_code"] = o.type_code
temp["group2_inpn"] = utils.deleteAccent(o.group2_inpn)
temp["pathImg"] = utils.findPath(o)
obsList.append(temp)
Expand All @@ -111,9 +112,8 @@ def lastObservationsCommune(connection, mylimit, insee):
'</i>'
) AS taxon
FROM atlas.vm_observations o
JOIN atlas.vm_communes c ON ST_Intersects(o.the_geom_point, c.the_geom)
JOIN atlas.vm_taxons tax ON o.cd_ref = tax.cd_ref
WHERE c.insee = :thisInsee
WHERE o.insee = :thisInsee
ORDER BY o.dateobs DESC
LIMIT 100"""
observations = connection.execute(text(sql), thisInsee=insee)
Expand Down
4 changes: 2 additions & 2 deletions atlas/static/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,11 @@ h3.title-spaced {
}*/

.tabEspece:hover {
background-color: #cccccc;
background-color: rgba(var(--main-color-rgb), 0.2);
}

.tabEspece.current {
background-color: #e6e6e6;
background-color: rgba(var(--main-color-rgb), 0.4);
font-weight: bold;
}

Expand Down
5 changes: 3 additions & 2 deletions atlas/static/css/listEspeces.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,13 @@ ul#statHierarchy {
}

tbody tr:hover {
background-color: rgba(var(--main-color-rgb), 0.2) !important;
/*background-color: #cccccc !important;*/
cursor: pointer;
}

tbody tr.current {
background-color: #e6e6e6 !important;
background-color: rgba(var(--main-color-rgb), 0.4) !important;
font-weight: bold;
}

Expand Down Expand Up @@ -203,4 +204,4 @@ tbody tr.current {
font-size: 0.8rem;
color: deeppink;
}
}
}
9 changes: 7 additions & 2 deletions atlas/static/mapAreas.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var areaLayer = L.geoJson(areaInfos.areaGeoJson, {
weight: 2,
color: areaBorderColor,
// dashArray: "3",
fillOpacity: 0.3
fillOpacity: 0.3,
invert: true
};
}
}).addTo(map);
Expand Down Expand Up @@ -93,6 +94,7 @@ function displayObsPreciseBaseUrl(areaCode, cd_ref) {
$("#loaderSpinner").hide();
// $("#loadingGif").hide();
map.removeLayer(currentLayer);
clearOverlays()
if (configuration.AFFICHAGE_MAILLE) {
displayMailleLayerLastObs(observations);
} else {
Expand Down Expand Up @@ -129,6 +131,7 @@ function displayObsTaxon(insee, cd_ref) {
}).done(function(observations) {
$("#loadingGif").hide();
map.removeLayer(currentLayer);
clearOverlays()
if (configuration.AFFICHAGE_MAILLE) {
displayMailleLayerLastObs(observations);
} else {
Expand All @@ -153,7 +156,9 @@ function displayObsTaxonMaille(areaCode, cd_ref) {
$("#loaderSpinner").hide();
// $("#loadingGif").hide();
map.removeLayer(currentLayer);
displayGridLayerArea(observations);
clearOverlays()
const geojsonMaille = generateGeoJsonMailleLastObs(observations);
displayMailleLayerFicheEspece(geojsonMaille);
});
}

Expand Down
Loading