diff --git a/atlas/atlasAPI.py b/atlas/atlasAPI.py index b239c3381..fb8e1ce66 100644 --- a/atlas/atlasAPI.py +++ b/atlas/atlasAPI.py @@ -8,7 +8,7 @@ vmObservationsRepository, vmObservationsMaillesRepository, vmMedias, - vmCommunesRepository, + tZonesRepository, ) from atlas.env import cache, db @@ -25,12 +25,12 @@ def searchTaxonAPI(): return jsonify(results) -@api.route("/searchCommune", methods=["GET"]) -def searchCommuneAPI(): +@api.route("/searchZone", methods=["GET"]) +def searchZoneAPI(): session = db.session search = request.args.get("search", "") limit = request.args.get("limit", 50) - results = vmCommunesRepository.searchMunicipalities(session, search, limit) + results = tZonesRepository.searchMunicipalities(session, search, limit) session.close() return jsonify(results) @@ -110,21 +110,21 @@ def getObservationsGenericApi(cd_ref: int): if not current_app.config["AFFICHAGE_MAILLE"]: - @api.route("/observations//", methods=["GET"]) - def getObservationsCommuneTaxonAPI(insee, cd_ref): + @api.route("/observations//", methods=["GET"]) + def getObservationsZoneTaxonAPI(id_zone, cd_ref): connection = db.engine.connect() - observations = vmObservationsRepository.getObservationTaxonCommune( - connection, insee, cd_ref + observations = vmObservationsRepository.getObservationTaxonZone( + connection, id_zone, cd_ref ) connection.close() return jsonify(observations) -@api.route("/observationsMaille//", methods=["GET"]) -def getObservationsCommuneTaxonMailleAPI(insee, cd_ref): +@api.route("/observationsMaille//", methods=["GET"]) +def getObservationsZoneTaxonMailleAPI(id_zone, cd_ref): connection = db.engine.connect() - observations = vmObservationsMaillesRepository.getObservationsTaxonCommuneMaille( - connection, insee, cd_ref + observations = vmObservationsMaillesRepository.getObservationsTaxonZoneMaille( + connection, id_zone, cd_ref ) connection.close() return jsonify(observations) diff --git a/atlas/atlasRoutes.py b/atlas/atlasRoutes.py index 21b95163d..cfb247321 100644 --- a/atlas/atlasRoutes.py +++ b/atlas/atlasRoutes.py @@ -18,7 +18,7 @@ from atlas.env import db from atlas import utils -from atlas.modeles.entities import vmTaxons, vmCommunes +from atlas.modeles.entities import vmTaxons, t_zoning from atlas.modeles.repositories import ( vmOrganismsRepository, vmTaxonsRepository, @@ -26,7 +26,7 @@ vmAltitudesRepository, vmMoisRepository, vmTaxrefRepository, - vmCommunesRepository, + tZonesRepository, vmObservationsMaillesRepository, vmMedias, vmCorTaxonAttribut, @@ -125,9 +125,9 @@ def ficheOrganism(id_organism): @main.route( - "/commune/" + current_app.config["REMOTE_MEDIAS_PATH"] + "", methods=["GET", "POST"] + "/zone/" + current_app.config["REMOTE_MEDIAS_PATH"] + "", methods=["GET", "POST"] ) -def communeMedias(image): +def zoneMedias(image): return redirect( current_app.config["REMOTE_MEDIAS_URL"] + current_app.config["REMOTE_MEDIAS_PATH"] + image ) @@ -227,13 +227,12 @@ def ficheEspece(cd_nom): # Redirect to cd_ref if cd_nom is a synonym. Redirection is better for SEO. if cd_ref != cd_nom: return redirect(url_for(request.endpoint, cd_nom=cd_ref)) - # Get data to render template taxon = vmTaxrefRepository.searchEspece(connection, cd_ref) altitudes = vmAltitudesRepository.getAltitudesChilds(connection, cd_ref) months = vmMoisRepository.getMonthlyObservationsChilds(connection, cd_ref) synonyme = vmTaxrefRepository.getSynonymy(connection, cd_ref) - communes = vmCommunesRepository.getCommunesObservationsChilds(connection, cd_ref) + zone = tZonesRepository.getZonesObservationsChilds(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( @@ -275,7 +274,7 @@ def ficheEspece(cd_nom): altitudes=altitudes, months=months, synonyme=synonyme, - communes=communes, + zone=zone, taxonomyHierarchy=taxonomyHierarchy, firstPhoto=firstPhoto, photoCarousel=photoCarousel, @@ -287,39 +286,39 @@ def ficheEspece(cd_nom): ) -@main.route("/commune/", methods=["GET", "POST"]) -def ficheCommune(insee): +@main.route("/zone/", methods=["GET", "POST"]) +def ficheZone(id_zone): session = db.session connection = db.engine.connect() - listTaxons = vmTaxonsRepository.getTaxonsCommunes(connection, insee) - commune = vmCommunesRepository.getCommuneFromInsee(connection, insee) + listTaxons = vmTaxonsRepository.getTaxonsZones(connection, id_zone) + + zone = tZonesRepository.getZoneFromIdZone(connection, id_zone) if current_app.config["AFFICHAGE_MAILLE"]: - observations = vmObservationsMaillesRepository.lastObservationsCommuneMaille( - connection, current_app.config["NB_LAST_OBS"], str(insee) + observations = vmObservationsMaillesRepository.lastObservationsZoneMaille( + connection, current_app.config["NB_LAST_OBS"], str(id_zone) ) else: - observations = vmObservationsRepository.lastObservationsCommune( - connection, current_app.config["NB_LAST_OBS"], insee + observations = vmObservationsRepository.lastObservationsZone( + connection, current_app.config["NB_LAST_OBS"], id_zone ) surroundingAreas = [] - observers = vmObservationsRepository.getObserversCommunes(connection, insee) + observers = vmObservationsRepository.getObserversZone(connection, id_zone) session.close() connection.close() return render_template( "templates/areaSheet/_main.html", - sheetType="commune", surroundingAreas=surroundingAreas, listTaxons=listTaxons, - areaInfos=commune, + areaInfos=zone, observations=observations, observers=observers, DISPLAY_EYE_ON_LIST=True, - insee=insee, + id_zone=id_zone, ) @@ -419,11 +418,9 @@ def sitemap(): modified_time = ten_days_ago pages.append([url, modified_time]) - municipalities = ( - session.query(vmCommunes.VmCommunes).order_by(vmCommunes.VmCommunes.insee).all() - ) + municipalities = session.query(vmZones.t_zoning).order_by(vmZones.t_zoning.id_code).all() for municipalitie in municipalities: - url = url_root + url_for("main.ficheCommune", insee=municipalitie.insee) + url = url_root + url_for("main.ficheZone", id_code=municipalitie.id_code) modified_time = ten_days_ago pages.append([url, modified_time]) diff --git a/atlas/configuration/config.py.example b/atlas/configuration/config.py.example index bd7da925e..25429c635 100644 --- a/atlas/configuration/config.py.example +++ b/atlas/configuration/config.py.example @@ -142,7 +142,7 @@ NB_DAY_LAST_OBS = '7' # Texte à afficher pour décrire la cartographie des 'dernières observations' TEXT_LAST_OBS = 'Les observations des agents ces 7 derniers jours |' -# Carte de la fiche commune : nombre des 'x' dernières observations affichées +# Carte de la fiche "zone" : nombre des 'x' dernières observations affichées NB_LAST_OBS=100 ########################### @@ -237,7 +237,7 @@ ATTR_VIMEO = 9 SPLIT_NOM_VERN = True ############################################ -#### FICHE COMMUNE ET RANG TAXONOMIQUE ##### +#### FICHE "ZONE" ET RANG TAXONOMIQUE ##### ############################################ # Permet d'afficher ou non les colonnes Protection et/ou Patrimonialité/Enjeux dans les listes de taxons diff --git a/atlas/configuration/settings.ini.sample b/atlas/configuration/settings.ini.sample index f8eddf134..8333d4d93 100644 --- a/atlas/configuration/settings.ini.sample +++ b/atlas/configuration/settings.ini.sample @@ -82,18 +82,19 @@ type_territoire="'PEC'" ########### Si ref_geo = False ############# -#### COMMUNES #### +#### ZONE #### -# Creer la table des communes à partir d'un shapefile ? -# Si false, modifiez la creation de 'atlas.vm_communes' dans data/atlas/atlas.vm_communes.sql +# Creer la table des zones à partir d'un shapefile ? +# Si false, modifiez la creation de 'atlas.zoning' dans data/atlas/7.atlas.zoning.sql # PARAMETRE OBSOLETE OBLIGATOIRE SI PAS DE REF_GEO -# import_commune_shp=true +# +import_commune_shp=true -# Chemin et nom des colonnes du SHP des communes du territoire. Laisser tel quel (en modifiant uniquement MYUSERLINUX) -# pour utiliser les communes du PnEcrins par défaut -communes_shp=/home/`whoami`/atlas/data/ref/communes.shp +# Chemin et nom des colonnes du SHP des zones du territoire. Laisser tel quel (en modifiant uniquement MYUSERLINUX) +# pour utiliser les zones du PnEcrins par défaut +zones_shp=/home/`whoami`/atlas/data/ref/zones.shp colonne_insee=insee -colonne_nom_commune=nom_com +colonne_nom_zone=nom_com #### TERRITOIRE #### diff --git a/atlas/messages.pot b/atlas/messages.pot index c36bb800d..791e62a94 100644 --- a/atlas/messages.pot +++ b/atlas/messages.pot @@ -112,7 +112,7 @@ msgstr "" #: static/custom/templates/navbar.html:47 #: static/custom/templates/navbar.html.sample:47 #: templates/home/globalStats.html:55 -msgid "search.city" +msgid "search.zone" msgstr "" #: static/custom/templates/presentation.html:4 diff --git a/atlas/modeles/entities/tCommunes.py b/atlas/modeles/entities/tCommunes.py index db2acb11a..8cbd371fb 100644 --- a/atlas/modeles/entities/tCommunes.py +++ b/atlas/modeles/entities/tCommunes.py @@ -12,6 +12,6 @@ class LCommune(Base): __table_args__ = {"schema": "layers"} insee = Column(String(5), primary_key=True) - commune_maj = Column(String(50)) + area_name = Column(String(50)) commune_min = Column(String(50)) the_geom = Column(Geometry) diff --git a/atlas/modeles/entities/t_zoning.py b/atlas/modeles/entities/t_zoning.py new file mode 100644 index 000000000..86b852655 --- /dev/null +++ b/atlas/modeles/entities/t_zoning.py @@ -0,0 +1,26 @@ +# coding: utf-8 +from geoalchemy2.types import Geometry +from sqlalchemy import Column, MetaData, String, Table, Sequence, Integer, Text +from sqlalchemy.ext.declarative import declarative_base + +from atlas.env import db + +metadata = MetaData() +Base = declarative_base() + + +class t_zoning(Base): + __table__ = Table( + "zoning", + metadata, + Column("id", Sequence("zoning_id_seq"), primary_key=True, unique=True), + Column("id_zone", Integer()), + Column("area_name", String(50)), + Column("the_geom", Geometry("MULTIPOLYGON"), index=True), + Column("zone_geojson", Text), + Column("id_zoning_type", Integer()), + Column("id_parent", Integer()), + schema="atlas", + autoload=True, + autoload_with=db.engine, + ) diff --git a/atlas/modeles/entities/vmCommunes.py b/atlas/modeles/entities/vmCommunes.py deleted file mode 100644 index 46684589c..000000000 --- a/atlas/modeles/entities/vmCommunes.py +++ /dev/null @@ -1,23 +0,0 @@ -# coding: utf-8 -from geoalchemy2.types import Geometry -from sqlalchemy import Column, MetaData, String, Table -from sqlalchemy.ext.declarative import declarative_base - -from atlas.env import db - -metadata = MetaData() -Base = declarative_base() - - -class VmCommunes(Base): - __table__ = Table( - "vm_communes", - metadata, - Column("insee", String(5), primary_key=True, unique=True), - Column("commune_maj", String(50)), - # Column('commune_min', String(50)), - Column("the_geom", Geometry("MULTIPOLYGON"), index=True), - schema="atlas", - autoload=True, - autoload_with=db.engine, - ) diff --git a/atlas/modeles/repositories/tCommunesRepository.py b/atlas/modeles/repositories/tCommunesRepository.py index bbdd8e6ce..b72eb390e 100644 --- a/atlas/modeles/repositories/tCommunesRepository.py +++ b/atlas/modeles/repositories/tCommunesRepository.py @@ -4,15 +4,15 @@ from sqlalchemy.sql import text -def getCommunesObservationsChilds(connection, cd_ref): +def getZonesObservationsChilds(connection, cd_ref): sql = """ - SELECT DISTINCT(com.insee) AS insee, com.commune_maj + SELECT DISTINCT(com.insee) AS insee, com.area_name FROM layers.l_communes com JOIN atlas.vm_observations obs ON obs.insee = com.insee WHERE obs.cd_ref IN ( SELECT * FROM atlas.find_all_taxons_childs(:thiscdref) ) OR obs.cd_ref = :thiscdref - GROUP BY com.commune_maj, com.insee + GROUP BY com.area_name, com.insee """.encode( "UTF-8" ) diff --git a/atlas/modeles/repositories/tZonesRepository.py b/atlas/modeles/repositories/tZonesRepository.py new file mode 100644 index 000000000..a8f5de6c6 --- /dev/null +++ b/atlas/modeles/repositories/tZonesRepository.py @@ -0,0 +1,83 @@ +# -*- coding:utf-8 -*- + +import ast + +from sqlalchemy import distinct +from sqlalchemy.sql import text +from sqlalchemy.sql.expression import func + +from atlas.modeles.entities.t_zoning import t_zoning + + +def getAllZones(session): + req = session.query(distinct(t_zoning.area_name), t_zoning.id_zone).all() + zoneList = list() + for r in req: + temp = {"label": r[0], "value": r[1]} + zoneList.append(temp) + return zoneList + + +def searchMunicipalities(session, search, limit=50): + like_search = "%" + search.replace(" ", "%") + "%" + + query = ( + session.query( + distinct(t_zoning.area_name), + t_zoning.id_zone, + func.length(t_zoning.area_name), + ) + .filter(func.unaccent(t_zoning.area_name).ilike(func.unaccent(like_search))) + .order_by(t_zoning.area_name) + .limit(limit) + ) + results = query.all() + + return [{"label": r[0], "value": r[1]} for r in results] + + +def getZoneFromIdZone(connection, id_zone): + sql = """ + SELECT c.area_name, + c.id_zone, + c.zone_geojson, + bib.type_name + FROM atlas.zoning c + JOIN ref_geo.bib_areas_types bib ON bib.id_type = c.id_zoning_type + WHERE c.id_zone = :thisIdZone + """ + req = connection.execute(text(sql), thisIdZone=id_zone) + zone_obj = dict() + for r in req: + zone_obj = { + "areaName": r.area_name, + "areaCode": str(r.id_zone), + "areaGeoJson": ast.literal_eval(r.zone_geojson), + "typeName": r.type_name, + } + return zone_obj + + +def getZonesObservationsChilds(connection, cd_ref): + sql = "SELECT * FROM atlas.find_all_taxons_childs(:thiscdref) AS taxon_childs(cd_nom)" + results = connection.execute(text(sql), thiscdref=cd_ref) + taxons = [cd_ref] + for r in results: + taxons.append(r.cd_nom) + + sql = """ + SELECT DISTINCT + zone.area_name, + zone.id_zone + FROM atlas.vm_observations AS obs + JOIN atlas.zoning AS zone + ON st_intersects(obs.the_geom_point, zone.the_geom_4326) + WHERE obs.cd_ref = ANY(:taxonsList) + ORDER BY zone.area_name ASC + """ + results = connection.execute(text(sql), taxonsList=taxons) + municipalities = list() + for r in results: + municipality = {"id_zone": r.id_zone, "area_name": r.area_name} + municipalities.append(municipality) + return municipalities diff --git a/atlas/modeles/repositories/vmCommunesRepository.py b/atlas/modeles/repositories/vmCommunesRepository.py deleted file mode 100644 index 4c9252489..000000000 --- a/atlas/modeles/repositories/vmCommunesRepository.py +++ /dev/null @@ -1,80 +0,0 @@ -# -*- coding:utf-8 -*- - -import ast - -from sqlalchemy import distinct -from sqlalchemy.sql import text -from sqlalchemy.sql.expression import func - -from atlas.modeles.entities.vmCommunes import VmCommunes - - -def getAllCommunes(session): - req = session.query(distinct(VmCommunes.commune_maj), VmCommunes.insee).all() - communeList = list() - for r in req: - temp = {"label": r[0], "value": r[1]} - communeList.append(temp) - return communeList - - -def searchMunicipalities(session, search, limit=50): - like_search = "%" + search.replace(" ", "%") + "%" - - query = ( - session.query( - distinct(VmCommunes.commune_maj), - VmCommunes.insee, - func.length(VmCommunes.commune_maj), - ) - .filter(func.unaccent(VmCommunes.commune_maj).ilike(func.unaccent(like_search))) - .order_by(VmCommunes.commune_maj) - .limit(limit) - ) - results = query.all() - - return [{"label": r[0], "value": r[1]} for r in results] - - -def getCommuneFromInsee(connection, insee): - sql = """ - SELECT c.commune_maj, - c.insee, - c.commune_geojson - FROM atlas.vm_communes c - WHERE c.insee = :thisInsee - """ - req = connection.execute(text(sql), thisInsee=insee) - communeObj = dict() - for r in req: - communeObj = { - "areaName": r.commune_maj, - "areaCode": str(r.insee), - "areaGeoJson": ast.literal_eval(r.commune_geojson), - } - return communeObj - - -def getCommunesObservationsChilds(connection, cd_ref): - sql = "SELECT * FROM atlas.find_all_taxons_childs(:thiscdref) AS taxon_childs(cd_nom)" - results = connection.execute(text(sql), thiscdref=cd_ref) - taxons = [cd_ref] - for r in results: - taxons.append(r.cd_nom) - - sql = """ - SELECT DISTINCT - com.commune_maj, - com.insee - FROM atlas.vm_observations AS obs - JOIN atlas.vm_communes AS com - ON obs.insee = com.insee - WHERE obs.cd_ref = ANY(:taxonsList) - ORDER BY com.commune_maj ASC - """ - results = connection.execute(text(sql), taxonsList=taxons) - municipalities = list() - for r in results: - municipality = {"insee": r.insee, "commune_maj": r.commune_maj} - municipalities.append(municipality) - return municipalities diff --git a/atlas/modeles/repositories/vmObservationsMaillesRepository.py b/atlas/modeles/repositories/vmObservationsMaillesRepository.py index 3628ed93e..0460dda43 100644 --- a/atlas/modeles/repositories/vmObservationsMaillesRepository.py +++ b/atlas/modeles/repositories/vmObservationsMaillesRepository.py @@ -95,7 +95,7 @@ def lastObservationsMailles(connection, mylimit, idPhoto): return obsList -def lastObservationsCommuneMaille(connection, obs_limit, insee_code): +def lastObservationsZoneMaille(connection, obs_limit, id_zone): sql = """ WITH last_obs AS ( SELECT @@ -103,11 +103,11 @@ def lastObservationsCommuneMaille(connection, obs_limit, insee_code): COALESCE(t.nom_vern || ' | ', '') || t.lb_nom AS display_name, obs.the_geom_point AS l_geom FROM atlas.vm_observations AS obs - JOIN atlas.vm_communes AS c - ON ST_Intersects(obs.the_geom_point, c.the_geom) + JOIN atlas.zoning AS zone + ON ST_Intersects(obs.the_geom_point, zone.the_geom_4326) JOIN atlas.vm_taxons AS t ON obs.cd_ref = t.cd_ref - WHERE c.insee = :inseeCode + WHERE zone.id_zone = :idZoneCode ORDER BY obs.dateobs DESC LIMIT :obsLimit ) @@ -119,7 +119,7 @@ def lastObservationsCommuneMaille(connection, obs_limit, insee_code): 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) + results = connection.execute(text(sql), idZoneCode=id_zone, obsLimit=obs_limit) observations = list() for r in results: # taxon = (r.nom_vern + " | " + r.lb_nom) if r.nom_vern else r.lb_nom @@ -135,7 +135,7 @@ def lastObservationsCommuneMaille(connection, obs_limit, insee_code): # Use for API -def getObservationsTaxonCommuneMaille(connection, insee, cd_ref): +def getObservationsTaxonZoneMaille(connection, id_zone, cd_ref): sql = """ SELECT o.cd_ref, @@ -143,15 +143,15 @@ def getObservationsTaxonCommuneMaille(connection, insee, cd_ref): 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.zoning AS c + ON ST_INTERSECTS(o.the_geom_point, c.the_geom_4326) JOIN atlas.t_mailles_territoire AS t ON ST_INTERSECTS(t.the_geom, o.the_geom_point) WHERE o.cd_ref = :thiscdref - AND c.insee = :thisInsee + AND c.id_zone = :thisIdZone ORDER BY id_maille """ - observations = connection.execute(text(sql), thisInsee=insee, thiscdref=cd_ref) + observations = connection.execute(text(sql), thisIdZone=id_zone, thiscdref=cd_ref) tabObs = list() for o in observations: temp = { diff --git a/atlas/modeles/repositories/vmObservationsRepository.py b/atlas/modeles/repositories/vmObservationsRepository.py index cf17c55ce..c488cfdb9 100644 --- a/atlas/modeles/repositories/vmObservationsRepository.py +++ b/atlas/modeles/repositories/vmObservationsRepository.py @@ -102,7 +102,7 @@ def lastObservations(connection, mylimit, idPhoto): return obsList -def lastObservationsCommune(connection, mylimit, insee): +def lastObservationsZone(connection, mylimit, id_code): sql = """SELECT o.*, CONCAT( split_part(tax.nom_vern, ',', 1) || ' | ', @@ -111,12 +111,12 @@ def lastObservationsCommune(connection, mylimit, insee): '' ) AS taxon FROM atlas.vm_observations o - JOIN atlas.vm_communes c ON ST_Intersects(o.the_geom_point, c.the_geom) + JOIN atlas.zoning c ON ST_Intersects(o.the_geom_point, c.the_geom_4326) JOIN atlas.vm_taxons tax ON o.cd_ref = tax.cd_ref - WHERE c.insee = :thisInsee + WHERE c.id_code = :thisIdZone ORDER BY o.dateobs DESC LIMIT 100""" - observations = connection.execute(text(sql), thisInsee=insee) + observations = connection.execute(text(sql), thisIdZone=id_code) obsList = list() for o in observations: temp = dict(o) @@ -127,7 +127,7 @@ def lastObservationsCommune(connection, mylimit, insee): return obsList -def getObservationTaxonCommune(connection, insee, cd_ref): +def getObservationTaxonZone(connection, id_zone, cd_ref): sql = """ SELECT o.*, COALESCE(split_part(tax.nom_vern, ',', 1) || ' | ', '') @@ -135,7 +135,7 @@ def getObservationTaxonCommune(connection, insee, cd_ref): o.observateurs FROM ( SELECT * FROM atlas.vm_observations o - WHERE o.insee = :thisInsee AND o.cd_ref = :thiscdref + WHERE o.id_zone = :thisIdZone AND o.cd_ref = :thiscdref ) o JOIN ( SELECT nom_vern, lb_nom, cd_ref @@ -144,7 +144,7 @@ def getObservationTaxonCommune(connection, insee, cd_ref): ) tax ON tax.cd_ref = tax.cd_ref """ - observations = connection.execute(text(sql), thiscdref=cd_ref, thisInsee=insee) + observations = connection.execute(text(sql), thiscdref=cd_ref, thisIdZone=id_zone) obsList = list() for o in observations: temp = dict(o) @@ -207,13 +207,15 @@ def getGroupeObservers(connection, groupe): return observersParser(req) -def getObserversCommunes(connection, insee): +def getObserversZone(connection, id_zone): sql = """ SELECT DISTINCT observateurs - FROM atlas.vm_observations - WHERE insee = :thisInsee + FROM atlas.vm_observations AS obs + JOIN atlas.zoning AS zone + ON ST_Intersects(obs.the_geom_point, zone.the_geom_4326) + WHERE zone.id_zone = :thisIdZone """ - req = connection.execute(text(sql), thisInsee=insee) + req = connection.execute(text(sql), thisIdZone=id_zone) return observersParser(req) @@ -229,7 +231,7 @@ def statIndex(connection): sql = """ SELECT COUNT(*) AS count - FROM atlas.vm_communes + FROM atlas.zoning """ req = connection.execute(text(sql)) for r in req: diff --git a/atlas/modeles/repositories/vmTaxonsRepository.py b/atlas/modeles/repositories/vmTaxonsRepository.py index 664d88f19..912145161 100644 --- a/atlas/modeles/repositories/vmTaxonsRepository.py +++ b/atlas/modeles/repositories/vmTaxonsRepository.py @@ -7,7 +7,7 @@ # With distinct the result in a array not an object, 0: lb_nom, 1: nom_vern -def getTaxonsCommunes(connection, insee): +def getTaxonsZones(connection, id_zone): sql = """ SELECT DISTINCT o.cd_ref, max(date_part('year'::text, o.dateobs)) as last_obs, @@ -16,16 +16,17 @@ def getTaxonsCommunes(connection, insee): m.url, m.chemin, m.id_media FROM atlas.vm_observations o JOIN atlas.vm_taxons t ON t.cd_ref=o.cd_ref + JOIN atlas.zoning zone ON st_intersects(o.the_geom_point, zone.the_geom_4326) LEFT JOIN atlas.vm_medias m ON m.cd_ref=o.cd_ref AND m.id_type={} - WHERE o.insee = :thisInsee + WHERE zone.id_zone = :thisIdZone GROUP BY o.cd_ref, t.nom_vern, t.nom_complet_html, t.group2_inpn, t.patrimonial, t.protection_stricte, m.url, m.chemin, m.id_media ORDER BY nb_obs DESC """.format( current_app.config["ATTR_MAIN_PHOTO"] ) - req = connection.execute(text(sql), thisInsee=insee) - taxonCommunesList = list() + req = connection.execute(text(sql), thisIdZone=id_zone) + taxonZonesList = list() nbObsTotal = 0 for r in req: temp = { @@ -40,9 +41,9 @@ def getTaxonsCommunes(connection, insee): "path": utils.findPath(r), "id_media": r.id_media, } - taxonCommunesList.append(temp) + taxonZonesList.append(temp) nbObsTotal = nbObsTotal + r.nb_obs - return {"taxons": taxonCommunesList, "nbObsTotal": nbObsTotal} + return {"taxons": taxonZonesList, "nbObsTotal": nbObsTotal} def getTaxonsChildsList(connection, cd_ref): diff --git a/atlas/static/css/index.css b/atlas/static/css/index.css index c16a570e1..a93c6e547 100644 --- a/atlas/static/css/index.css +++ b/atlas/static/css/index.css @@ -145,7 +145,7 @@ h3.title-spaced { } #searchTaxonsStat, -#searchCommunesStat { +#searchZonesStat { background-position: right center; background-repeat: no-repeat; background-size: 25px 25px; diff --git a/atlas/static/custom/maps-custom.js.sample b/atlas/static/custom/maps-custom.js.sample index 64e89d5e2..153df10ea 100644 --- a/atlas/static/custom/maps-custom.js.sample +++ b/atlas/static/custom/maps-custom.js.sample @@ -1,6 +1,6 @@ // Fonction style d'affichage des points dans la fiche espèce // Voir documentation leaflet pour customiser davantage l'affichage des points: http://leafletjs.com/reference-1.3.0.html#circlemarker-option -var pointDisplayOptionsFicheEspece = (pointDisplayOptionsFicheCommuneHome = function( +var pointDisplayOptionsFicheEspece = (pointDisplayOptionsFicheZoneHome = function( feature ) { return { @@ -9,7 +9,7 @@ var pointDisplayOptionsFicheEspece = (pointDisplayOptionsFicheCommuneHome = func }); // Légende des points dans la fiche espèce -var divLegendeFicheEspece = (divLegendeFicheCommuneHome = +var divLegendeFicheEspece = (divLegendeFicheZoneHome = '\

\ Dégradées\ diff --git a/atlas/static/custom/templates/navbar.html.sample b/atlas/static/custom/templates/navbar.html.sample index 52f81b9c6..cf2d8945b 100644 --- a/atlas/static/custom/templates/navbar.html.sample +++ b/atlas/static/custom/templates/navbar.html.sample @@ -38,15 +38,15 @@ {% if configuration.MULTILINGUAL %} @@ -79,4 +79,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/atlas/static/custom/templates/presentation.html.example b/atlas/static/custom/templates/presentation.html.example index d96258e19..b7a10cfb5 100644 --- a/atlas/static/custom/templates/presentation.html.example +++ b/atlas/static/custom/templates/presentation.html.example @@ -146,9 +146,9 @@
Generic placeholder image -

Fiches communes

-

Découvrez les espèces observées sur chaque commune du parc national et affichez leurs observations sur la carte de la commune.

-

Exemple »

+

Fiches zones

+

Découvrez les espèces observées sur chaque zone du parc national et affichez leurs observations sur la carte de la zone.

+

Exemple »

Generic placeholder image @@ -241,8 +241,8 @@ Bref, un savoir dynamique à consulter sans modération !

- Fiches par commune
- Pour chacune des 53 communes de l'aire d'adhésion du Parc national, découvrez les espèces observées et affichez leurs localisations, leurs statuts et toutes les informations contenues dans les fiches espèces. + Fiches par zone
+ Pour chacune des 53 zones de l'aire d'adhésion du Parc national, découvrez les espèces observées et affichez leurs localisations, leurs statuts et toutes les informations contenues dans les fiches espèces.

Et aussi
@@ -381,7 +381,7 @@

Silene, plate-forme SINP (Système d'information sur la nature et les paysages), est le portail de données de la région Provence-Alpes-Côte d'Azur.
- Sur ce site qui permet de saisir et de consulter une masse de données très importante, des synthèses des patrimoines flore et faune de la région par commune et par maille sont disponibles. + Sur ce site qui permet de saisir et de consulter une masse de données très importante, des synthèses des patrimoines flore et faune de la région par zone et par maille sont disponibles.

Voir aussi l'homologue pour la région Rhône-Alpes: Le pôle d'information flore et habitats (PIFH). diff --git a/atlas/static/main.js b/atlas/static/main.js index 92fb2f89f..ad21b2bdd 100644 --- a/atlas/static/main.js +++ b/atlas/static/main.js @@ -29,8 +29,8 @@ autocompleteSearch = function(inputID, urlDestination, nbProposal) { var searchUrl; if (urlDestination == "espece") { searchUrl = "/api/searchTaxon"; - } else if (urlDestination == "commune") { - searchUrl = "/api/searchCommune"; + } else if (urlDestination == "zone") { + searchUrl = "/api/searchZone"; } else { searchUrl = "/api/searchArea/"+urlDestination; @@ -62,8 +62,8 @@ autocompleteSearch = function(inputID, urlDestination, nbProposal) { var url = ui.item.value; if (urlDestination == "espece") { location.href = configuration.URL_APPLICATION + language + "/espece/" + url; - } else if (urlDestination == "commune") { - location.href = configuration.URL_APPLICATION + language + "/commune/" + url; + } else if (urlDestination == "zone") { + location.href = configuration.URL_APPLICATION + language + "/zone/" + url; } else { location.href = configuration.URL_APPLICATION + language + "/area/" + urlDestination +"/"+ url; } @@ -88,11 +88,11 @@ $("#searchTaxonsStat").focus(function() { autocompleteSearch("#searchTaxonsStat", "espece", 10); }); -$("#searchCommunes").focus(function() { - autocompleteSearch("#searchCommunes", "commune", 20); +$("#searchZones").focus(function() { + autocompleteSearch("#searchZones", "zone", 20); }); -$("#searchCommunesStat").focus(function() { - autocompleteSearch("#searchCommunesStat", "commune", 10); +$("#searchZonesStat").focus(function() { + autocompleteSearch("#searchZonesStat", "zone", 10); }); diff --git a/atlas/static/mapAreas.js b/atlas/static/mapAreas.js index 1baeb8a15..0dc3532c0 100644 --- a/atlas/static/mapAreas.js +++ b/atlas/static/mapAreas.js @@ -65,7 +65,7 @@ htmlLegend = configuration.AFFICHAGE_MAILLE generateLegende(htmlLegend); function displayObsPreciseBaseUrl() { - if (sheetType === 'commune') { + if (window.location.pathname === `/zone/${areaInfos.areaCode}`) { return configuration.URL_APPLICATION + "/api/observations/" + areaInfos.areaCode } else { return configuration.URL_APPLICATION + "/api/observations/area/" + areaInfos.id_area @@ -96,13 +96,13 @@ function displayObsPreciseBaseUrl(areaCode, cd_ref) { if (configuration.AFFICHAGE_MAILLE) { displayMailleLayerLastObs(observations); } else { - displayMarkerLayerPointCommune(observations); + displayMarkerLayerPointZone(observations); } }); } function displayObsGridBaseUrl() { - if (sheetType === 'commune') { + if (window.location.pathname === `/zone/${areaInfos.areaCode}`) { return configuration.URL_APPLICATION + "/api/observationsMaille/" } else { return configuration.URL_APPLICATION + "/api/observationsMaille/area/" @@ -110,12 +110,12 @@ function displayObsGridBaseUrl() { } // display observation on click -function displayObsTaxon(insee, cd_ref) { +function displayObsTaxon(id_zone, cd_ref) { $.ajax({ url: configuration.URL_APPLICATION + "/api/observations/" + - insee + + id_zone + "/" + cd_ref, dataType: "json", @@ -132,7 +132,7 @@ function displayObsTaxon(insee, cd_ref) { if (configuration.AFFICHAGE_MAILLE) { displayMailleLayerLastObs(observations); } else { - displayMarkerLayerPointCommune(observations); + displayMarkerLayerPointZone(observations); } }); } @@ -164,9 +164,9 @@ function refreshObsArea() { .removeClass("current"); $(this).addClass("current"); if (configuration.AFFICHAGE_MAILLE) { - displayObsTaxonMaille($(this).attr("area-code"), $(this).attr("cdRef")); + displayObsTaxonMaille(this.getAttribute("area-code"), this.getAttribute("cdref")); } else { - displayObsTaxon($(this).attr("area-code"), $(this).attr("cdRef")); + displayObsTaxon(this.getAttribute("area-code"), this.getAttribute("cdref")); } var name = $(this) .find("#name") diff --git a/atlas/static/mapGenerator.js b/atlas/static/mapGenerator.js index c1df79768..445f6b6c7 100644 --- a/atlas/static/mapGenerator.js +++ b/atlas/static/mapGenerator.js @@ -32,7 +32,7 @@ function generateObservationPopup(feature, linkSpecies = false) { /* Génération popup des observations linkSpecies : indique s'il faut ou non rajouter un lien vers la fiche espèce - (cas des fiches communes ; home page) + (cas des fiches zoning ; home page) */ date = new Date(feature.properties.dateobs); popupContent = ` @@ -443,7 +443,7 @@ function displayMarkerLayerFicheEspece( } } -// ***************Fonction lastObservations: mapHome et mapCommune***************** +// ***************Fonction lastObservations: mapHome et mapZone***************** /* *** Point ****/ @@ -452,7 +452,7 @@ function onEachFeaturePointLastObs(feature, layer) { layer.bindPopup(popupContent); } -function onEachFeaturePointCommune(feature, layer) { +function onEachFeaturePointZone(feature, layer) { popupContent = generateObservationPopup(feature, true); layer.bindPopup(popupContent); } @@ -476,8 +476,8 @@ function generateGeojsonPointLastObs(observationsPoint) { function displayMarkerLayerPointLastObs(observationsPoint) { myGeoJson = generateGeojsonPointLastObs(observationsPoint); - if (typeof pointDisplayOptionsFicheCommuneHome == "undefined") { - pointDisplayOptionsFicheCommuneHome = function (feature) { + if (typeof pointDisplayOptionsFicheZoneHome == "undefined") { + pointDisplayOptionsFicheZoneHome = function (feature) { return {}; }; } @@ -487,45 +487,45 @@ function displayMarkerLayerPointLastObs(observationsPoint) { pointToLayer: function (feature, latlng) { return L.circleMarker( latlng, - pointDisplayOptionsFicheCommuneHome(feature) + pointDisplayOptionsFicheZoneHome(feature) ); }, }); map.addLayer(currentLayer); - if (typeof divLegendeFicheCommuneHome !== "undefined") { + if (typeof divLegendeFicheZoneHome !== "undefined") { legend.onAdd = function (map) { var div = L.DomUtil.create("div", "info legend"); - div.innerHTML = divLegendeFicheCommuneHome; + div.innerHTML = divLegendeFicheZoneHome; return div; }; legend.addTo(map); } } -function displayMarkerLayerPointCommune(observationsPoint) { +function displayMarkerLayerPointZone(observationsPoint) { myGeoJson = generateGeojsonPointLastObs(observationsPoint); - if (typeof pointDisplayOptionsFicheCommuneHome == "undefined") { - pointDisplayOptionsFicheCommuneHome = function (feature) { + if (typeof pointDisplayOptionsFicheZoneHome == "undefined") { + pointDisplayOptionsFicheZoneHome = function (feature) { return {}; }; } currentLayer = L.geoJson(myGeoJson, { - onEachFeature: onEachFeaturePointCommune, + onEachFeature: onEachFeaturePointZone, pointToLayer: function (feature, latlng) { return L.circleMarker( latlng, - pointDisplayOptionsFicheCommuneHome(feature) + pointDisplayOptionsFicheZoneHome(feature) ); }, }); map.addLayer(currentLayer); - if (typeof divLegendeFicheCommuneHome !== "undefined") { + if (typeof divLegendeFicheZoneHome !== "undefined") { legend.onAdd = function (map) { var div = L.DomUtil.create("div", "info legend"); - div.innerHTML = divLegendeFicheCommuneHome; + div.innerHTML = divLegendeFicheZoneHome; return div; }; legend.addTo(map); diff --git a/atlas/templates/areaSheet/_main.html b/atlas/templates/areaSheet/_main.html index 128f9b5e2..3106b4d8b 100644 --- a/atlas/templates/areaSheet/_main.html +++ b/atlas/templates/areaSheet/_main.html @@ -2,11 +2,7 @@ {% block title %} {# Personnalisez ici le titre de la page (celui qui est affiché dans l'onglet du navigateur) #} - {% if sheetType =='commune' %} - {{ _('municipality.of') }} {{ areaInfos.areaName }} - {% else %} - {{ areaInfos.typeName }} - {{ areaInfos.areaName }} - {% endif %} + {{ areaInfos.typeName }} - {{ areaInfos.areaName }} {% endblock %} {% block metaTags %} @@ -32,12 +28,6 @@ var configuration = {{configuration|tojson}}; var observations = {{observations|tojson}}; var areaInfos = {{ areaInfos | tojson }}; - var sheetType = {{ sheetType|tojson }}; - var communeArea = false; - if (sheetType === 'commune') { - var communeArea = true; - } - ; var url_limit_territory = "{{url_for('static', filename='custom/territoire.json') }}"; @@ -55,24 +45,15 @@ {% if configuration.EXTENDED_AREAS %} {% include 'templates/areaSheet/surrounding_areas.html' %} {% endif %} - {% if sheetType =='commune' %} -

{{ _('municipality.of') }} {{ areaInfos.areaName }}

- {% else %} -

{{ areaInfos.typeName }} - {{ areaInfos.areaName }}

- {% endif %} +

{{ areaInfos.typeName }} - {{ areaInfos.areaName }}

{% include 'templates/core/statHierarchy.html' %}
{% include 'templates/core/listTaxons.html' %}
- {% if sheetType =='commune' %} -
{{ configuration.NB_LAST_OBS }} {{ _('last.obs.municipality') }} - {{ areaInfos.areaName }}
- {% else %} -
{{ configuration.NB_LAST_OBS }} {{ _('last.obs.zone') }} - {{ areaInfos.areaName }}
- {% endif %} +
{{ configuration.NB_LAST_OBS }} {{ _('last.obs.zone') }} + {{ areaInfos.areaName }}
diff --git a/atlas/templates/core/listTaxons.html b/atlas/templates/core/listTaxons.html index 4e953cb09..814558d51 100644 --- a/atlas/templates/core/listTaxons.html +++ b/atlas/templates/core/listTaxons.html @@ -18,7 +18,7 @@
    {% for taxon in listTaxons.taxons %} -
  • {{ taxon.group2_inpn }} diff --git a/atlas/templates/home/globalStats.html b/atlas/templates/home/globalStats.html index 43dc616ec..8a561957f 100644 --- a/atlas/templates/home/globalStats.html +++ b/atlas/templates/home/globalStats.html @@ -45,16 +45,16 @@

    {{ _('municipalities') }}

    -
diff --git a/atlas/templates/speciesSheet/map.html b/atlas/templates/speciesSheet/map.html index 515621189..4dbe83779 100644 --- a/atlas/templates/speciesSheet/map.html +++ b/atlas/templates/speciesSheet/map.html @@ -16,8 +16,8 @@

  • - {{ communes|length|pretty }}
    - {{ _('municipalities')|lower if communes|length > 1 else _('municipality')|lower }} + {{ zone|length|pretty }}
    + {{ _('municipalities')|lower if zone|length > 1 else _('municipality')|lower }}

  • diff --git a/atlas/templates/speciesSheet/otherInformations.html b/atlas/templates/speciesSheet/otherInformations.html index ef6a9e1bf..481afd843 100644 --- a/atlas/templates/speciesSheet/otherInformations.html +++ b/atlas/templates/speciesSheet/otherInformations.html @@ -6,12 +6,12 @@
  • - {% else %} - {% endif %} @@ -80,13 +80,13 @@
    {% endif %} {% if articles | length != 0 %} -
    +
    {% else %} -
    +
    {% endif %}

    - {% for com in communes %} - {{ com.commune_maj }} + {% for com in zone %} + {{ com.area_name }} {% if not loop.last %} - {% endif %} diff --git a/atlas/translations/en/LC_MESSAGES/messages.mo b/atlas/translations/en/LC_MESSAGES/messages.mo index 39dcdca50..39f7a4e3c 100644 Binary files a/atlas/translations/en/LC_MESSAGES/messages.mo and b/atlas/translations/en/LC_MESSAGES/messages.mo differ diff --git a/atlas/translations/en/LC_MESSAGES/messages.po b/atlas/translations/en/LC_MESSAGES/messages.po index 8b6ec8e66..ffd151b70 100644 --- a/atlas/translations/en/LC_MESSAGES/messages.po +++ b/atlas/translations/en/LC_MESSAGES/messages.po @@ -119,8 +119,8 @@ msgstr "Search by species" #: static/custom/templates/navbar.html:47 #: static/custom/templates/navbar.html.sample:47 #: templates/home/globalStats.html:55 -msgid "search.city" -msgstr "Search by municipality" +msgid "search.zone" +msgstr "Search by area" #: static/custom/templates/presentation.html:4 #: static/custom/templates/presentation.html.sample:4 diff --git a/atlas/translations/fr/LC_MESSAGES/messages.mo b/atlas/translations/fr/LC_MESSAGES/messages.mo index 388a3706a..ec33eb3e4 100644 Binary files a/atlas/translations/fr/LC_MESSAGES/messages.mo and b/atlas/translations/fr/LC_MESSAGES/messages.mo differ diff --git a/atlas/translations/fr/LC_MESSAGES/messages.po b/atlas/translations/fr/LC_MESSAGES/messages.po index 0c0ede54e..56e393e4b 100644 --- a/atlas/translations/fr/LC_MESSAGES/messages.po +++ b/atlas/translations/fr/LC_MESSAGES/messages.po @@ -121,22 +121,14 @@ msgstr "Recherche par espèce" #: static/custom/templates/navbar.html:47 #: static/custom/templates/navbar.html.sample:47 #: templates/home/globalStats.html:55 -msgid "search.city" -msgstr "Recherche par commune" +msgid "search.zone" +msgstr "Recherche par zone" #: static/custom/templates/presentation.html:4 #: static/custom/templates/presentation.html.sample:4 msgid "atlas.presentation" msgstr "Présentation de l'atlas" -#: templates/areaSheet/_main.html:6 templates/areaSheet/_main.html:59 -msgid "municipality.of" -msgstr "Commune de" - -#: templates/areaSheet/_main.html:70 -msgid "last.obs.municipality" -msgstr "dernières observations dans la commune de" - #: templates/areaSheet/_main.html:73 msgid "last.obs.zone" msgstr "Dernière observations : " @@ -299,7 +291,7 @@ msgstr "Fiche" #: templates/core/tabTaxons.html:82 msgid "display.city.infos" -msgstr "Afficher les informations de la commune" +msgstr "Afficher les informations de la zone" #: templates/home/globalStats.html:4 msgid "home.insomefigures" diff --git a/atlas/translations/it/LC_MESSAGES/messages.mo b/atlas/translations/it/LC_MESSAGES/messages.mo index f23daef27..6f40e281f 100644 Binary files a/atlas/translations/it/LC_MESSAGES/messages.mo and b/atlas/translations/it/LC_MESSAGES/messages.mo differ diff --git a/atlas/translations/it/LC_MESSAGES/messages.po b/atlas/translations/it/LC_MESSAGES/messages.po index 9dcd3d1c7..ecd8a4169 100644 --- a/atlas/translations/it/LC_MESSAGES/messages.po +++ b/atlas/translations/it/LC_MESSAGES/messages.po @@ -120,8 +120,8 @@ msgstr "Cerca per species" #: static/custom/templates/navbar.html:47 #: static/custom/templates/navbar.html.sample:47 #: templates/home/globalStats.html:55 -msgid "search.city" -msgstr "Ricerca per comune" +msgid "search.zone" +msgstr "Ricerca per zona" #: static/custom/templates/presentation.html:4 #: static/custom/templates/presentation.html.sample:4 diff --git a/data/atlas/11.vm_cor_area_synthese.sql b/data/atlas/11.vm_cor_area_synthese.sql new file mode 100644 index 000000000..f37fd4c59 --- /dev/null +++ b/data/atlas/11.vm_cor_area_synthese.sql @@ -0,0 +1,45 @@ +IMPORT FOREIGN SCHEMA gn_synthese + LIMIT TO (gn_synthese.cor_area_synthese) +FROM SERVER geonaturedbserver INTO synthese; + +CREATE MATERIALIZED VIEW atlas.vm_cor_area_synthese +TABLESPACE pg_default +AS +WITH info_tmp AS ( +SELECT + sa.id_synthese, + sa.id_area, + a.centroid, + a.id_type, + s.id_nomenclature_sensitivity, + st_transform(a.geom, 4326) AS geom +FROM synthese.synthese s + JOIN synthese.cor_area_synthese sa ON sa.id_synthese = s.id_synthese + JOIN ref_geo.l_areas a ON sa.id_area = a.id_area + JOIN atlas.t_layer_territoire ON st_intersects(a.geom_4326, t_layer_territoire.geom)-- AND NOT ST_Touches(t_layer_territoire.geom, a.geom_4326) + ) +SELECT info.id_synthese, + info.id_area, + info.centroid, + info.geom AS geom, + st_asgeojson(info.geom) AS geojson_4326, + st_transform(info.centroid, 4326) AS centroid_4326, + t.type_code, + sensi.cd_nomenclature, + CASE + WHEN sensi.cd_nomenclature = '1' AND t.type_code = :'sensibility1' THEN true + WHEN sensi.cd_nomenclature = '2' AND t.type_code = :'sensibility2' THEN true + WHEN sensi.cd_nomenclature = '3' AND t.type_code = :'sensibility3' THEN true + WHEN (sensi.cd_nomenclature = '0' OR sensi.cd_nomenclature IS NULL) AND t.type_code::text = :'sensibility0' THEN true + ELSE false + END AS is_blurred_geom +FROM info_tmp info + JOIN ref_geo.bib_areas_types t ON info.id_type = t.id_type + LEFT JOIN synthese.t_nomenclatures sensi ON info.id_nomenclature_sensitivity = sensi.id_nomenclature +WHERE (t.type_code IN (:'sensibility0', :'sensibility1', :'sensibility2', :'sensibility3')) + AND (NOT sensi.cd_nomenclature = '4'::TEXT OR sensi.cd_nomenclature IS NULL ) + +WITH DATA; +CREATE UNIQUE INDEX i_vm_cor_area_synthese ON atlas.vm_cor_area_synthese USING btree (id_synthese, id_area ); + +REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_cor_area_synthese; diff --git a/data/atlas/12.atlas.t_mailles_territoire.sql b/data/atlas/12.atlas.t_mailles_territoire.sql index 9f6c07064..9a0774f97 100644 --- a/data/atlas/12.atlas.t_mailles_territoire.sql +++ b/data/atlas/12.atlas.t_mailles_territoire.sql @@ -9,7 +9,7 @@ CREATE TABLE atlas.t_mailles_territoire AS 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'))) + ON ST_intersects(a.geom, st_transform(l.geom, find_srid('ref_geo', 'l_areas', 'geom'))) WHERE a.enable = true AND t.type_code = :type_maille ; diff --git a/data/atlas/14.grant.sql b/data/atlas/14.grant.sql index 42e26451b..8bb43c7b3 100644 --- a/data/atlas/14.grant.sql +++ b/data/atlas/14.grant.sql @@ -21,7 +21,7 @@ GRANT ALL ON TABLE spatial_ref_sys TO my_reader_user;*/ GRANT USAGE ON SCHEMA atlas TO my_reader_user; GRANT SELECT ON TABLE atlas.vm_altitudes TO my_reader_user; -GRANT SELECT ON TABLE atlas.vm_communes TO my_reader_user; +GRANT SELECT ON TABLE atlas.zoning TO my_reader_user; GRANT SELECT ON TABLE atlas.vm_observations TO my_reader_user; GRANT SELECT ON TABLE atlas.vm_cor_taxon_attribut TO my_reader_user; GRANT SELECT ON TABLE atlas.vm_medias TO my_reader_user; diff --git a/data/atlas/2.atlas.vm_observations.sql b/data/atlas/2.atlas.vm_observations.sql index 3598bcd2a..60c2d1fca 100644 --- a/data/atlas/2.atlas.vm_observations.sql +++ b/data/atlas/2.atlas.vm_observations.sql @@ -3,7 +3,7 @@ --DROP materialized view atlas.vm_observations; CREATE MATERIALIZED VIEW atlas.vm_observations AS SELECT s.id_synthese AS id_observation, - s.insee, + s.id_zone, s.dateobs, s.observateurs, s.altitude_retenue, @@ -19,7 +19,7 @@ CREATE MATERIALIZED VIEW atlas.vm_observations AS CREATE UNIQUE INDEX ON atlas.vm_observations (id_observation); CREATE INDEX ON atlas.vm_observations (cd_ref); -CREATE INDEX ON atlas.vm_observations (insee); +CREATE INDEX ON atlas.vm_observations (id_zone); CREATE INDEX ON atlas.vm_observations (altitude_retenue); CREATE INDEX ON atlas.vm_observations (dateobs); CREATE INDEX index_gist_vm_observations_the_geom_point ON atlas.vm_observations USING gist (the_geom_point); diff --git a/data/atlas/7.atlas.vm_communes.sql b/data/atlas/7.atlas.vm_communes.sql deleted file mode 100644 index 99f3bcd98..000000000 --- a/data/atlas/7.atlas.vm_communes.sql +++ /dev/null @@ -1,12 +0,0 @@ --- Communes contenues entièrement dans le territoire - -CREATE MATERIALIZED VIEW atlas.vm_communes AS -SELECT c.insee, -c.commune_maj, -c.the_geom, -st_asgeojson(st_transform(c.the_geom, 4326)) as commune_geojson -FROM atlas.l_communes c -JOIN atlas.t_layer_territoire t ON ST_CONTAINS(ST_BUFFER(t.the_geom,200), c.the_geom); - -CREATE UNIQUE INDEX ON atlas.vm_communes (insee); -CREATE INDEX index_gist_vm_communes_the_geom ON atlas.vm_communes USING gist (the_geom); diff --git a/data/atlas/7.atlas.zoning.sql b/data/atlas/7.atlas.zoning.sql new file mode 100644 index 000000000..d017fb0c2 --- /dev/null +++ b/data/atlas/7.atlas.zoning.sql @@ -0,0 +1,33 @@ +-- Zones contenues entièrement dans le territoire + +CREATE TABLE atlas.zoning +( + id serial PRIMARY KEY , + id_zone int NOT NULL, + area_name character varying(50), + the_geom_4326 geometry, + zone_geojson text, + id_zoning_type int, + id_parent int +); + +-- Insertion par défaut des communes dans la table + +INSERT INTO atlas.zoning ( + id_zone, + area_name, + the_geom_4326, + zone_geojson, + id_zoning_type +) +SELECT c.id_zone, + c.area_name, + st_transform(c.the_geom, 4326), + st_asgeojson(st_transform(c.the_geom, 4326)) as zone_geojson, + type.id_type +FROM atlas.l_communes c + JOIN ref_geo.bib_areas_types type ON type.type_code = 'COM' + JOIN atlas.t_layer_territoire t ON ST_INTERSECTS(t.geom, c.the_geom); + +CREATE UNIQUE INDEX ON atlas.zoning (id); +CREATE INDEX index_gist_zoning_the_geom_4326 ON atlas.zoning USING gist (the_geom_4326); diff --git a/data/atlas/8.atlas.vm_medias.sql b/data/atlas/8.atlas.vm_medias.sql index 1960b9935..5811c80ac 100644 --- a/data/atlas/8.atlas.vm_medias.sql +++ b/data/atlas/8.atlas.vm_medias.sql @@ -12,7 +12,6 @@ CREATE MATERIALIZED VIEW atlas.vm_medias AS t_medias.id_type, t_medias.licence, t_medias.source - FROM taxonomie.t_medias -WHERE NOT t_medias.supprime = true; + FROM taxonomie.t_medias; CREATE UNIQUE INDEX ON atlas.vm_medias(id_media); diff --git a/data/atlas/without_geonature.sql b/data/atlas/without_geonature.sql index d4dbdedf6..16785dec7 100644 --- a/data/atlas/without_geonature.sql +++ b/data/atlas/without_geonature.sql @@ -3,7 +3,7 @@ CREATE TABLE synthese.syntheseff( id_organism integer DEFAULT 2, id_dataset integer, cd_nom integer, - insee character(5), + id_zone integer, dateobs date NOT NULL DEFAULT now(), observateurs character varying(255), altitude_retenue integer, @@ -14,11 +14,11 @@ CREATE TABLE synthese.syntheseff( ); INSERT INTO synthese.syntheseff -(cd_nom, insee, observateurs, altitude_retenue, the_geom_point, effectif_total, diffusion_level) -VALUES (67111, 05122, 'Mon observateur', 1254, ST_SetSRID( ST_Point( 6, 42.315), 4326), 3, 5); +(cd_nom, id_zone, observateurs, altitude_retenue, the_geom_point, effectif_total, diffusion_level) +VALUES (67111, 1, 'Mon observateur', 1254, ST_SetSRID( ST_Point( 6, 42.315), 4326), 3, 5); INSERT INTO synthese.syntheseff -(cd_nom, insee, observateurs, altitude_retenue, the_geom_point, effectif_total, diffusion_level) -VALUES (67111, 05122, 'Mon observateur 3', 940, ST_SetSRID( ST_Point( 6.1, 42.315), 4326), 2, 5); +(cd_nom, id_zone, observateurs, altitude_retenue, the_geom_point, effectif_total, diffusion_level) +VALUES (67111, 2, 'Mon observateur 3', 940, ST_SetSRID( ST_Point( 6.1, 42.315), 4326), 2, 5); CREATE TABLE gn_meta.cor_dataset_actor ( diff --git a/data/atlas_with_extended_areas.sql b/data/atlas_with_extended_areas.sql index e6decccf6..df6a8e289 100644 --- a/data/atlas_with_extended_areas.sql +++ b/data/atlas_with_extended_areas.sql @@ -15,7 +15,7 @@ CREATE INDEX ON atlas.vm_bib_areas_types(id_type); CREATE INDEX ON atlas.vm_bib_areas_types(type_code); CREATE INDEX ON atlas.vm_bib_areas_types(type_name); --- Suppression si temporaire des communes la table existe +-- Suppression si temporaire des zones la table existe DROP MATERIALIZED VIEW IF EXISTS atlas.vm_l_areas; diff --git a/data/gn2/atlas_ref_geo.sql b/data/gn2/atlas_ref_geo.sql index 79fdd086a..12ea0c810 100644 --- a/data/gn2/atlas_ref_geo.sql +++ b/data/gn2/atlas_ref_geo.sql @@ -12,12 +12,12 @@ END$$; -- création de la vm l_communes à partir des communes du ref_geo CREATE MATERIALIZED VIEW atlas.l_communes AS - SELECT c.area_code as insee, - c.area_name as commune_maj, - st_transform(c.geom, 4326) as the_geom, - st_asgeojson(st_transform(c.geom, 4326)) AS commune_geojson + SELECT c.id_area as id_zone, + c.area_name, + st_transform(c.geom, 4326) as the_geom FROM ref_geo.l_areas c JOIN ref_geo.li_municipalities m ON c.id_area = m.id_area + JOIN atlas.t_layer_territoire t ON ST_INTERSECTS(t.geom, c.geom_4326) WHERE enable=true WITH DATA; @@ -27,10 +27,10 @@ CREATE INDEX index_gist_l_communes_the_geom (the_geom); -CREATE UNIQUE INDEX l_communes_insee_idx +CREATE UNIQUE INDEX l_communes_id_zone_idx ON atlas.l_communes USING btree - (insee COLLATE pg_catalog."default"); + (id_zone COLLATE pg_catalog."default"); --################################ diff --git a/data/gn2/atlas_synthese.sql b/data/gn2/atlas_synthese.sql index ab4aebf51..3e17bd6b0 100644 --- a/data/gn2/atlas_synthese.sql +++ b/data/gn2/atlas_synthese.sql @@ -44,7 +44,7 @@ WITH areas AS ( d.altitude_retenue, d.the_geom_point, d.effectif_total, - c.insee, + c.id_zone, diffusion_level FROM obs_data d JOIN atlas.l_communes c ON st_intersects(d.the_geom_point, c.the_geom); \ No newline at end of file diff --git a/docker_install_atlas_schema.sh b/docker_install_atlas_schema.sh index d40decc36..ced613ec4 100755 --- a/docker_install_atlas_schema.sh +++ b/docker_install_atlas_schema.sh @@ -66,7 +66,7 @@ psql -v ON_ERROR_STOP=1 -d ${POSTGRES_DB} -U ${POSTGRES_USER} -h ${POSTGRES_HOST psql -v ON_ERROR_STOP=1 -d ${POSTGRES_DB} -U ${POSTGRES_USER} -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -f data/atlas/5.atlas.vm_search_taxon.sql psql -v ON_ERROR_STOP=1 -d ${POSTGRES_DB} -U ${POSTGRES_USER} -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -f data/atlas/6.atlas.vm_mois.sql -psql -v ON_ERROR_STOP=1 -d ${POSTGRES_DB} -U ${POSTGRES_USER} -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -f data/atlas/7.atlas.vm_communes.sql +psql -v ON_ERROR_STOP=1 -d ${POSTGRES_DB} -U ${POSTGRES_USER} -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -f data/atlas/7.atlas.zoning.sql psql -v ON_ERROR_STOP=1 -d ${POSTGRES_DB} -U ${POSTGRES_USER} -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -f data/atlas/8.atlas.vm_medias.sql psql -v ON_ERROR_STOP=1 -d ${POSTGRES_DB} -U ${POSTGRES_USER} -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -f data/atlas/9.atlas.vm_cor_taxon_attribut.sql psql -v ON_ERROR_STOP=1 -d ${POSTGRES_DB} -U ${POSTGRES_USER} -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -f data/atlas/10.atlas.vm_taxons_plus_observes.sql @@ -75,4 +75,4 @@ psql -v ON_ERROR_STOP=1 -d ${POSTGRES_DB} -U ${POSTGRES_USER} -h ${POSTGRES_HOST -v type_maille=$ATLAS_TYPE_MAILLE \ -f data/atlas/12.atlas.t_mailles_territoire.sql psql -v ON_ERROR_STOP=1 -d ${POSTGRES_DB} -U ${POSTGRES_USER} -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -f data/atlas/13.atlas.vm_observations_mailles.sql -psql -v ON_ERROR_STOP=1 -d ${POSTGRES_DB} -U ${POSTGRES_USER} -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -f data/atlas/atlas.refresh_materialized_view_data.sql \ No newline at end of file +psql -v ON_ERROR_STOP=1 -d ${POSTGRES_DB} -U ${POSTGRES_USER} -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -f data/atlas/atlas.refresh_materialized_view_data.sql diff --git a/docs/changelog.rst b/docs/changelog.rst index ac203698d..49c168165 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -9,6 +9,7 @@ CHANGELOG - Ajout du lien "Données personelles" dans le pied de page (#527 @juggler31) - Suppression du support des installations sans TaxHub +- Changement de la notion de "commune" en notion de "zoning" (#545 @juggler31) 🐛 **Corrections** diff --git a/docs/installation.rst b/docs/installation.rst index 5e1d19f7c..4a65fb901 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -114,9 +114,11 @@ NOTES : \q exit -* GeoNature-atlas fonctionne avec des données géographiques qui doivent être fournies en amont (mailles, limite de territoire, limite de communes). Vous avez la possibilité de récupérer ces données directement depuis le référentiel géographique de GeoNature si les données y sont présentes (``use_ref_geo_gn2=true``); ou de fournir des fichiers shapefiles (à mettre dans le répertoire ``data/ref``) +* GeoNature-atlas fonctionne avec des données géographiques qui doivent être fournies en amont (mailles, limite de territoire, limite de communes ou zone geographique). Vous avez la possibilité de récupérer ces données directement depuis le référentiel géographique de GeoNature si les données y sont présentes (``use_ref_geo_gn2=true``); ou de fournir des fichiers shapefiles (à mettre dans le répertoire ``data/ref``) -**Attention** si ``use_ref_geo_gn2=true``. Par défaut le ``ref_geo`` contient l'ensemble des communes de France, ce qui ralentit fortement l'installation lorsqu'on construit la vue matérialisée ``vm_communes`` (qui intersecte les communes avec les limites du territoire). +**Attention** si ``use_ref_geo_gn2=true``. Par défaut le ``ref_geo`` contient l'ensemble des communes de France, ce qui ralentit fortement l'installation lorsqu'on construit la table ``zoning`` (qui intersecte les communes avec les limites du territoire). + +La table `zoning` doit être remplie en indicant l'identifiant de son type de 'zone' (table `bib_areas_types``). Pour accelérer l'installation, vous pouvez "désactiver" certaines communes du ``ref_geo``, dont vous ne vous servez pas. Voir l'exemple de requête ci-dessous : diff --git a/docs/vues_materialisees_maj.rst b/docs/vues_materialisees_maj.rst index 9c85bc27e..7d019c136 100644 --- a/docs/vues_materialisees_maj.rst +++ b/docs/vues_materialisees_maj.rst @@ -50,7 +50,7 @@ Les champs de cette table sont ``cd_nom``, ``id_statut``, ``id_habitat``, ``id_r - ``atlas.vm_phenologies`` qui renvoie le nombre d'observations pour chaque mois et chaque taxon. -- ``atlas.vm_communes`` qui renvoie les communes du territoire. A adapter si on n'a pas importé les communes dans ``atlas.l_communes`` +- ``atlas.zoning`` qui renvoie les zones du territoire. A adapter si on n'a pas importé les communes dans ``atlas.l_communes`` - ``atlas.vm_medias`` qui renvoie tous les médias des taxons, sur la base du schéma ``taxonomie`` de TaxHub diff --git a/install_db.sh b/install_db.sh index faa82742e..a8710b3f3 100755 --- a/install_db.sh +++ b/install_db.sh @@ -149,7 +149,7 @@ if ! database_exists $db_name ogr2ogr -f "PostgreSQL" \ -t_srs EPSG:4326 \ -lco GEOMETRY_NAME=the_geom \ - -sql "SELECT $colonne_nom_commune AS commune_maj, $colonne_insee AS insee FROM $file_name" \ + -sql "SELECT $colonne_nom_commune AS area_name, $colonne_insee AS insee FROM $file_name" \ PG:"host=$db_host port=$db_port dbname=$db_name user=$owner_atlas password=$owner_atlas_pass schemas=atlas" \ -nln l_communes $communes_shp @@ -256,7 +256,7 @@ if ! database_exists $db_name "4.atlas.vm_altitudes.sql" "5.atlas.vm_search_taxon.sql" "6.atlas.vm_mois.sql" - "7.atlas.vm_communes.sql" + "7.atlas.zoning.sql" "8.atlas.vm_medias.sql" "9.atlas.vm_cor_taxon_attribut.sql" "10.atlas.vm_taxons_plus_observes.sql"