diff --git a/CenRa_SICEN/__init__.py b/CenRa_SICEN/__init__.py index 82f4db1..aa75791 100644 --- a/CenRa_SICEN/__init__.py +++ b/CenRa_SICEN/__init__.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- """ /*************************************************************************** - SICEN - A QGIS plugin - Filtre sur données SICEN - ------------------- +SICEN + A QGIS plugin +Filtre sur données SICEN + ------------------- begin : 2014-10-17 copyright : (C) 2014 by Guillaume COSTES email : guillaume.costes@espaces-naturels.fr @@ -18,10 +18,11 @@ * (at your option) any later version. * * * ***************************************************************************/ - This script initializes the plugin, making it known to QGIS. +This script initializes the plugin, making it known to QGIS. """ from __future__ import absolute_import + def classFactory(iface): # load SICEN class from file SICEN from .sicen import SICEN diff --git a/CenRa_SICEN/resources_rc.py b/CenRa_SICEN/resources_rc.py index 569a744..6f916d5 100644 --- a/CenRa_SICEN/resources_rc.py +++ b/CenRa_SICEN/resources_rc.py @@ -5,10 +5,9 @@ # Created by: The Resource Compiler for PyQt5 (Qt v5.15.2) # # WARNING! All changes made in this file will be lost! -try: - from PyQt5 import QtCore -except: - from PyQt6 import QtCore + +from qgis.PyQt import QtCore + qt_resource_data = b"\ \x00\x00\x0d\x89\ \x89\ @@ -558,10 +557,13 @@ else: rcc_version = 2 qt_resource_struct = qt_resource_struct_v2 + def qInitResources(): QtCore.qRegisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data) + def qCleanupResources(): QtCore.qUnregisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data) + qInitResources() diff --git a/CenRa_SICEN/sicen.py b/CenRa_SICEN/sicen.py index e130e61..071bafc 100644 --- a/CenRa_SICEN/sicen.py +++ b/CenRa_SICEN/sicen.py @@ -1,61 +1,20 @@ # -*- coding: utf-8 -*- -""" -/*************************************************************************** - SICEN - A QGIS plugin - Filtre sur données SICEN - ------------------- - begin : 2014-10-17 - copyright : (C) 2014 by Guillaume COSTES (CENRA) - email : guillaume.costes@espaces-naturels.fr - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ -""" -"""from __future__ import absolute_import -# Import the PyQt and QGIS libraries -from builtins import str -from builtins import object -from PyQt4.QtCore import * -from PyQt4.QtGui import * -from qgis.core import * -from qgis.gui import * -from qgis.utils import iface""" from builtins import str from builtins import object import os -try: - from PyQt5.QtCore import * - from PyQt5.QtGui import * -except: - from PyQt6.QtCore import * - from PyQt6.QtGui import * -from qgis.PyQt import uic -from qgis.core import * -from qgis.core import QgsDataSourceUri, QgsWkbTypes, QgsLayerTreeGroup, QgsLayerTreeLayer -from qgis.PyQt.QtGui import QFont -from qgis.PyQt.QtWidgets import QMenu, QAction, QDialog, QDialogButtonBox, QLabel, QApplication, QTabWidget, QWidget, QGroupBox, QGridLayout, QComboBox, QCheckBox, QCalendarWidget, QToolBox, QFrame, QLineEdit, QSizePolicy, QFileDialog #Modifié +# from qgis.PyQt import uic +from qgis.core import QgsDataSourceUri, QgsLayerTreeLayer, QgsProject, QgsVectorLayer +from qgis.PyQt.QtGui import QIcon +from qgis.PyQt.QtWidgets import QMenu, QAction, QFileDialog +from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication, qVersion # Initialize Qt resources from file resources.py from . import resources_rc # Import the code for the dialog from .sicendialog import SICENDialog -from .tools.resources import maj_verif,pyperclip -pyperclip() -try: - from .tools.PythonSQL import login_base -except: - print('Pas de fichier PythonSQL') import os.path import qgis import datetime @@ -63,12 +22,20 @@ import csv from .forms.about_form import AboutDialog -import psycopg2 -import psycopg2.extras -import base64 +# import psycopg2 +# import psycopg2.extras +# import base64 import socket import os -#import sys + +from .tools.resources import maj_verif, pyperclip +pyperclip() +try: + from .tools.PythonSQL import login_base +except ValueError: + print('Pas de fichier PythonSQL') + +# import sys class SICEN(object): @@ -93,11 +60,11 @@ class SICEN(object): self.dlg = SICENDialog() maj_verif('CenRa_SICEN') - version = qgis.utils.pluginMetadata('CenRa_SICEN','version') + version = qgis.utils.pluginMetadata('CenRa_SICEN', 'version') # Display About window on first use s = QSettings() versionUse = s.value("sicen/version", 1, type=str) - if str(versionUse) != str(version) : + if str(versionUse) != str(version): s.setValue("sicen/version", str(version)) self.open_about_dialog() @@ -105,12 +72,12 @@ class SICEN(object): self.toolBar = self.iface.addToolBar("SICEN") self.toolBar.setObjectName("SICEN") - ## Create action that will start plugin configuration + # Create action that will start plugin configuration self.action = QAction( QIcon(":/plugins/sicen/sicen.png"), u"Ouverture des données SICEN", self.iface.mainWindow()) self.action.setEnabled(False) - if os.access('N:/',os.R_OK): + if os.access('N:/', os.R_OK): self.action.setEnabled(True) # connect the action to the run method self.action.triggered.connect(self.ouverture) @@ -119,12 +86,12 @@ class SICEN(object): self.toolBar.addAction(self.action) self.iface.addPluginToMenu(u"SICEN", self.action) - ## Create action that will start plugin configuration + # Create action that will start plugin configuration self.action = QAction( QIcon(":/plugins/sicen/sicen_export.png"), u"Export liste d'espèces", self.iface.mainWindow()) self.action.setEnabled(False) - IPAddr=socket.gethostbyname(socket.gethostname()) + IPAddr = socket.gethostbyname(socket.gethostname()) if IPAddr[0:11] == "100.100.100": self.action.setEnabled(True) elif IPAddr[0:9] == "192.168.0": @@ -139,17 +106,17 @@ class SICEN(object): self.iface.addPluginToMenu(u"SICEN", self.action) self.menu = QMenu() - self.menu.setTitle( QCoreApplication.translate( "SICEN","&SICEN" ) ) + self.menu.setTitle(QCoreApplication.translate("SICEN", "&SICEN")) - self.sicen_ouverture = QAction( QIcon(":/plugins/SICEN/sicen.png"), QCoreApplication.translate("SICEN", u"Ouverture des données SICEN" ), self.iface.mainWindow() ) - self.sicen_export = QAction( QIcon(":/plugins/SICEN/sicen_export.png"), QCoreApplication.translate("SICEN", u"Export liste d'espèces" ), self.iface.mainWindow() ) + self.sicen_ouverture = QAction(QIcon(":/plugins/SICEN/sicen.png"), QCoreApplication.translate("SICEN", u"Ouverture des données SICEN"), self.iface.mainWindow()) + self.sicen_export = QAction(QIcon(":/plugins/SICEN/sicen_export.png"), QCoreApplication.translate("SICEN", u"Export liste d'espèces"), self.iface.mainWindow()) - self.menu.addActions( [self.sicen_ouverture, self.sicen_export] ) + self.menu.addActions([self.sicen_ouverture, self.sicen_export]) menu_bar = self.iface.mainWindow().menuBar() actions = menu_bar.actions() - lastAction = actions[ len( actions ) - 1 ] - menu_bar.insertMenu( lastAction, self.menu ) + lastAction = actions[len(actions) - 1] + menu_bar.insertMenu(lastAction, self.menu) self.sicen_ouverture.triggered.connect(self.ouverture) self.sicen_export.triggered.connect(self.export) @@ -175,15 +142,15 @@ class SICEN(object): cur = account[7] con = account[8] - ## Creation des listes deroulantes - # Listing de valeur des champs + # Creation des listes deroulantes + # Listing de valeur des champs SQL_observateur = u"""SELECT DISTINCT nom || '_' || prenom as nom FROM md.personne ORDER BY nom""" SQL_nom_com = u"""SELECT DISTINCT nom FROM saisie.commune ORDER BY nom""" SQL_nom_vern = u"""SELECT DISTINCT nom_vern FROM _agregation_ra.observations_table ORDER BY nom_vern""" SQL_nom_complet = u"""SELECT DISTINCT nom_complet FROM _agregation_ra.observations_table ORDER BY nom_complet""" SQL_ordre = u"""SELECT DISTINCT ordre FROM _agregation_ra.observations_table ORDER BY ordre""" - # Generation des listes + # Generation des listes cur.execute(SQL_observateur) list_observateur = cur.fetchall() @@ -201,69 +168,69 @@ class SICEN(object): con.close() - - # Ajout des items dans les combobox + # Ajout des items dans les combobox self.dlg.observateur_1.clear() i = 0 while i < len(list_observateur): self.dlg.observateur_1.addItems(list_observateur[i]) - i=i+1 - self.dlg.observateur_1.setCurrentIndex(-1) # Pour ne pas commencer la liste au premier item + i = i + 1 + # Pour ne pas commencer la liste au premier item + self.dlg.observateur_1.setCurrentIndex(-1) self.dlg.observateur_2.clear() i = 0 while i < len(list_observateur): self.dlg.observateur_2.addItems(list_observateur[i]) - i=i+1 + i = i + 1 self.dlg.observateur_2.setCurrentIndex(-1) self.dlg.observateur_3.clear() i = 0 while i < len(list_observateur): self.dlg.observateur_3.addItems(list_observateur[i]) - i=i+1 + i = i + 1 self.dlg.observateur_3.setCurrentIndex(-1) self.dlg.observateur_4.clear() i = 0 while i < len(list_observateur): self.dlg.observateur_4.addItems(list_observateur[i]) - i=i+1 + i = i + 1 self.dlg.observateur_4.setCurrentIndex(-1) self.dlg.nom_com_1.clear() i = 0 while i < len(list_nom_com): self.dlg.nom_com_1.addItems(list_nom_com[i]) - i=i+1 + i = i + 1 self.dlg.nom_com_1.setCurrentIndex(-1) self.dlg.nom_com_2.clear() i = 0 while i < len(list_nom_com): self.dlg.nom_com_2.addItems(list_nom_com[i]) - i=i+1 + i = i + 1 self.dlg.nom_com_2.setCurrentIndex(-1) self.dlg.nom_vern.clear() i = 0 while i < len(list_nom_vern): self.dlg.nom_vern.addItems(list_nom_vern[i]) - i=i+1 + i = i + 1 self.dlg.nom_vern.setCurrentIndex(-1) self.dlg.nom_complet.clear() i = 0 while i < len(list_nom_complet): self.dlg.nom_complet.addItems(list_nom_complet[i]) - i=i+1 + i = i + 1 self.dlg.nom_complet.setCurrentIndex(-1) self.dlg.ordre.clear() i = 0 while i < len(list_ordre): self.dlg.ordre.addItems(list_ordre[i]) - i=i+1 + i = i + 1 self.dlg.ordre.setCurrentIndex(-1) # show the dialog @@ -283,39 +250,39 @@ class SICEN(object): con = account[8] # Requete filtre observateur - if self.dlg.observateur_1.currentIndex() != -1 : + if self.dlg.observateur_1.currentIndex() != - 1: sql_obs1 = """ "observateur" LIKE '%""" + self.dlg.observateur_1.currentText() + "%' " - else : + else: sql_obs1 = '' - if self.dlg.observateur_2.currentIndex() != -1 : + if self.dlg.observateur_2.currentIndex() != - 1: sql_obs2 = """ "observateur" LIKE '%""" + self.dlg.observateur_2.currentText() + "%' " - else : + else: sql_obs2 = '' - if self.dlg.observateur_3.currentIndex() != -1 : + if self.dlg.observateur_3.currentIndex() != - 1: sql_obs3 = """ "observateur" LIKE '%""" + self.dlg.observateur_3.currentText() + "%' " - else : + else: sql_obs3 = '' - if self.dlg.observateur_4.currentIndex() != -1 : + if self.dlg.observateur_4.currentIndex() != - 1: sql_obs4 = """ "observateur" LIKE '%""" + self.dlg.observateur_4.currentText() + "%' " - else : + else: sql_obs4 = '' reqwhere_obs = sql_obs1 + 'OR' + sql_obs2 + 'OR' + sql_obs3 + 'OR' + sql_obs4 - while reqwhere_obs[-2:] == 'OR' : + while reqwhere_obs[-2:] == 'OR': reqwhere_obs = reqwhere_obs[:-2] - while reqwhere_obs[:2] == 'OR' : + while reqwhere_obs[:2] == 'OR': reqwhere_obs = reqwhere_obs[2:] # Requete communes # Connexion a la BD - #con = psycopg2.connect("dbname="+ dbname + " user=" + user + " host=" + host + " password=" + password + " port=" + port) - #cur = con.cursor() + # con = psycopg2.connect("dbname="+ dbname + " user=" + user + " host=" + host + " password=" + password + " port=" + port) + # cur = con.cursor() - if self.dlg.nom_com_1.currentIndex() != -1 : + if self.dlg.nom_com_1.currentIndex() != - 1: nom_com = self.dlg.nom_com_1.currentText() SQL_code_INSEE = u"""SELECT DISTINCT code_insee FROM saisie.commune WHERE nom = '""" + nom_com + "'" cur.execute(SQL_code_INSEE) @@ -323,10 +290,10 @@ class SICEN(object): code_INSEE = list_code_INSEE[0][0] sql_insee_1 = """ "code_insee" = '""" + code_INSEE + "' " - else : + else: sql_insee_1 = '' - if self.dlg.nom_com_2.currentIndex() != -1 : + if self.dlg.nom_com_2.currentIndex() != - 1: nom_com = self.dlg.nom_com_2.currentText() SQL_code_INSEE = u"""SELECT DISTINCT code_insee FROM saisie.commune WHERE nom = '""" + nom_com + "'" cur.execute(SQL_code_INSEE) @@ -334,14 +301,14 @@ class SICEN(object): code_INSEE = list_code_INSEE[0][0] sql_insee_2 = """ "code_insee" = '""" + code_INSEE + "' " - else : + else: sql_insee_2 = '' reqwhere_insee = sql_insee_1 + 'OR' + sql_insee_2 - while reqwhere_insee[-2:] == 'OR' : + while reqwhere_insee[-2:] == 'OR': reqwhere_insee = reqwhere_insee[:-2] - while reqwhere_insee[:2] == 'OR' : + while reqwhere_insee[:2] == 'OR': reqwhere_insee = reqwhere_insee[2:] con.close() @@ -351,290 +318,288 @@ class SICEN(object): date_min = self.dlg.date_min.selectedDate().toString("yyyy-MM-dd") date_max = self.dlg.date_max.selectedDate().toString("yyyy-MM-dd") - if date_min != today : + if date_min != today: sql_date_min = """ "date_obs" >= '""" + date_min + "' " - else : + else: sql_date_min = '' - if date_max != today : + if date_max != today: sql_date_max = """ "date_obs" <= '""" + date_max + "' " - else : + else: sql_date_max = '' reqwhere_date = sql_date_min + 'AND' + sql_date_max - while reqwhere_obs[-3:] == 'AND' : + while reqwhere_obs[-3:] == 'AND': reqwhere_obs = reqwhere_obs[:-3] - while reqwhere_obs[:3] == 'AND' : + while reqwhere_obs[:3] == 'AND': reqwhere_obs = reqwhere_obs[3:] # Requete regne - if self.dlg.Animalia.isChecked() == 1 : + if self.dlg.Animalia.isChecked() == 1: sql_Animalia = """"regne" = 'Animalia'""" - else : + else: sql_Animalia = '' - if self.dlg.Plantae.isChecked() == 1 : + if self.dlg.Plantae.isChecked() == 1: sql_Plantae = """"regne" = 'Plantae'""" - else : + else: sql_Plantae = '' reqwhere_regne = sql_Animalia + 'OR' + sql_Plantae - while reqwhere_regne[-2:] == 'OR' : + while reqwhere_regne[-2:] == 'OR': reqwhere_regne = reqwhere_regne[:-2] - while reqwhere_regne[:2] == 'OR' : + while reqwhere_regne[:2] == 'OR': reqwhere_regne = reqwhere_regne[2:] # Requete ordre - if self.dlg.ordre.currentIndex() != -1 : + if self.dlg.ordre.currentIndex() != - 1: reqwhere_ordre = """"ordre" = '""" + self.dlg.ordre.currentText() + "'" - else : + else: reqwhere_ordre = '' # Requete sp - if self.dlg.nom_vern.currentIndex() != -1 : + if self.dlg.nom_vern.currentIndex() != - 1: sql_nom_vern = """"nom_vern" = '""" + self.dlg.nom_vern.currentText() + "'" - else : + else: sql_nom_vern = '' - if self.dlg.nom_complet.currentIndex() != -1 : + if self.dlg.nom_complet.currentIndex() != - 1: sql_nom_complet = """"nom_complet" = '""" + self.dlg.nom_complet.currentText() + "'" - else : + else: sql_nom_complet = '' reqwhere_sp = sql_nom_vern + 'OR' + sql_nom_complet - while reqwhere_sp[-2:] == 'OR' : + while reqwhere_sp[-2:] == 'OR': reqwhere_sp = reqwhere_sp[:-2] - while reqwhere_sp[:2] == 'OR' : + while reqwhere_sp[:2] == 'OR': reqwhere_sp = reqwhere_sp[2:] # Requete filtre patrimonialite - if self.dlg.LRD_01.isChecked() == 1 : - sql_lrd01 = """ lrd01 IN ('VU','EN','RE','CR') """ - else : + if self.dlg.LRD_01.isChecked() == 1: + sql_lrd01 = """ lrd01 IN ('VU', 'EN', 'RE', 'CR') """ + else: sql_lrd01 = '' - if self.dlg.LRD_07.isChecked() == 1 : - sql_lrd07 = """ lrd07 IN ('VU','EN','RE','CR') """ - else : + if self.dlg.LRD_07.isChecked() == 1: + sql_lrd07 = """ lrd07 IN ('VU', 'EN', 'RE', 'CR') """ + else: sql_lrd07 = '' - if self.dlg.LRD_26.isChecked() == 1 : - sql_lrd26 = """ lrd26 IN ('VU','EN','RE','CR') """ - else : + if self.dlg.LRD_26.isChecked() == 1: + sql_lrd26 = """ lrd26 IN ('VU', 'EN', 'RE', 'CR') """ + else: sql_lrd26 = '' - if self.dlg.LRD_38.isChecked() == 1 : - sql_lrd38 = """ lrd38 IN ('VU','EN','RE','CR', 'AS-1', 'AS-2', 'AS-3') """ - else : + if self.dlg.LRD_38.isChecked() == 1: + sql_lrd38 = """ lrd38 IN ('VU', 'EN', 'RE', 'CR', 'AS-1', 'AS-2', 'AS-3') """ + else: sql_lrd38 = '' - if self.dlg.LRD_42.isChecked() == 1 : - sql_lrd42 = """ lrd42 IN ('VU','EN','RE','CR') """ - else : + if self.dlg.LRD_42.isChecked() == 1: + sql_lrd42 = """ lrd42 IN ('VU', 'EN', 'RE', 'CR') """ + else: sql_lrd42 = '' - if self.dlg.LRD_69.isChecked() == 1 : - sql_lrd69 = """ lrd69 IN ('VU','EN','RE','CR') """ - else : + if self.dlg.LRD_69.isChecked() == 1: + sql_lrd69 = """ lrd69 IN ('VU', 'EN', 'RE', 'CR') """ + else: sql_lrd69 = '' - if self.dlg.LRD_73.isChecked() == 1 : - sql_lrd73 = """ lrd73 IN ('VU','EN','RE','CR') """ - else : + if self.dlg.LRD_73.isChecked() == 1: + sql_lrd73 = """ lrd73 IN ('VU', 'EN', 'RE', 'CR') """ + else: sql_lrd73 = '' - if self.dlg.LRD_74.isChecked() == 1 : - sql_lrd74 = """ lrd74 IN ('VU','EN','RE','CR') """ - else : + if self.dlg.LRD_74.isChecked() == 1: + sql_lrd74 = """ lrd74 IN ('VU', 'EN', 'RE', 'CR') """ + else: sql_lrd74 = '' - if self.dlg.LRR_Flore.isChecked() == 1 : + if self.dlg.LRR_Flore.isChecked() == 1: sql_LRR_Flore = u""" "TAXO_GROUPE" IN ('Plantes') AND (lrr like '%CR%' OR lrr like '%EN%' OR lrr like '%EW%' OR lrr like '%RE%' OR lrr like '%VU%')""" - else : + else: sql_LRR_Flore = '' - if self.dlg.LRR_Oiseaux.isChecked() == 1 : + if self.dlg.LRR_Oiseaux.isChecked() == 1: sql_LRR_Oiseaux = u""" "TAXO_GROUPE" = 'Oiseaux' AND (lrr like '%RE %' OR lrr like '%CR %' OR lrr like '%EN %' OR lrr like '%VU %') """ - else : + else: sql_LRR_Oiseaux = '' - if self.dlg.LRR_Autre.isChecked() == 1 : + if self.dlg.LRR_Autre.isChecked() == 1: sql_LRR_Autre = u""" (lrr like '%RE %' OR lrr like '%CR %' OR lrr like '%EN %' OR lrr like '%VU %') AND "TAXO_GROUPE" NOT IN ('Oiseaux', 'Plantes') """ - else : + else: sql_LRR_Autre = '' - if self.dlg.LRN_Flore.isChecked() == 1 : + if self.dlg.LRN_Flore.isChecked() == 1: sql_LRN_Flore = u""" "TAXO_GROUPE" ilike 'plantes' AND (lrr like '%CR%' OR lrr like '%EN%' OR lrr like '%EW%' OR lrr like '%RE%' OR lrr like '%VU%') """ - else : + else: sql_LRN_Flore = '' - if self.dlg.LRN_Oiseaux.isChecked() == 1 : + if self.dlg.LRN_Oiseaux.isChecked() == 1: sql_LRN_Oiseaux = u""" "TAXO_GROUPE" = 'Oiseaux' AND (lrn like '%RE %' OR lrn like '%CR %' OR lrn like '%EN %' OR lrn like '%VU %') """ - else : + else: sql_LRN_Oiseaux = '' - if self.dlg.LRN_Ortho.isChecked() == 1 : + if self.dlg.LRN_Ortho.isChecked() == 1: sql_LRN_Ortho = u""" "TAXO_GROUPE" ilike 'orthoptères' AND (lrn like '1%' OR lrn like '2%' OR lrn like '3%') """ - else : + else: sql_LRN_Ortho = '' - if self.dlg.LRN_Autre.isChecked() == 1 : + if self.dlg.LRN_Autre.isChecked() == 1: sql_LRN_Autre = u""" (lrr like '%CR%' OR lrr like '%EN%' OR lrr like '%EW%' OR lrr like '%RE%' OR lrr like '%VU%') AND "TAXO_GROUPE" NOT IN ('Oiseaux', 'Plantes', 'Orthoptères') """ - else : + else: sql_LRN_Autre = '' - if self.dlg.LRE.isChecked() == 1 : - sql_lre = """ lre IN ('VU','EN','RE','CR', 'EW', 'EX') """ - else : + if self.dlg.LRE.isChecked() == 1: + sql_lre = """ lre IN ('VU', 'EN', 'RE', 'CR', 'EW', 'EX') """ + else: sql_lre = '' - if self.dlg.UICN.isChecked() == 1 : - sql_UICN = """ lrm IN ('VU','EN','RE','CR', 'EW', 'EX') """ - else : + if self.dlg.UICN.isChecked() == 1: + sql_UICN = """ lrm IN ('VU', 'EN', 'RE', 'CR', 'EW', 'EX') """ + else: sql_UICN = '' - - if self.dlg.PATRIMONIALITE.isChecked() == 1 : + if self.dlg.PATRIMONIALITE.isChecked() == 1: sql_patrimonialite = """"patrimonialite" IS NOT NULL """ - else : + else: sql_patrimonialite = '' - if self.dlg.PATRI01.isChecked() == 1 : + if self.dlg.PATRI01.isChecked() == 1: sql_patri01 = """"patri01" IS NOT NULL """ - else : + else: sql_patri01 = '' - if self.dlg.PATRI07.isChecked() == 1 : + if self.dlg.PATRI07.isChecked() == 1: sql_patri07 = """"patri07" IS NOT NULL """ - else : + else: sql_patri07 = '' - if self.dlg.PATRI26.isChecked() == 1 : + if self.dlg.PATRI26.isChecked() == 1: sql_patri26 = """"patri26" IS NOT NULL """ - else : + else: sql_patri26 = '' - if self.dlg.PATRI38.isChecked() == 1 : + if self.dlg.PATRI38.isChecked() == 1: sql_patri38 = """"patri38" IS NOT NULL """ - else : + else: sql_patri38 = '' - if self.dlg.PATRI42.isChecked() == 1 : + if self.dlg.PATRI42.isChecked() == 1: sql_patri42 = """"patri42" IS NOT NULL """ - else : + else: sql_patri42 = '' - if self.dlg.PATRI69.isChecked() == 1 : + if self.dlg.PATRI69.isChecked() == 1: sql_patri69 = """"patri69" IS NOT NULL """ - else : + else: sql_patri69 = '' - if self.dlg.PATRI73.isChecked() == 1 : + if self.dlg.PATRI73.isChecked() == 1: sql_patri73 = """"patri73" IS NOT NULL """ - else : + else: sql_patri73 = '' - if self.dlg.PATRI74.isChecked() == 1 : + if self.dlg.PATRI74.isChecked() == 1: sql_patri74 = """"patri74" IS NOT NULL """ - else : + else: sql_patri74 = '' - - if self.dlg.ZNIEFF.isChecked() == 1 : + if self.dlg.ZNIEFF.isChecked() == 1: sql_znieff = """"znieff" IS NOT NULL """ - else : + else: sql_znieff = '' - if self.dlg.DH_AnnII.isChecked() == 1 : + if self.dlg.DH_AnnII.isChecked() == 1: sql_dh_an2 = """"dh_an2" IS NOT NULL """ - else : + else: sql_dh_an2 = '' - if self.dlg.PD_38.isChecked() == 1 : + if self.dlg.PD_38.isChecked() == 1: sql_pd38 = """"pd38" IS NOT NULL """ - else : + else: sql_pd38 = '' - if self.dlg.PD_42.isChecked() == 1 : + if self.dlg.PD_42.isChecked() == 1: sql_pd42 = """"pd42" IS NOT NULL """ - else : + else: sql_pd42 = '' - if self.dlg.PN.isChecked() == 1 : + if self.dlg.PN.isChecked() == 1: sql_pn = """"pn" IS NOT NULL """ - else : + else: sql_pn = '' - if self.dlg.PR.isChecked() == 1 : + if self.dlg.PR.isChecked() == 1: sql_pr = """"pr" IS NOT NULL """ - else : + else: sql_pr = '' - reqwhere_pat = sql_lrd01 + 'OR' + sql_lrd07 + 'OR' + sql_lrd26 + 'OR' + sql_lrd38 + 'OR' + sql_lrd42 + 'OR' + sql_lrd69 + 'OR' + sql_lrd73 + 'OR' + sql_lrd74 + 'OR' + sql_lre + 'OR' + sql_LRN_Flore + 'OR' + sql_LRN_Oiseaux + 'OR' + sql_LRN_Ortho + 'OR' + sql_LRN_Autre + 'OR' + sql_LRR_Flore + 'OR' + sql_LRR_Oiseaux + 'OR' + sql_LRR_Autre + 'OR' + sql_UICN + 'OR' + sql_pd38 + 'OR' + sql_pd42 + 'OR' + sql_pn + 'OR' + sql_pr + 'OR' + sql_dh_an2 + 'OR' + sql_patri01 + 'OR' + sql_patri07 + 'OR' + sql_patri26 + 'OR' + sql_patri38 + 'OR' + sql_patri42 + 'OR' + sql_patri69 + 'OR' + sql_patri73 + 'OR' + sql_patri74 + 'OR' + sql_patrimonialite + reqwhere_pat = sql_lrd01 + 'OR' + sql_lrd07 + 'OR' + sql_lrd26 + 'OR' + sql_lrd38 + 'OR' + sql_lrd42 + 'OR' + sql_lrd69 + 'OR' + sql_lrd73 + 'OR' + sql_lrd74 + 'OR' + sql_lre + 'OR' + sql_LRN_Flore + 'OR' + sql_LRN_Oiseaux + 'OR' + sql_LRN_Ortho + 'OR' + sql_LRN_Autre + 'OR' + sql_LRR_Flore + 'OR' + sql_LRR_Oiseaux + 'OR' + sql_LRR_Autre + 'OR' + sql_UICN + 'OR' + sql_pd38 + 'OR' + sql_pd42 + 'OR' + sql_pn + 'OR' + sql_pr + 'OR' + sql_znieff + 'OR' + sql_dh_an2 + 'OR' + sql_patri01 + 'OR' + sql_patri07 + 'OR' + sql_patri26 + 'OR' + sql_patri38 + 'OR' + sql_patri42 + 'OR' + sql_patri69 + 'OR' + sql_patri73 + 'OR' + sql_patri74 + 'OR' + sql_patrimonialite - while reqwhere_pat.find('OROR') != -1 : - reqwhere_pat = reqwhere_pat.replace('OROR','OR') - while reqwhere_pat[-2:] == 'OR' : + while reqwhere_pat.find('OROR') != - 1: + reqwhere_pat = reqwhere_pat.replace('OROR', 'OR') + while reqwhere_pat[-2:] == 'OR': reqwhere_pat = reqwhere_pat[:-2] - while reqwhere_pat[:2] == 'OR' : + while reqwhere_pat[:2] == 'OR': reqwhere_pat = reqwhere_pat[2:] # Requete geom - if self.dlg.bouton_geom.isChecked() == 1 : + if self.dlg.bouton_geom.isChecked() == 1: layer = self.iface.activeLayer() - if layer == None : - #self.iface.messageBar().pushMessage(u"Vous devez sélectionner une table !", level=QgsMessageBar.WARNING, duration=5) - self.iface.messageBar().pushMessage("Ooops", u"Vous devez sélectionner une table !", level=Qgis.Warning, duration=5) + if layer is None: + # self.iface.messageBar().pushMessage(u"Vous devez sélectionner une table !", level=QgsMessageBar.WARNING, duration=5) + self.iface.messageBar().pushMessage("Ooops", u"Vous devez sélectionner une table !", level=1, duration=5) - else : + else: selection = layer.selectedFeatures() - if layer.selectedFeatureCount() >= 1 : + if layer.selectedFeatureCount() >= 1: GEOM = '' for feature in selection: geom = feature.geometry() - poly = "ST_GeomFromText('"+geom.asWkt()+"',2154)," + poly = "ST_GeomFromText('" + geom.asWkt() + "',2154)," GEOM = GEOM + poly poly = GEOM[0:-1] - #print(poly) + # print(poly) buffer = self.dlg.buffer.text() reqwhere_geom = " ST_intersects(geometrie,ST_Buffer(ST_Collect(array[" + poly + "]), " + buffer + " ))" # Requete finale - reqwhere_final = '(' + reqwhere_obs + ')' + 'AND' + reqwhere_insee + 'AND' + reqwhere_ordre + 'AND' + reqwhere_sp + 'AND' + '(' + reqwhere_pat + ')' + 'AND' + reqwhere_regne + 'AND' + reqwhere_date + 'AND' + reqwhere_geom + reqwhere_final = '(' + reqwhere_obs + ')' + 'AND' + reqwhere_insee + 'AND' + reqwhere_ordre + 'AND' + reqwhere_sp + 'AND' + '(' + reqwhere_pat + ')' + 'AND' + reqwhere_regne + 'AND' + reqwhere_date + 'AND' + reqwhere_geom # Nettoyage de la requete finale - while reqwhere_final.find('ANDAND') != -1 : - reqwhere_final = reqwhere_final.replace('ANDAND','AND') - while reqwhere_final.find('AND()AND') != -1 : - reqwhere_final = reqwhere_final.replace('AND()AND','AND') - while reqwhere_final[-3:] == 'AND' : + while reqwhere_final.find('ANDAND') != - 1: + reqwhere_final = reqwhere_final.replace('ANDAND', 'AND') + while reqwhere_final.find('AND()AND') != - 1: + reqwhere_final = reqwhere_final.replace('AND()AND', 'AND') + while reqwhere_final[-3:] == 'AND': reqwhere_final = reqwhere_final[:-3] - while reqwhere_final[:5] == '()AND' : + while reqwhere_final[:5] == '()AND': reqwhere_final = reqwhere_final[5:] - while reqwhere_final[-5:] == 'AND()' : + while reqwhere_final[-5:] == 'AND()': reqwhere_final = reqwhere_final[:-5] - while reqwhere_final[:3] == 'AND' : + while reqwhere_final[:3] == 'AND': reqwhere_final = reqwhere_final[3:] - ## Affichage des tables + # Affichage des tables table_name = 'observations' uri = QgsDataSourceUri() - uri.setConnection(host ,port ,dbname ,user ,mdp) + uri.setConnection(host, port, dbname, user, mdp) - if self.dlg.centroide.isChecked() == 1 : - ### Centroide - if reqwhere_final.find('()') != -1 : + if self.dlg.centroide.isChecked() == 1: + # Centroide + if reqwhere_final.find('()') != - 1: reqwhere_final = '' print(reqwhere_final) uri.setDataSource("_agregation_ra", "observations_centroide", "geometrie", reqwhere_final, "gid") layer = self.iface.addVectorLayer(uri.uri(), table_name + '_centroides', "postgres") - else : + else: account = login_base("account") user = account[0] @@ -646,25 +611,25 @@ class SICEN(object): con = account[8] # Creation group de couches - #i = qgis.utils.iface - #legende = i.legendInterface() + # i = qgis.utils.iface + # legende = i.legendInterface() legende = QgsProject.instance().layerTreeRoot() - #nomgroupe = 'Observations' - #groupe = legende.addGroup(nomgroupe,False) + # nomgroupe = 'Observations' + # groupe = legende.addGroup(nomgroupe,False) groupe = legende.insertGroup(1, "Observations") groupe = legende.findGroup("Observations") # Récupération de la liste de groupes - #toc = iface.layerTreeView() - #toc = qgis.utils.iface.legendInterface() - #groups = toc. - #groups = toc.groups() - #index = groups.index(nomgroupe) - index = 1 + # toc = iface.layerTreeView() + # toc = qgis.utils.iface.legendInterface() + # groups = toc. + # groups = toc.groups() + # index = groups.index(nomgroupe) + # index = 1 - ### Polygone + # Polygone reqwhere_final_poly = '(' + reqwhere_final + " AND GeometryType(geometrie) LIKE '%POLYGON%'" + ')' - if reqwhere_final_poly.find('()') != -1 : + if reqwhere_final_poly.find('()') != - 1: reqwhere_final_poly = "(GeometryType(geometrie) LIKE '%POLYGON%')" SQL_count_poly = u"""SELECT DISTINCT count(gid) AS count FROM _agregation_ra.observations_table WHERE """ + reqwhere_final_poly @@ -674,16 +639,16 @@ class SICEN(object): if count_poly != 0: uri.setDataSource("_agregation_ra", "observations_table", "geometrie", reqwhere_final_poly, "gid") - #layer_poly = self.iface.addVectorLayer(uri.uri(), table_name + '_poly', "postgres") + # layer_poly = self.iface.addVectorLayer(uri.uri(), table_name + '_poly', "postgres") layer_poly = QgsVectorLayer(uri.uri(), table_name + '_poly', "postgres") QgsProject.instance().addMapLayer(layer_poly, False) - #legende.moveLayer(layer_poly,index) - #groupe.addLayer(layer_poly) + # legende.moveLayer(layer_poly,index) + # groupe.addLayer(layer_poly) groupe.insertChildNode(0, QgsLayerTreeLayer(layer_poly)) - ### Point + # Point reqwhere_final_point = '(' + reqwhere_final + " AND GeometryType(geometrie) LIKE '%POINT%'" + ')' - if reqwhere_final_point.find('()') != -1 : + if reqwhere_final_point.find('()') != - 1: reqwhere_final_point = "(GeometryType(geometrie) LIKE '%POINT%')" SQL_count_point = u"""SELECT DISTINCT count(gid) AS count FROM _agregation_ra.observations_table WHERE """ + reqwhere_final_point @@ -693,16 +658,16 @@ class SICEN(object): if count_point != 0: uri.setDataSource("_agregation_ra", "observations_table", "geometrie", reqwhere_final_point, "gid") - #layer_point = self.iface.addVectorLayer(uri.uri(), table_name + '_point', "postgres") + # layer_point = self.iface.addVectorLayer(uri.uri(), table_name + '_point', "postgres") layer_point = QgsVectorLayer(uri.uri(), table_name + '_point', "postgres") QgsProject.instance().addMapLayer(layer_point, False) - #legende.moveLayer(layer_point,index) - #groupe.addLayer(layer_point) + # legende.moveLayer(layer_point,index) + # groupe.addLayer(layer_point) groupe.insertChildNode(0, QgsLayerTreeLayer(layer_point)) - ### Ligne + # Ligne reqwhere_final_ligne = '(' + reqwhere_final + " AND GeometryType(geometrie) LIKE '%LINE%'" + ')' - if reqwhere_final_ligne.find('()') != -1 : + if reqwhere_final_ligne.find('()') != - 1: reqwhere_final_ligne = "(GeometryType(geometrie) LIKE '%LINE%')" SQL_count_ligne = u"""SELECT DISTINCT count(gid) AS count FROM _agregation_ra.observations_table WHERE """ + reqwhere_final_ligne @@ -712,61 +677,60 @@ class SICEN(object): if count_ligne != 0: uri.setDataSource("_agregation_ra", "observations_table", "geometrie", reqwhere_final_ligne, "gid") - #layer_ligne = self.iface.addVectorLayer(uri.uri(), table_name + '_ligne', "postgres") + # layer_ligne = self.iface.addVectorLayer(uri.uri(), table_name + '_ligne', "postgres") layer_ligne = QgsVectorLayer(uri.uri(), table_name + '_ligne', "postgres") QgsProject.instance().addMapLayer(layer_ligne, False) - #legende.moveLayer(layer_ligne,index) - #groupe.addLayer(layer_ligne) + # legende.moveLayer(layer_ligne,index) + # groupe.addLayer(layer_ligne) groupe.insertChildNode(0, QgsLayerTreeLayer(layer_ligne)) # ajout des couches dans le groupe Observations - #legende.setGroupExpanded (index, True) + # legende.setGroupExpanded (index, True) - #self.iface.messageBar().pushMessage(u"Extraction réussie : ", u" Pensez à renommer vos couches pour plus de lisibilité.", level=QgsMessageBar.INFO, duration=10) - self.iface.messageBar().pushMessage("Info", u"Extraction réussie : ", u" Pensez à renommer vos couches pour plus de lisibilité.", level=Qgis.Success, duration=4) + # self.iface.messageBar().pushMessage(u"Extraction réussie : ", u" Pensez à renommer vos couches pour plus de lisibilité.", level=QgsMessageBar.INFO, duration=10) + self.iface.messageBar().pushMessage("Info", u"Extraction réussie : ", u" Pensez à renommer vos couches pour plus de lisibilité.", level=0, duration=4) - - elif layer.selectedFeatureCount() == 0 : - #self.iface.messageBar().pushMessage(u"Vous devez sélectionner au moins un polygone !", level=QgsMessageBar.WARNING, duration=5) - self.iface.messageBar().pushMessage("Ooops", u"Vous devez sélectionner au moins un polygone !", level=Qgis.Warning, duration=5) + elif layer.selectedFeatureCount() == 0: + # self.iface.messageBar().pushMessage(u"Vous devez sélectionner au moins un polygone !", level=QgsMessageBar.WARNING, duration=5) + self.iface.messageBar().pushMessage("Ooops", u"Vous devez sélectionner au moins un polygone !", level=1, duration=5) reqwhere_geom = '' - else : - #self.iface.messageBar().pushMessage(u"Vous devez sélectionner qu'un seul polygone !", level=QgsMessageBar.WARNING, duration=5) - self.iface.messageBar().pushMessage("Ooops", u"Vous ne devez sélectionner qu'un seul polygone !", level=Qgis.Warning, duration=5) + else: + # self.iface.messageBar().pushMessage(u"Vous devez sélectionner qu'un seul polygone !", level=QgsMessageBar.WARNING, duration=5) + self.iface.messageBar().pushMessage("Ooops", u"Vous ne devez sélectionner qu'un seul polygone !", level=1, duration=5) reqwhere_geom = '' - else : + else: # Requete finale - reqwhere_final = '(' + reqwhere_obs + ')' + 'AND' + reqwhere_insee + 'AND' + reqwhere_ordre + 'AND' + reqwhere_sp + 'AND' + '(' + reqwhere_pat + ')' + 'AND' + reqwhere_regne + 'AND' + reqwhere_date + reqwhere_final = '(' + reqwhere_obs + ')' + 'AND' + reqwhere_insee + 'AND' + reqwhere_ordre + 'AND' + reqwhere_sp + 'AND' + '(' + reqwhere_pat + ')' + 'AND' + reqwhere_regne + 'AND' + reqwhere_date # Nettoyage de la requete finale - while reqwhere_final.find('ANDAND') != -1 : - reqwhere_final = reqwhere_final.replace('ANDAND','AND') - while reqwhere_final.find('AND()AND') != -1 : - reqwhere_final = reqwhere_final.replace('AND()AND','AND') - while reqwhere_final[-3:] == 'AND' : + while reqwhere_final.find('ANDAND') != - 1: + reqwhere_final = reqwhere_final.replace('ANDAND', 'AND') + while reqwhere_final.find('AND()AND') != - 1: + reqwhere_final = reqwhere_final.replace('AND()AND', 'AND') + while reqwhere_final[-3:] == 'AND': reqwhere_final = reqwhere_final[:-3] - while reqwhere_final[:5] == '()AND' : + while reqwhere_final[:5] == '()AND': reqwhere_final = reqwhere_final[5:] - while reqwhere_final[-5:] == 'AND()' : + while reqwhere_final[-5:] == 'AND()': reqwhere_final = reqwhere_final[:-5] - while reqwhere_final[:3] == 'AND' : + while reqwhere_final[:3] == 'AND': reqwhere_final = reqwhere_final[3:] - ## Affichage des tables + # Affichage des tables table_name = 'observations' uri = QgsDataSourceUri() - uri.setConnection(host ,port ,dbname ,user ,mdp) + uri.setConnection(host, port, dbname, user, mdp) - ## Centroide - if self.dlg.centroide.isChecked() == 1 : - if reqwhere_final.find('()') != -1 : + # Centroide + if self.dlg.centroide.isChecked() == 1: + if reqwhere_final.find('()') != - 1: reqwhere_final = '' uri.setDataSource("_agregation_ra", "observations_centroide", "geometrie", reqwhere_final, "gid") layer = self.iface.addVectorLayer(uri.uri(), table_name + '_centroides', "postgres") - else : + else: account = login_base("account") user = account[0] @@ -779,24 +743,24 @@ class SICEN(object): # Creation group de couches i = qgis.utils.iface - #legende = i.legendInterface() + # legende = i.legendInterface() legende = QgsProject.instance().layerTreeRoot() - #nomgroupe = 'Observations' - #groupe = legende.addGroup(nomgroupe,False) + # nomgroupe = 'Observations' + # groupe = legende.addGroup(nomgroupe,False) groupe = legende.insertGroup(1, "Observations") groupe = legende.findGroup("Observations") # Récupération de la liste de groupes - #toc = iface.layerTreeView() - #toc = qgis.utils.iface.legendInterface() - #groups = toc. - #groups = toc.groups() - #index = groups.index(nomgroupe) - index = 1 + # toc = iface.layerTreeView() + # toc = qgis.utils.iface.legendInterface() + # groups = toc. + # groups = toc.groups() + # index = groups.index(nomgroupe) + # index = 1 - ### Polygone + # Polygone reqwhere_final_poly = '(' + reqwhere_final + " AND GeometryType(geometrie) LIKE '%POLYGON%'" + ')' - if reqwhere_final_poly.find('()') != -1 : + if reqwhere_final_poly.find('()') != - 1: reqwhere_final_poly = "(GeometryType(geometrie) LIKE '%POLYGON%')" SQL_count_poly = u"""SELECT DISTINCT count(gid) AS count FROM _agregation_ra.observations_table WHERE """ + reqwhere_final_poly @@ -806,16 +770,16 @@ class SICEN(object): if count_poly != 0: uri.setDataSource("_agregation_ra", "observations_table", "geometrie", reqwhere_final_poly, "gid") - #layer_poly = self.iface.addVectorLayer(uri.uri(), table_name + '_poly', "postgres") + # layer_poly = self.iface.addVectorLayer(uri.uri(), table_name + '_poly', "postgres") layer_poly = QgsVectorLayer(uri.uri(), table_name + '_poly', "postgres") QgsProject.instance().addMapLayer(layer_poly, False) - #legende.moveLayer(layer_poly,index) - #groupe.addLayer(layer_poly) + # legende.moveLayer(layer_poly,index) + # groupe.addLayer(layer_poly) groupe.insertChildNode(0, QgsLayerTreeLayer(layer_poly)) - ### Point + # Point reqwhere_final_point = '(' + reqwhere_final + " AND GeometryType(geometrie) LIKE '%POINT%'" + ')' - if reqwhere_final_point.find('()') != -1 : + if reqwhere_final_point.find('()') != - 1: reqwhere_final_point = "(GeometryType(geometrie) LIKE '%POINT%')" SQL_count_point = u"""SELECT DISTINCT count(gid) AS count FROM _agregation_ra.observations_table WHERE """ + reqwhere_final_point @@ -825,16 +789,16 @@ class SICEN(object): if count_point != 0: uri.setDataSource("_agregation_ra", "observations_table", "geometrie", reqwhere_final_point, "gid") - #layer_point = self.iface.addVectorLayer(uri.uri(), table_name + '_point', "postgres") + # layer_point = self.iface.addVectorLayer(uri.uri(), table_name + '_point', "postgres") layer_point = QgsVectorLayer(uri.uri(), table_name + '_point', "postgres") QgsProject.instance().addMapLayer(layer_point, False) - #legende.moveLayer(layer_point,index) - #groupe.addLayer(layer_point) + # legende.moveLayer(layer_point,index) + # groupe.addLayer(layer_point) groupe.insertChildNode(0, QgsLayerTreeLayer(layer_point)) - ### Ligne + # Ligne reqwhere_final_ligne = '(' + reqwhere_final + " AND GeometryType(geometrie) LIKE '%LINE%'" + ')' - if reqwhere_final_ligne.find('()') != -1 : + if reqwhere_final_ligne.find('()') != - 1: reqwhere_final_ligne = "(GeometryType(geometrie) LIKE '%LINE%')" SQL_count_ligne = u"""SELECT DISTINCT count(gid) AS count FROM _agregation_ra.observations_table WHERE """ + reqwhere_final_ligne @@ -844,18 +808,18 @@ class SICEN(object): if count_ligne != 0: uri.setDataSource("_agregation_ra", "observations_table", "geometrie", reqwhere_final_ligne, "gid") - #layer_ligne = self.iface.addVectorLayer(uri.uri(), table_name + '_ligne', "postgres") + # layer_ligne = self.iface.addVectorLayer(uri.uri(), table_name + '_ligne', "postgres") layer_ligne = QgsVectorLayer(uri.uri(), table_name + '_ligne', "postgres") QgsProject.instance().addMapLayer(layer_ligne, False) - #legende.moveLayer(layer_ligne,index) - #groupe.addLayer(layer_ligne) + # legende.moveLayer(layer_ligne,index) + # groupe.addLayer(layer_ligne) groupe.insertChildNode(0, QgsLayerTreeLayer(layer_ligne)) # ajout des couches dans le groupe Observations - #legende.setGroupExpanded (index, True) + # legende.setGroupExpanded (index, True) - #self.iface.messageBar().pushMessage(u"Extraction réussie : ", u" Pensez à renommer vos couches pour plus de lisibilité.", level=QgsMessageBar.INFO, duration=10) - self.iface.messageBar().pushMessage("Info", u"Extraction réussie : ", u" Pensez à renommer vos couches pour plus de lisibilité.", level=Qgis.Success, duration=10) + # self.iface.messageBar().pushMessage(u"Extraction réussie : ", u" Pensez à renommer vos couches pour plus de lisibilité.", level=QgsMessageBar.INFO, duration=10) + self.iface.messageBar().pushMessage("Info", u"Extraction réussie : ", u" Pensez à renommer vos couches pour plus de lisibilité.", level=0, duration=10) pass @@ -863,13 +827,13 @@ class SICEN(object): layer = self.iface.activeLayer() - if layer == None : - #self.iface.messageBar().pushMessage(u"Vous devez sélectionner une table !", level=QgsMessageBar.WARNING, duration=5) - self.iface.messageBar().pushMessage("Ooops", u"Vous devez sélectionner une table !", level=Qgis.Warning, duration=5) + if layer is None: + # self.iface.messageBar().pushMessage(u"Vous devez sélectionner une table !", level=QgsMessageBar.WARNING, duration=5) + self.iface.messageBar().pushMessage("Ooops", u"Vous devez sélectionner une table !", level=1, duration=5) - else : + else: selection = layer.selectedFeatures() - if (layer.selectedFeatureCount() == 1) : + if (layer.selectedFeatureCount() == 1): for feature in selection: geom = feature.geometry() poly = geom.asWkt() @@ -877,76 +841,83 @@ class SICEN(object): buffer = '100' account = login_base("account") - user = account[0] - mdp = account[1] - host = account[2] - port = account[3] - dbname = account[4] + # user = account[0] + # mdp = account[1] + # host = account[2] + # port = account[3] + # dbname = account[4] cur = account[7] - con = account[8] + # con = account[8] - SQL_list_sp = u"""SELECT DISTINCT classe::text,ordre::text,nom_complet::text,split_part(nom_vern::text,',',1) as nom_vern,cd_ref::text as cd_ref,max(COALESCE(date_obs, date_debut_obs))::text AS derniere_obs FROM _agregation_ra.observations_table WHERE ST_intersects(geometrie,ST_Buffer(ST_geomFromText('""" + poly + "',2154), " + buffer + " ))GROUP BY classe::text, ordre::text, nom_complet::text, nom_vern::text, cd_ref::text ORDER BY nom_complet::text""" + SQL_list_sp = u"""SELECT DISTINCT classe::text,ordre::text,nom_complet::text,split_part(nom_vern::text,', ',1) as nom_vern,cd_ref::text as cd_ref,max(COALESCE(date_obs, date_debut_obs))::text AS derniere_obs FROM _agregation_ra.observations_table WHERE ST_intersects(geometrie,ST_Buffer(ST_geomFromText('""" + poly + "',2154), " + buffer + " ))GROUP BY classe::text, ordre::text, nom_complet::text, nom_vern::text, cd_ref::text ORDER BY nom_complet::text""" cur.execute(SQL_list_sp) data_sp = cur.fetchall() chemin_fichier, __ = QFileDialog.getSaveFileName(None, 'Enregistrer sous...', r"C:\Users\\Desktop\\" + str(os.environ.get("USERNAME")) + '_liste_sp.csv', "Fichiers CSV (*.csv)") - #file = open(chemin_fichier, 'wb') + # file = open(chemin_fichier, 'wb') file = open(chemin_fichier, 'w', newline='', encoding='utf-8') - #file.write('\ufeff'.encode('utf8')) # BOM (optionel...Permet a Excel d'ouvrir proprement le fichier en UTF-8) + # file.write('\ufeff'.encode('utf8')) # BOM (optionel...Permet a Excel d'ouvrir proprement le fichier en UTF-8) file.write('\ufeff') - writer = csv.writer(file, delimiter = ';') # délimiteur ';' pour faciliter l'ouverture avec Excel - writer.writerow(['Classe', 'Ordre', 'Nom Complet', 'Nom Vernaculaire','cd_ref', 'Date Derniere Observation']) # Création des entêtes + # délimiteur ';' pour faciliter l'ouverture avec Excel + writer = csv.writer(file, delimiter=';') + # Création des entêtes + writer.writerow(['Classe', 'Ordre', 'Nom Complet', 'Nom Vernaculaire', 'cd_ref', 'Date Derniere Observation']) - for row in data_sp : # Boucle d'écriture ligne par ligne dans le csv - #print(1) + # Boucle d'écriture ligne par ligne dans le csv + for row in data_sp: + # print(1) list_sp = [] - if row[0] == None : # Si la valeur est 'None' l'encodage ne peut se faire donc boucle d'évitement + # Si la valeur est 'None' l'encodage ne peut se faire donc boucle d'évitement + if row[0] is None: row0 = str(row[0]) row0 = '' - else : + else: row0 = row[0] - #print(row0) + # print(row0) list_sp.append(row0) - if row[1] == None : # Si la valeur est 'None' l'encodage ne peut se faire donc boucle d'évitement + # Si la valeur est 'None' l'encodage ne peut se faire donc boucle d'évitement + if row[1] is None: row1 = str(row[1]) row1 = '' - else : + else: row1 = row[1] list_sp.append(row1) - if row[2] == None : # Si la valeur est 'None' l'encodage ne peut se faire donc boucle d'évitement + # Si la valeur est 'None' l'encodage ne peut se faire donc boucle d'évitement + if row[2] is None: row2 = str(row[2]) row2 = '' - else : + else: row2 = row[2] list_sp.append(row2) - if row[3] == None : # Si la valeur est 'None' l'encodage ne peut se faire donc boucle d'évitement + # Si la valeur est 'None' l'encodage ne peut se faire donc boucle d'évitement + if row[3] is None: row3 = str(row[3]) row3 = '' - else : + else: row3 = row[3] list_sp.append(row3) - if row[4] == None : + if row[4] is None: row4 = str(row[4]) row4 = '' - else : + else: row4 = row[4] list_sp.append(row4) - if row[5] == None : + if row[5] is None: row5 = str(row[5]) row5 = '' - else : + else: row5 = row[5] print(row5) list_sp.append(row5) writer.writerow(list_sp) file.close() - #self.iface.messageBar().pushMessage(u"Export réussi dans " + chemin_fichier , level=QgsMessageBar.INFO, duration=5) - self.iface.messageBar().pushMessage("Ooops", u"Export réussi dans " + chemin_fichier, level=Qgis.Success, duration=5) + # self.iface.messageBar().pushMessage(u"Export réussi dans " + chemin_fichier , level=QgsMessageBar.INFO, duration=5) + self.iface.messageBar().pushMessage("Ooops", u"Export réussi dans " + chemin_fichier, level=0, duration=5) - elif (layer.selectedFeatureCount() == 0) : - #self.iface.messageBar().pushMessage(u"Vous devez sélectionner au moins un polygone !", level=QgsMessageBar.WARNING, duration=5) - self.iface.messageBar().pushMessage("Ooops", u"Vous devez sélectionner au moins un polygone !", level=Qgis.Warning, duration=5) + elif (layer.selectedFeatureCount() == 0): + # self.iface.messageBar().pushMessage(u"Vous devez sélectionner au moins un polygone !", level=QgsMessageBar.WARNING, duration=5) + self.iface.messageBar().pushMessage("Ooops", u"Vous devez sélectionner au moins un polygone !", level=1, duration=5) - else : - #self.iface.messageBar().pushMessage(u"Vous devez sélectionner qu'un seul polygone !", level=QgsMessageBar.WARNING, duration=5) - self.iface.messageBar().pushMessage("Ooops", u"Vous ne devez sélectionner qu'un seul polygone !", level=Qgis.Warning, duration=5) + else: + # self.iface.messageBar().pushMessage(u"Vous devez sélectionner qu'un seul polygone !", level=QgsMessageBar.WARNING, duration=5) + self.iface.messageBar().pushMessage("Ooops", u"Vous ne devez sélectionner qu'un seul polygone !", level=1, duration=5) diff --git a/CenRa_SICEN/sicendialog.py b/CenRa_SICEN/sicendialog.py index 4ab7be7..5df13bf 100644 --- a/CenRa_SICEN/sicendialog.py +++ b/CenRa_SICEN/sicendialog.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- """ /*************************************************************************** - SICENDialog - A QGIS plugin - Filtre sur données SICEN - ------------------- +SICENDialog + A QGIS plugin +Filtre sur données SICEN + ------------------- begin : 2014-10-17 copyright : (C) 2014 by Guillaume COSTES email : guillaume.costes@espaces-naturels.fr @@ -20,8 +20,8 @@ ***************************************************************************/ """ -from qgis.PyQt import QtCore, QtGui -from qgis.PyQt.QtWidgets import QAction, QDialog +# from qgis.PyQt import QtCore, QtGui +from qgis.PyQt.QtWidgets import QDialog from .ui_sicen import Ui_SICEN # create the dialog for zoom to point diff --git a/CenRa_SICEN/ui_sicen.py b/CenRa_SICEN/ui_sicen.py index ba141f8..00f8649 100644 --- a/CenRa_SICEN/ui_sicen.py +++ b/CenRa_SICEN/ui_sicen.py @@ -8,9 +8,10 @@ # WARNING! All changes made in this file will be lost! from builtins import object -from qgis.PyQt import QtCore, QtGui +from qgis.PyQt import QtCore from qgis.PyQt.QtGui import QFont -from qgis.PyQt.QtWidgets import QAction, QDialog, QDialogButtonBox, QLabel, QApplication, QTabWidget, QWidget, QGroupBox, QGridLayout, QComboBox, QCheckBox, QCalendarWidget, QToolBox, QFrame, QLineEdit, QSizePolicy #Modifié +# Modifié +from qgis.PyQt.QtWidgets import QDialogButtonBox, QLabel, QApplication, QTabWidget, QWidget, QGroupBox, QGridLayout, QComboBox, QCheckBox, QCalendarWidget, QToolBox, QFrame, QLineEdit, QSizePolicy try: @@ -21,20 +22,22 @@ except AttributeError: try: _encoding = QApplication.UnicodeUTF8 + def _translate(context, text, disambig): return QApplication.translate(context, text, disambig, _encoding) except AttributeError: def _translate(context, text, disambig): return QApplication.translate(context, text, disambig) + class Ui_SICEN(object): def setupUi(self, SICEN): SICEN.setObjectName(_fromUtf8("SICEN")) SICEN.resize(592, 556) self.buttonBox = QDialogButtonBox(SICEN) self.buttonBox.setGeometry(QtCore.QRect(390, 520, 161, 32)) - #self.buttonBox.setOrientation(QtCore.Qt.Horizontal) - self.buttonBox.setStandardButtons(QDialogButtonBox.StandardButton(0x00400000)|QDialogButtonBox.StandardButton(0x00000400)) + # self.buttonBox.setOrientation(QtCore.Qt.Horizontal) + self.buttonBox.setStandardButtons(QDialogButtonBox.StandardButton(0x00400000) | QDialogButtonBox.StandardButton(0x00000400)) self.buttonBox.setObjectName(_fromUtf8("buttonBox")) self.Titre = QLabel(SICEN) self.Titre.setGeometry(QtCore.QRect(110, 10, 331, 31)) @@ -529,7 +532,7 @@ class Ui_SICEN(object): font.setBold(True) font.setWeight(75) self.groupBox_6.setFont(font) - self.groupBox_6.setAlignment(QtCore.Qt.AlignmentFlag(0x0001)|QtCore.Qt.AlignmentFlag(0x0001)|QtCore.Qt.AlignmentFlag(0x0080)) + self.groupBox_6.setAlignment(QtCore.Qt.AlignmentFlag(0x0001) | QtCore.Qt.AlignmentFlag(0x0001) | QtCore.Qt.AlignmentFlag(0x0080)) self.groupBox_6.setObjectName(_fromUtf8("groupBox_6")) self.gridLayoutWidget_7 = QWidget(self.groupBox_6) self.gridLayoutWidget_7.setGeometry(QtCore.QRect(10, 20, 491, 21)) @@ -680,8 +683,9 @@ class Ui_SICEN(object): self.retranslateUi(SICEN) self.Emprise.setCurrentIndex(0) self.protections.setCurrentIndex(0) - self.buttonBox.accepted.connect(SICEN.accept) - self.buttonBox.rejected.connect(SICEN.reject) #Modifié + self.buttonBox.accepted.connect(SICEN.accept) + # Modifié + self.buttonBox.rejected.connect(SICEN.reject) QtCore.QMetaObject.connectSlotsByName(SICEN) def retranslateUi(self, SICEN): @@ -753,4 +757,3 @@ class Ui_SICEN(object): self.label_11.setText(_translate("SICEN", "4.", None)) self.Emprise.setTabText(self.Emprise.indexOf(self.tab_4), _translate("SICEN", "Filtre par Emprise", None)) self.centroide.setText(_translate("SICEN", "Utiliser les centroïdes pour les observations autres que ponctuelles", None)) -