+
+
+Your QGIS plugin directory is located at:
+ C:/Users/gcostes/.qgis2/python/plugins
+
+
+For information on writing PyQGIS code, see http://loc8.cc/pyqgis_resources for a list of resources. +
+
+©2011-2015 GeoApt LLC - geoapt.com
+
+
diff --git a/CenRa_COPIE/README.txt b/CenRa_COPIE/README.txt
new file mode 100644
index 00000000..b966603a
--- /dev/null
+++ b/CenRa_COPIE/README.txt
@@ -0,0 +1,33 @@
+Plugin Builder Results
+
+Your plugin Copie was created in:
+ C:\Users\gcostes\.qgis2\python\plugins\Copie
+
+Your QGIS plugin directory is located at:
+ C:/Users/gcostes/.qgis2/python/plugins
+
+What's Next:
+
+ * Copy the entire directory containing your new plugin to the QGIS plugin
+ directory
+
+ * Compile the resources file using pyrcc4
+
+ * Run the tests (``make test``)
+
+ * Test the plugin by enabling it in the QGIS plugin manager
+
+ * Customize it by editing the implementation file: ``copie.py``
+
+ * Create your own custom icon, replacing the default icon.png
+
+ * Modify your user interface by opening Copie.ui in Qt Designer
+
+ * You can use the Makefile to compile your Ui and resource files when
+ you make changes. This requires GNU make (gmake)
+
+For more information, see the PyQGIS Developer Cookbook at:
+http://www.qgis.org/pyqgis-cookbook/index.html
+
+(C) 2011-2014 GeoApt LLC - geoapt.com
+Git revision : $Format:%H$
diff --git a/CenRa_COPIE/copie.py.bak b/CenRa_COPIE/copie.py.bak
new file mode 100644
index 00000000..057d5db1
--- /dev/null
+++ b/CenRa_COPIE/copie.py.bak
@@ -0,0 +1,360 @@
+# -*- coding: utf-8 -*-
+"""
+/***************************************************************************
+ Copie
+ A QGIS plugin
+ Permet la copie d'une table dans une base PostGis
+ -------------------
+ begin : 2015-04-13
+ git sha : $Format:%H$
+ copyright : (C) 2015 by Guillaume COSTES - CEN Rhône-Alpes
+ 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 PyQt4.QtCore import *
+#from PyQt4.QtGui import *
+from qgis.core import *
+from qgis.gui import *
+# Initialize Qt resources from file resources.py
+import resources_rc
+# Import the code for the dialog
+from copie_dialog import CopieDialog
+import os.path
+
+
+class Copie:
+ """QGIS Plugin Implementation."""
+
+ def __init__(self, iface):
+ """Constructor.
+
+ :param iface: An interface instance that will be passed to this class
+ which provides the hook by which you can manipulate the QGIS
+ application at run time.
+ :type iface: QgsInterface
+ """
+ # Save reference to the QGIS interface
+ self.iface = iface
+ # initialize plugin directory
+ self.plugin_dir = os.path.dirname(__file__)
+ # initialize locale
+ locale = QSettings().value('locale/userLocale')[0:2]
+ locale_path = os.path.join(
+ self.plugin_dir,
+ 'i18n',
+ 'Copie_{}.qm'.format(locale))
+
+ if os.path.exists(locale_path):
+ self.translator = QTranslator()
+ self.translator.load(locale_path)
+
+ if qVersion() > '4.3.3':
+ QCoreApplication.installTranslator(self.translator)
+
+ # Create the dialog (after translation) and keep reference
+ self.dlg = CopieDialog()
+
+ # Declare instance attributes
+ self.actions = []
+ self.menu = self.tr(u'&Copie')
+ # TODO: We are going to let the user set this up in a future iteration
+ self.toolbar = self.iface.addToolBar(u'Copie')
+ self.toolbar.setObjectName(u'Copie')
+
+ # noinspection PyMethodMayBeStatic
+ def tr(self, message):
+ """Get the translation for a string using Qt translation API.
+
+ We implement this ourselves since we do not inherit QObject.
+
+ :param message: String for translation.
+ :type message: str, QString
+
+ :returns: Translated version of message.
+ :rtype: QString
+ """
+ # noinspection PyTypeChecker,PyArgumentList,PyCallByClass
+ return QCoreApplication.translate('Copie', message)
+
+
+ def add_action(
+ self,
+ icon_path,
+ text,
+ callback,
+ enabled_flag=True,
+ add_to_menu=True,
+ add_to_toolbar=True,
+ status_tip=None,
+ whats_this=None,
+ parent=None):
+ """Add a toolbar icon to the toolbar.
+
+ :param icon_path: Path to the icon for this action. Can be a resource
+ path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
+ :type icon_path: str
+
+ :param text: Text that should be shown in menu items for this action.
+ :type text: str
+
+ :param callback: Function to be called when the action is triggered.
+ :type callback: function
+
+ :param enabled_flag: A flag indicating if the action should be enabled
+ by default. Defaults to True.
+ :type enabled_flag: bool
+
+ :param add_to_menu: Flag indicating whether the action should also
+ be added to the menu. Defaults to True.
+ :type add_to_menu: bool
+
+ :param add_to_toolbar: Flag indicating whether the action should also
+ be added to the toolbar. Defaults to True.
+ :type add_to_toolbar: bool
+
+ :param status_tip: Optional text to show in a popup when mouse pointer
+ hovers over the action.
+ :type status_tip: str
+
+ :param parent: Parent widget for the new action. Defaults None.
+ :type parent: QWidget
+
+ :param whats_this: Optional text to show in the status bar when the
+ mouse pointer hovers over the action.
+
+ :returns: The action that was created. Note that the action is also
+ added to self.actions list.
+ :rtype: QAction
+ """
+
+ icon = QIcon(icon_path)
+ action = QAction(icon, text, parent)
+ action.triggered.connect(callback)
+ action.setEnabled(enabled_flag)
+
+ if status_tip is not None:
+ action.setStatusTip(status_tip)
+
+ if whats_this is not None:
+ action.setWhatsThis(whats_this)
+
+ if add_to_toolbar:
+ self.toolbar.addAction(action)
+
+ if add_to_menu:
+ self.iface.addPluginToMenu(
+ self.menu,
+ action)
+
+ self.actions.append(action)
+
+ return action
+
+ def initGui(self):
+ """Create the menu entries and toolbar icons inside the QGIS GUI."""
+
+ icon_path = ':/plugins/Copie/table_copie.png'
+ self.add_action(
+ icon_path,
+ text=self.tr(u'Copie'),
+ callback=self.run,
+ parent=self.iface.mainWindow())
+
+
+ def unload(self):
+ """Removes the plugin menu item and icon from QGIS GUI."""
+ for action in self.actions:
+ self.iface.removePluginMenu(
+ self.tr(u'&Copie'),
+ action)
+ self.iface.removeToolBarIcon(action)
+ # remove the toolbar
+ del self.toolbar
+
+
+ def run(self):
+ """Run method that performs all the real work"""
+ layer = self.iface.activeLayer()
+
+ if layer == None :
+ self.iface.messageBar().pushMessage(u"Vous devez sélectionner une table !", level=QgsMessageBar.WARNING, duration=5)
+
+ else :
+ # Récupération des sources de la couche active
+ list_sources = layer.source().split(" ")
+ # dbname
+ source_db = [s for s in list_sources if "dbname" in s][0].split("'")[1]
+ # schema
+ source_schema = [s for s in list_sources if "table" in s][0].split('"')[1]
+ # tablename
+ source_tablename = [s for s in list_sources if "table" in s][0].split('"')[3]
+
+ if source_db != 'sig4269':
+ self.iface.messageBar().pushMessage(u"Un référentiel ne peut être copié, utilisez les filtres !", level=QgsMessageBar.CRITICAL, duration=10)
+
+ else :
+ import psycopg2
+
+ config = "//100.100.100.100/bd_sig/z_QGIS/config.txt" # Chemin du fichier config
+ # Fonction de lecture des lignes du fichier config
+ def readline(n):
+ with open(config, "r") as f:
+ for lineno, line in enumerate(f):
+ if lineno == n:
+ return line.strip() # Permet d'enlever les retours chariots
+
+ host = readline(10)
+ port = readline(12)
+ dbname = readline(14)
+ user = readline(16)
+ password = readline(18)
+
+ con = psycopg2.connect("dbname="+ dbname + " user=" + user + " host=" + host + " password=" + password)
+ cur = con.cursor()
+ # Creation de la liste des schemas de la base de donnees
+ SQL = """WITH list_schema AS (
+ SELECT catalog_name, schema_name
+ FROM information_schema.schemata
+ WHERE schema_name <> 'information_schema'
+ AND schema_name !~ E'^pg_'
+ ORDER BY schema_name
+ )
+
+ SELECT string_agg(schema_name,',')
+ FROM list_schema
+ GROUP BY catalog_name"""
+
+ cur.execute(SQL)
+
+ list_brut = str(cur.next())
+
+ list = list_brut [3:-3]
+ listItems = list.split(",")
+
+ con.close()
+
+ self.dlg.schema.clear()
+ self.dlg.schema.addItems(listItems)
+ self.dlg.schema.setCurrentIndex(-1) # Pour ne pas commencer la liste au premier schema
+
+
+ self.dlg.table_source.setText(source_schema + "." + source_tablename) # Affiche le nom de la table source
+ # show the dialog
+ self.dlg.show()
+ # Run the dialog event loop
+ result = self.dlg.exec_()
+ # See if OK was pressed
+ if result:
+ #******************************debut script*********************************
+ ### config.txt
+ config = "//100.100.100.100/bd_sig/z_QGIS/config.txt" # Chemin du fichier config
+
+ # Fonction de lecture des lignes du fichier config
+ def readline(n):
+ with open(config, "r") as f:
+ for lineno, line in enumerate(f):
+ if lineno == n:
+ return line.strip() # Permet d'enlever les retours chariots
+
+ # Recuperation des donnees
+ host = readline(10)
+ port = readline(12)
+ dbname = readline(14)
+ user = readline(16)
+ password = readline(18)
+
+ con = psycopg2.connect("dbname="+ dbname + " user=" + user + " host=" + host + " password=" + password)
+ cur = con.cursor()
+
+ # Récupération de la couche active
+ layer = self.iface.activeLayer()
+
+ # Récupération des sources de la couche active
+ list_sources = layer.source().split(" ")
+ # dbname
+ source_db = [s for s in list_sources if "dbname" in s][0].split("'")[1]
+ # schema
+ source_schema = [s for s in list_sources if "table" in s][0].split('"')[1]
+ # tablename
+ source_tablename = [s for s in list_sources if "table" in s][0].split('"')[3]
+
+ if self.dlg.schema.currentIndex() == -1 :
+ QMessageBox.warning(None, "Oups :", "Veuillez choisir un dossier de destination.")
+ return
+
+ schema = self.dlg.schema.currentText()
+
+ if self.dlg.table_destination.text() == '' :
+ QMessageBox.warning(None, "Oups :", "Veuillez choisir un nom de destination.")
+ return
+
+ if self.dlg.annee.text() == 'aaaa' or self.dlg.annee.text() == '':
+ tablename = schema + "_" + self.dlg.table_destination.text().lower()
+ else :
+ tablename = schema + "_" + self.dlg.table_destination.text().lower() + "_" + self.dlg.annee.text()
+
+ tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
+
+ geom = readline(6)
+
+ if self.dlg.table_vide.isChecked() == 1 :
+ SQL_table = "CREATE TABLE " + schema + "." + tablename + " AS SELECT * FROM " + source_schema + "." + source_tablename + " LIMIT 0;"
+ else :
+ SQL_table = "CREATE TABLE " + schema + "." + tablename + " AS SELECT * FROM " + source_schema + "." + source_tablename
+
+
+ SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
+ SQL_sequence_01 = "CREATE SEQUENCE " + schema + "." + tablename + "_gid_seq" + " INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1;"
+ SQL_sequence_02 = "ALTER TABLE " + schema + "." + tablename + " ALTER COLUMN gid SET DEFAULT nextval(\'" + schema + "." + tablename + "_gid_seq\'::regclass);"
+ SQL_sequence_03 = "SELECT setval(\'" + schema + "." + tablename + "_gid_seq\'::regclass, (SELECT max(gid) AS max_gid FROM " + schema + "." + tablename + "));"
+ SQL_sequence_04 = "ALTER SEQUENCE " + schema + "." + tablename + "_gid_seq" + " OWNED BY " + schema + "." + tablename + ".gid;"
+
+ SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
+ SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
+ SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
+ SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
+ SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
+
+ cur.execute(SQL_table)
+ cur.execute(SQL_pkey)
+ cur.execute(SQL_sequence_01)
+ cur.execute(SQL_sequence_02)
+ cur.execute(SQL_sequence_03)
+ cur.execute(SQL_sequence_04)
+
+ if layer.wkbType() == QGis.WKBPoint :
+ cur.execute(SQL_trigger_coordonnees)
+
+ if layer.wkbType() == QGis.WKBMultiLineString :
+ cur.execute(SQL_trigger_length_m)
+ cur.execute(SQL_trigger_length_km)
+
+ if layer.wkbType() == QGis.WKBMultiPolygon :
+ cur.execute(SQL_trigger_area_m2)
+ cur.execute(SQL_trigger_area_ha)
+
+ con.commit()
+
+ ### Affichage de la table
+ uri = QgsDataSourceURI()
+ # set host name, port, database name, username and password
+ uri.setConnection(host ,port ,dbname ,user ,password)
+ # set database schema, table name, geometry column and optionaly subset (WHERE clause)
+ uri.setDataSource(schema, tablename, geom)
+
+ layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
+
+ con.commit()
+ con.close()
+
+ self.iface.messageBar().pushMessage("Table \"" + source_schema + "." + source_tablename + u"\" copiée dans \"" + schema + "." + tablename + "\"." , level=QgsMessageBar.INFO, duration=10)
+ pass
diff --git a/CenRa_COPIE/copie_dialog.py.bak b/CenRa_COPIE/copie_dialog.py.bak
new file mode 100644
index 00000000..a951555c
--- /dev/null
+++ b/CenRa_COPIE/copie_dialog.py.bak
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+"""
+/***************************************************************************
+ CopieDialog
+ A QGIS plugin
+ Permet la copie d'une table dans une base PostGis
+ -------------------
+ begin : 2015-04-13
+ git sha : $Format:%H$
+ copyright : (C) 2015 by Guillaume COSTES - CEN Rhône-Alpes
+ 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. *
+ * *
+ ***************************************************************************/
+"""
+
+import os
+
+from PyQt4 import QtGui, uic
+
+FORM_CLASS, _ = uic.loadUiType(os.path.join(
+ os.path.dirname(__file__), 'copie_dialog_base.ui'))
+
+
+class CopieDialog(QtGui.QDialog, FORM_CLASS):
+ def __init__(self, parent=None):
+ """Constructor."""
+ super(CopieDialog, self).__init__(parent)
+ # Set up the user interface from Designer.
+ # After setupUI you can access any designer object by doing
+ # self.
+Your QGIS plugin directory is located at:
+ C:/Users/Romain/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins
+
+
+For information on writing PyQGIS code, see http://loc8.cc/pyqgis_resources for a list of resources. +
++©2011-2019 GeoApt LLC - geoapt.com +
+ + diff --git a/CenRa_FLUX/README.txt b/CenRa_FLUX/README.txt new file mode 100644 index 00000000..278f7be6 --- /dev/null +++ b/CenRa_FLUX/README.txt @@ -0,0 +1,32 @@ +Plugin Builder Results + +Your plugin FluxCEN was created in: + C:\Users\Romain\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\fluxcen + +Your QGIS plugin directory is located at: + C:/Users/Romain/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins + +What's Next: + + * Copy the entire directory containing your new plugin to the QGIS plugin + directory + + * Compile the resources file using pyrcc5 + + * Run the tests (``make test``) + + * Test the plugin by enabling it in the QGIS plugin manager + + * Customize it by editing the implementation file: ``FluxCEN.py`` + + * Create your own custom icon, replacing the default icon.png + + * Modify your user interface by opening FluxCEN_dialog_base.ui in Qt Designer + + * You can use the Makefile to compile your Ui and resource files when + you make changes. This requires GNU make (gmake) + +For more information, see the PyQGIS Developer Cookbook at: +http://www.qgis.org/pyqgis-cookbook/index.html + +(C) 2011-2018 GeoApt LLC - geoapt.com diff --git a/CenRa_FLUX/forms/about_form.py b/CenRa_FLUX/forms/about_form.py new file mode 100644 index 00000000..131749a2 --- /dev/null +++ b/CenRa_FLUX/forms/about_form.py @@ -0,0 +1,46 @@ +import os.path + +from pathlib import Path + +from qgis.PyQt import uic +from qgis.PyQt.QtGui import QPixmap +from qgis.PyQt.QtWidgets import QDialog + +from ..tools.resources import devlog + +ABOUT_FORM_CLASS, _ = uic.loadUiType( + os.path.join( + str(Path(__file__).resolve().parent.parent), + 'forms', + 'flux_about_form.ui' + ) +) + + +class FluxAboutDialog(QDialog, ABOUT_FORM_CLASS): + + """ About - Let the user display the about dialog. """ + + def __init__(self, iface, parent=None): + super().__init__(parent) + self.iface = iface + self.setupUi(self) + + self.viewer.setHtml(devlog('CenRa_FLUX')) + + self.rejected.connect(self.onReject) + self.buttonBox.rejected.connect(self.onReject) + self.buttonBox.accepted.connect(self.onAccept) + + def onAccept(self): + """ + Save options when pressing OK button + """ + self.accept() + + def onReject(self): + """ + Run some actions when + the user closes the dialog + """ + self.close() \ No newline at end of file diff --git a/CenRa_FLUX/forms/flux_about_form.ui b/CenRa_FLUX/forms/flux_about_form.ui new file mode 100644 index 00000000..1c65e2a6 --- /dev/null +++ b/CenRa_FLUX/forms/flux_about_form.ui @@ -0,0 +1,96 @@ + +
+
+ Pas de métadonnées encore associées à cette ressource ! Revenez plus tard 😎
+ + diff --git a/CenRa_FLUX/pb_tool.cfg b/CenRa_FLUX/pb_tool.cfg new file mode 100644 index 00000000..63383310 --- /dev/null +++ b/CenRa_FLUX/pb_tool.cfg @@ -0,0 +1,80 @@ +#/*************************************************************************** +# FluxCEN +# +# Configuration file for plugin builder tool (pb_tool) +# Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ +# ------------------- +# begin : 2022-04-04 +# copyright : (C) 2022 by Romain Montillet +# email : r.montillet@cen-na.org +# ***************************************************************************/ +# +#/*************************************************************************** +# * * +# * 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. * +# * * +# ***************************************************************************/ +# +# +# You can install pb_tool using: +# pip install http://geoapt.net/files/pb_tool.zip +# +# Consider doing your development (and install of pb_tool) in a virtualenv. +# +# For details on setting up and using pb_tool, see: +# http://g-sherman.github.io/plugin_build_tool/ +# +# Issues and pull requests here: +# https://github.com/g-sherman/plugin_build_tool: +# +# Sane defaults for your plugin generated by the Plugin Builder are +# already set below. +# +# As you add Python source files and UI files to your plugin, add +# them to the appropriate [files] section below. + +[plugin] +# Name of the plugin. This is the name of the directory that will +# be created in .qgis2/python/plugins +name: FluxCEN + +# Full path to where you want your plugin directory copied. If empty, +# the QGIS default path will be used. Don't include the plugin name in +# the path. +plugin_path: + +[files] +# Python files that should be deployed with the plugin +python_files: __init__.py FluxCEN.py FluxCEN_dialog.py + +# The main dialog file that is loaded (not compiled) +main_dialog: FluxCEN_dialog_base.ui + +# Other ui files for dialogs you create (these will be compiled) +compiled_ui_files: + +# Resource file(s) that will be compiled +resource_files: resources.qrc + +# Other files required for the plugin +extras: metadata.txt icon.png + +# Other directories to be deployed with the plugin. +# These must be subdirectories under the plugin directory +extra_dirs: + +# ISO code(s) for any locales (translations), separated by spaces. +# Corresponding .ts files must exist in the i18n directory +locales: + +[help] +# the built help directory that should be deployed with the plugin +dir: help/build/html +# the name of the directory to target in the deployed plugin +target: help + + + diff --git a/CenRa_FLUX/pylintrc b/CenRa_FLUX/pylintrc new file mode 100644 index 00000000..7e168f64 --- /dev/null +++ b/CenRa_FLUX/pylintrc @@ -0,0 +1,281 @@ +[MASTER] + +# Specify a configuration file. +#rcfile= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Profiled execution. +profile=no + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=CVS + +# Pickle collected data for later comparisons. +persistent=yes + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + + +[MESSAGES CONTROL] + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time. See also the "--disable" option for examples. +#enable= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once).You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use"--disable=all --enable=classes +# --disable=W" +# see http://stackoverflow.com/questions/21487025/pylint-locally-defined-disables-still-give-warnings-how-to-suppress-them +disable=locally-disabled,C0103 + + +[REPORTS] + +# Set the output format. Available formats are text, parseable, colorized, msvs +# (visual studio) and html. You can also give a reporter class, eg +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Put messages in a separate file for each module / package specified on the +# command line instead of printing them on stdout. Reports (if any) will be +# written in a file name "pylint_global.[txt|html]". +files-output=no + +# Tells whether to display a full report or only the messages +reports=yes + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Add a comment according to your evaluation note. This is used by the global +# evaluation report (RP0004). +comment=no + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details +#msg-template= + + +[BASIC] + +# Required attributes for module, separated by a comma +required-attributes= + +# List of builtins function names that should not be used, separated by a comma +bad-functions=map,filter,apply,input + +# Regular expression which should only match correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Regular expression which should only match correct module level names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Regular expression which should only match correct class names +class-rgx=[A-Z_][a-zA-Z0-9]+$ + +# Regular expression which should only match correct function names +function-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct method names +method-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct instance attribute names +attr-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct argument names +argument-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct variable names +variable-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Regular expression which should only match correct attribute names in class +# bodies +class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Regular expression which should only match correct list comprehension / +# generator expression variable names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Good variable names which should always be accepted, separated by a comma +good-names=i,j,k,ex,Run,_ + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo,bar,baz,toto,tutu,tata + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=__.*__ + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME,XXX,TODO + + +[TYPECHECK] + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# List of classes names for which member attributes should not be checked +# (useful for classes with attributes dynamically set). +ignored-classes=SQLObject + +# When zope mode is activated, add a predefined set of Zope acquired attributes +# to generated-members. +zope=no + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E0201 when accessed. Python regular +# expressions are accepted. +generated-members=REQUEST,acl_users,aq_parent + + +[VARIABLES] + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# A regular expression matching the beginning of the name of dummy variables +# (i.e. not used). +dummy-variables-rgx=_$|dummy + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + + +[FORMAT] + +# Maximum number of characters on a single line. +max-line-length=80 + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + +# List of optional constructs for which whitespace checking is disabled +no-space-check=trailing-comma,dict-separator + +# Maximum number of lines in a module +max-module-lines=1000 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + + +[SIMILARITIES] + +# Minimum lines number of a similarity. +min-similarity-lines=4 + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + + +[IMPORTS] + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=regsub,TERMIOS,Bastion,rexec + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=5 + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.* + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of branch for function / method body +max-branches=12 + +# Maximum number of statements in function / method body +max-statements=50 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + + +[CLASSES] + +# List of interface methods to ignore, separated by a comma. This is used for +# instance to not check methods defines in Zope's Interface base class. +ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__,__new__,setUp + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=Exception diff --git a/CenRa_FLUX/scripts/compile-strings.sh b/CenRa_FLUX/scripts/compile-strings.sh new file mode 100644 index 00000000..9d760831 --- /dev/null +++ b/CenRa_FLUX/scripts/compile-strings.sh @@ -0,0 +1,12 @@ +#!/bin/bash +LRELEASE=$1 +LOCALES=$2 + + +for LOCALE in ${LOCALES} +do + echo "Processing: ${LOCALE}.ts" + # Note we don't use pylupdate with qt .pro file approach as it is flakey + # about what is made available. + $LRELEASE i18n/${LOCALE}.ts +done diff --git a/CenRa_FLUX/scripts/run-env-linux.sh b/CenRa_FLUX/scripts/run-env-linux.sh new file mode 100644 index 00000000..668247c5 --- /dev/null +++ b/CenRa_FLUX/scripts/run-env-linux.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +QGIS_PREFIX_PATH=/usr/local/qgis-2.0 +if [ -n "$1" ]; then + QGIS_PREFIX_PATH=$1 +fi + +echo ${QGIS_PREFIX_PATH} + + +export QGIS_PREFIX_PATH=${QGIS_PREFIX_PATH} +export QGIS_PATH=${QGIS_PREFIX_PATH} +export LD_LIBRARY_PATH=${QGIS_PREFIX_PATH}/lib +export PYTHONPATH=${QGIS_PREFIX_PATH}/share/qgis/python:${QGIS_PREFIX_PATH}/share/qgis/python/plugins:${PYTHONPATH} + +echo "QGIS PATH: $QGIS_PREFIX_PATH" +export QGIS_DEBUG=0 +export QGIS_LOG_FILE=/tmp/inasafe/realtime/logs/qgis.log + +export PATH=${QGIS_PREFIX_PATH}/bin:$PATH + +echo "This script is intended to be sourced to set up your shell to" +echo "use a QGIS 2.0 built in $QGIS_PREFIX_PATH" +echo +echo "To use it do:" +echo "source $BASH_SOURCE /your/optional/install/path" +echo +echo "Then use the make file supplied here e.g. make guitest" diff --git a/CenRa_FLUX/scripts/update-strings.sh b/CenRa_FLUX/scripts/update-strings.sh new file mode 100644 index 00000000..a31f7124 --- /dev/null +++ b/CenRa_FLUX/scripts/update-strings.sh @@ -0,0 +1,56 @@ +#!/bin/bash +LOCALES=$* + +# Get newest .py files so we don't update strings unnecessarily + +CHANGED_FILES=0 +PYTHON_FILES=`find . -regex ".*\(ui\|py\)$" -type f` +for PYTHON_FILE in $PYTHON_FILES +do + CHANGED=$(stat -c %Y $PYTHON_FILE) + if [ ${CHANGED} -gt ${CHANGED_FILES} ] + then + CHANGED_FILES=${CHANGED} + fi +done + +# Qt translation stuff +# for .ts file +UPDATE=false +for LOCALE in ${LOCALES} +do + TRANSLATION_FILE="i18n/$LOCALE.ts" + if [ ! -f ${TRANSLATION_FILE} ] + then + # Force translation string collection as we have a new language file + touch ${TRANSLATION_FILE} + UPDATE=true + break + fi + + MODIFICATION_TIME=$(stat -c %Y ${TRANSLATION_FILE}) + if [ ${CHANGED_FILES} -gt ${MODIFICATION_TIME} ] + then + # Force translation string collection as a .py file has been updated + UPDATE=true + break + fi +done + +if [ ${UPDATE} == true ] +# retrieve all python files +then + echo ${PYTHON_FILES} + # update .ts + echo "Please provide translations by editing the translation files below:" + for LOCALE in ${LOCALES} + do + echo "i18n/"${LOCALE}".ts" + # Note we don't use pylupdate with qt .pro file approach as it is flakey + # about what is made available. + pylupdate4 -noobsolete ${PYTHON_FILES} -ts i18n/${LOCALE}.ts + done +else + echo "No need to edit any translation files (.ts) because no python files" + echo "has been updated since the last update translation. " +fi diff --git a/CenRa_FLUX/styles_couches/RNN.qml b/CenRa_FLUX/styles_couches/RNN.qml new file mode 100644 index 00000000..3e22d491 --- /dev/null +++ b/CenRa_FLUX/styles_couches/RNN.qml @@ -0,0 +1,321 @@ + +| Title | [% title %] | +
|---|---|
| Abstract | [% abstract %] | +
| Categories | [% categories %] | +
| Themes | [% themes %] | +
| Keywords | [% keywords %] | +
| Data last update | [% data_last_update %] | +
| Level | [% spatial_level %] | +
|---|---|
| Minimum scale | [% minimum_optimal_scale %] | +
| Maximum scale | [% maximum_optimal_scale %] | +
| Feature count | [% feature_count %] | +
| Geometry | [% geometry_type %] | +
| Extent | [% spatial_extent %] | +
| Projection name | [% projection_name %] | +
| Projection ID | [% projection_authid %] | +
| Date | [% publication_date %] | +
|---|---|
| Frequency | [% publication_frequency %] | +
| License | [% license %] | +
| License attribution / number | [% license_attribution %] | +
| Confidentiality | [% confidentiality %] | +
| Type | +Name | +MIME | +Format | +Size | +
|---|
| Role | +Name | +Organisation | +Phone | +
|---|
| Table | [% table_name %] | +
|---|---|
| Schema | [% schema_name %] | +
| Creation | [% creation_date %] | +
| Update | [% update_date %] | +
| UUID | [% uid %] | +
+Your QGIS plugin directory is located at:
+ C:/Users/gcostes/.qgis2/python/plugins
+
+What's Next +
+For more information, see the PyQGIS Developer Cookbook at: +http://www.qgis.org/pyqgis-cookbook/index.html. +
+
+©2011-2014 GeoApt LLC - geoapt.com
+
+
diff --git a/CenRa_POSTGIS/__init__.py.bak b/CenRa_POSTGIS/__init__.py.bak
new file mode 100644
index 00000000..a1de1556
--- /dev/null
+++ b/CenRa_POSTGIS/__init__.py.bak
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+"""
+/***************************************************************************
+ CenRa
+ A QGIS plugin
+ Conservatoire d'Espaces Naturels de Rhône-Alpes
+ -------------------
+ begin : 2014-03-27
+ copyright : (C) 2014 by Conservatoire d'Espaces Naturels de Rhône-Alpes
+ 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. *
+ * *
+ ***************************************************************************/
+ This script initializes the plugin, making it known to QGIS.
+"""
+
+def classFactory(iface):
+ # load CenRa class from file CenRa
+ from cenra import CenRa
+ return CenRa(iface)
diff --git a/CenRa_POSTGIS/cenra.py.bak b/CenRa_POSTGIS/cenra.py.bak
new file mode 100644
index 00000000..0812e5ef
--- /dev/null
+++ b/CenRa_POSTGIS/cenra.py.bak
@@ -0,0 +1,798 @@
+# -*- coding: utf-8 -*-
+"""
+/***************************************************************************
+ CenRa
+ A QGIS plugin
+ Conservatoire d'Espaces Naturels de Rhône-Alpes
+ -------------------
+ begin : 2014-03-27
+ copyright : (C) 2014 by Conservatoire d'Espaces Naturels de Rhône-Alpes
+ 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 qgis.PyQt.QtCore import QSettings
+from qgis.PyQt.QtWidgets import QAction, QMenu
+from qgis.PyQt.QtGui import QIcon
+from qgis.core import *
+# Initialize Qt resources from file resources.py
+from . import resources_rc
+# Import the code for the dialog
+from .cenradialog import CenRaDialog
+from .table_postgisdialog import table_postgisDialog
+
+import os.path
+import webbrowser, os
+import sys
+import psycopg2
+
+class CenRa(object):
+
+ def __init__(self, iface):
+ # Save reference to the QGIS interface
+ self.iface = iface
+ # initialize plugin directory
+ self.plugin_dir = os.path.dirname(__file__)
+ # initialize locale
+ locale = QSettings().value("locale/userLocale")[0:2]
+ localePath = os.path.join(self.plugin_dir, 'i18n', 'cenra_{}.qm'.format(locale))
+
+ if os.path.exists(localePath):
+ self.translator = QTranslator()
+ self.translator.load(localePath)
+
+ if qVersion() > '4.3.3':
+ QCoreApplication.installTranslator(self.translator)
+
+ # Create the dialog (after translation) and keep reference
+ self.dlg = CenRaDialog()
+ self.dlgAjout = table_postgisDialog()
+
+ def initGui(self):
+ self.toolBar = self.iface.addToolBar("CEN-RA")
+ self.toolBar.setObjectName("CEN-RA")
+
+ # ***Create action that will start plugin configuration
+ self.action = QAction(
+ QIcon(":/plugins/CenRa/page_new.png"),
+ u"Création d'un dossier", self.iface.mainWindow())
+ # connect the action to the run method
+ self.action.triggered.connect(self.creation)
+
+ # Add toolbar button and menu item
+ self.toolBar.addAction(self.action)
+ self.iface.addPluginToMenu(u"CenRa", self.action)
+
+ # ***Create action that will start plugin configuration
+ self.action = QAction(
+ QIcon(":/plugins/CenRa/page_ajout.png"),
+ u"Ajout d'une table", self.iface.mainWindow())
+ # connect the action to the run method
+ self.action.triggered.connect(self.ajout)
+
+ # Add toolbar button and menu item
+ self.toolBar.addAction(self.action)
+ self.iface.addPluginToMenu(u"&CenRa", self.action)
+
+ # ***Create action that will start plugin configuration
+ self.action = QAction(
+ QIcon(":/plugins/CenRa/help.png"),
+ u"Aide", self.iface.mainWindow())
+ # connect the action to the run method
+ self.action.triggered.connect(self.doHelp)
+
+ # Add toolbar button and menu item
+ self.toolBar.addAction(self.action)
+ self.iface.addPluginToMenu(u"CenRa", self.action)
+
+ self.menu = QMenu()
+ self.menu.setTitle( QCoreApplication.translate( "CENRA","&CenRa" ) )
+
+ self.cenra_new = QAction( QIcon(":/plugins/CenRa/page_new.png"), QCoreApplication.translate("CENRA", u"Création d'un dossier" ), self.iface.mainWindow() )
+ self.cenra_ajout = QAction( QIcon(":/plugins/CenRa/page_ajout.png"), QCoreApplication.translate("CENRA", "Ajout d'une table" ), self.iface.mainWindow() )
+ self.cenra_help = QAction( QIcon(":/plugins/CenRa/help.png"), QCoreApplication.translate("CENRA", "Aide" ), self.iface.mainWindow() )
+
+ self.menu.addActions( [self.cenra_new, self.cenra_ajout, self.cenra_help] )
+
+ menu_bar = self.iface.mainWindow().menuBar()
+ actions = menu_bar.actions()
+ lastAction = actions[ len( actions ) - 1 ]
+ menu_bar.insertMenu( lastAction, self.menu )
+
+ self.cenra_new.triggered.connect(self.creation)
+ self.cenra_ajout.triggered.connect(self.ajout)
+ self.cenra_help.triggered.connect(self.doHelp)
+
+ def unload(self):
+ # Remove the plugin menu item and icon
+ self.iface.removePluginMenu(u"&CenRa", self.action)
+ self.iface.removeToolBarIcon(self.action)
+
+ # run method that performs all the real work
+ def creation(self):
+ # show the dialog
+ self.dlg.show()
+ # Run the dialog event loop
+ result = self.dlg.exec_()
+ # See if OK was pressed
+ if result == 1:
+
+#**********************************Debut_script****************************************
+ import psycopg2
+
+ ### config.txt
+ config = "//100.100.100.100/bd_sig/z_QGIS/config.txt" # Chemin du fichier config
+
+ # Fonction de lecture des lignes du fichier config
+ def readline(n):
+ with open(config, "r") as f:
+ for lineno, line in enumerate(f):
+ if lineno == n:
+ return line.strip() # Permet d'enlever les retours chariots
+
+ # Recuperation des donnees
+ host = readline(10)
+ port = readline(12)
+ dbname = readline(14)
+ user = readline(16)
+ password = readline(18)
+
+ ### Creation du schema pour le nouveau site
+ if self.dlg.at.isChecked():
+ schema = "_" + self.dlg.dept.currentText() + "_at_" + self.dlg.nom.text().lower() # Ajout de "_" pour eviter pb de numero en premier caractere
+ else :
+ schema = "_" + self.dlg.dept.currentText() + "_" + self.dlg.nom.text().lower() # Ajout de "_" pour eviter pb de numero en premier caractere
+
+ if self.dlg.nom.text() == "" or self.dlg.nom.text() == "NULL":
+ QMessageBox.warning(None, "Oups :", "Veuillez renseigner un nom de dossier.")
+ return
+
+ ch = [u"à", u"À", u"â", u"Â", u"ä", u"Ä", u"å", u"Å", u"ç", u"Ç", u"é", u"É", u"è", u"È", u"ê", u"Ê", u"ë", u"Ë", u"î", u"Î", u"ï", u"Ï", u"ô", u"Ô", u"ö", u"Ö", u"ù", u"Ù", u"û", u"Û", u"ü", u"Ü", u"ÿ", u"Ÿ", u"'", u"-", u" "]
+ for car in ch :
+ if self.dlg.nom.text().find(car) != -1 :
+ QMessageBox.warning(None, "Oups :", u"Le nom de dossier ne doit pas comporter de caractères spéciaux, ni d'espaces !\n\n\t" + self.dlg.nom.text().lower() )
+ return
+
+ con = psycopg2.connect("dbname="+ dbname + " user=" + user + " host=" + host + " password=" + password)
+ cur = con.cursor()
+
+ SQL_schema = "CREATE SCHEMA " + schema + " AUTHORIZATION postgres;"
+
+ cur.execute(SQL_schema)
+
+ ### Creation de la table contour
+ if self.dlg.couche_contour.isChecked(): # Verifie si la checkbox est cochee
+ if self.dlg.annee_1.text() == 'aaaa' or self.dlg.annee_1.text() == '':
+ tablename = schema + "_contour"
+ else :
+ tablename = schema + "_contour_" + self.dlg.annee_1.text()
+ tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
+ geom = readline(6)
+ style = readline(21)
+ champ_contour = readline(32)
+
+ SQL_contour = "CREATE TABLE " + schema + "."+ tablename + champ_contour
+ SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
+ SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
+ SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
+ SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
+ SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
+
+ SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
+ SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
+ FROM layer_styles
+ WHERE description = 'contour_modele'"""
+
+ cur.execute(SQL_contour)
+ cur.execute(SQL_pkey)
+ cur.execute(SQL_trigger_area_m2)
+ cur.execute(SQL_trigger_area_ha)
+ cur.execute(SQL_trigger_date_creation)
+ cur.execute(SQL_trigger_date_maj)
+ cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
+
+ con.commit()
+
+ ## Affichage de la table
+ uri = QgsDataSourceURI()
+ # set host name, port, database name, username and password
+ uri.setConnection(host ,port ,dbname ,user ,password)
+ # set database schema, table name, geometry column and optionaly subset (WHERE clause)
+ uri.setDataSource(schema, tablename, geom)
+
+ layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
+
+ ### Creation de la table habitat
+ if self.dlg.couche_habitat.isChecked():
+ if self.dlg.annee_2.text() == 'aaaa' or self.dlg.annee_2.text() == '':
+ tablename = schema + "_habitat"
+ else :
+ tablename = schema + "_habitat_" + self.dlg.annee_2.text()
+ tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
+ geom = readline(6)
+ style = readline(22)
+ champ_habitat = readline(35)
+
+ SQL_habitat = "CREATE TABLE " + schema + "."+ tablename + champ_habitat
+ SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
+ SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
+ SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
+ SQL_trigger_concat_cd_cb = "CREATE TRIGGER concat_cd_cb" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.concat_cd_cb();"
+ SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
+ SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
+
+ SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
+ SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
+ FROM layer_styles
+ WHERE description = 'habitat_modele'"""
+
+ cur.execute(SQL_habitat)
+ cur.execute(SQL_pkey)
+ cur.execute(SQL_trigger_area_m2)
+ cur.execute(SQL_trigger_area_ha)
+ cur.execute(SQL_trigger_concat_cd_cb)
+ cur.execute(SQL_trigger_date_creation)
+ cur.execute(SQL_trigger_date_maj)
+ cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
+
+ con.commit()
+
+ ## Affichage de la table
+ uri = QgsDataSourceURI()
+ # set host name, port, database name, username and password
+ uri.setConnection(host ,port ,dbname ,user ,password)
+ # set database schema, table name, geometry column and optionaly subset (WHERE clause)
+ uri.setDataSource(schema, tablename, geom)
+
+ layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
+
+ ### Creation de la table travaux prevus
+ if self.dlg.couche_travaux_prevus.isChecked():
+ #**********Poly
+ if self.dlg.annee_5.text() == 'aaaa' or self.dlg.annee_5.text() == '':
+ tablename = schema + "_travaux_prevus_poly"
+ else :
+ tablename = schema + "_travaux_prevus_poly_" + self.dlg.annee_5.text()
+ tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
+ geom = readline(6)
+ style = readline(26)
+ champ_travaux_prevus = readline(43)
+
+ SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus
+ SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
+ SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
+ SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
+ SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
+ SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
+
+ SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
+ SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
+ FROM layer_styles
+ WHERE description = 'travaux_prevus_poly_modele'"""
+
+ cur.execute(SQL_travaux_prevus)
+ cur.execute(SQL_pkey)
+ cur.execute(SQL_trigger_date_creation)
+ cur.execute(SQL_trigger_date_maj)
+ cur.execute(SQL_trigger_area_m2)
+ cur.execute(SQL_trigger_area_ha)
+ cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
+
+ con.commit()
+
+ ## Affichage de la table
+ uri = QgsDataSourceURI()
+ # set host name, port, database name, username and password
+ uri.setConnection(host ,port ,dbname ,user ,password)
+ # set database schema, table name, geometry column and optionaly subset (WHERE clause)
+ uri.setDataSource(schema, tablename, geom)
+
+ layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
+
+ #**********ligne
+ if self.dlg.annee_5.text() == 'aaaa' or self.dlg.annee_5.text() == '':
+ tablename = schema + "_travaux_prevus_ligne"
+ else :
+ tablename = schema + "_travaux_prevus_ligne_" + self.dlg.annee_5.text()
+ tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
+ geom = readline(6)
+ style = readline(27)
+ champ_travaux_prevus = readline(44)
+
+ SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus
+ SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
+ SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
+ SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
+ SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
+ SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
+
+ SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
+ SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
+ FROM layer_styles
+ WHERE description = 'travaux_prevus_ligne_modele'"""
+
+ cur.execute(SQL_travaux_prevus)
+ cur.execute(SQL_pkey)
+ cur.execute(SQL_trigger_date_creation)
+ cur.execute(SQL_trigger_date_maj)
+ cur.execute(SQL_trigger_length_m)
+ cur.execute(SQL_trigger_length_km)
+ cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
+
+ con.commit()
+
+ ## Affichage de la table
+ uri = QgsDataSourceURI()
+ # set host name, port, database name, username and password
+ uri.setConnection(host ,port ,dbname ,user ,password)
+ # set database schema, table name, geometry column and optionaly subset (WHERE clause)
+ uri.setDataSource(schema, tablename, geom)
+
+ layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
+
+ #**********point
+ if self.dlg.annee_5.text() == 'aaaa' or self.dlg.annee_5.text() == '':
+ tablename = schema + "_travaux_prevus_point"
+ else :
+ tablename = schema + "_travaux_prevus_point_" + self.dlg.annee_5.text()
+ tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
+ geom = readline(6)
+ style = readline(28)
+ champ_travaux_prevus = readline(45)
+
+ SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus
+ SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
+ SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
+ SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
+ SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
+
+ SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
+ SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
+ FROM layer_styles
+ WHERE description = 'travaux_prevus_point_modele'"""
+
+ cur.execute(SQL_travaux_prevus)
+ cur.execute(SQL_pkey)
+ cur.execute(SQL_trigger_date_creation)
+ cur.execute(SQL_trigger_date_maj)
+ cur.execute(SQL_trigger_coordonnees)
+ cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
+
+ con.commit()
+
+ ## Affichage de la table
+ uri = QgsDataSourceURI()
+ # set host name, port, database name, username and password
+ uri.setConnection(host ,port ,dbname ,user ,password)
+ # set database schema, table name, geometry column and optionaly subset (WHERE clause)
+ uri.setDataSource(schema, tablename, geom)
+
+ layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
+
+ ### Creation de la table vierge
+ if self.dlg.couche_vierge.isChecked():
+ if self.dlg.annee_4.text() == 'aaaa' or self.dlg.annee_4.text() == '':
+ tablename = schema + "_" + self.dlg.nom_couche_vierge.text().lower()
+ else :
+ tablename = schema + "_" + self.dlg.nom_couche_vierge.text().lower() + "_" + self.dlg.annee_4.text()
+ tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
+ geom = readline(6)
+ style = readline(29)
+ champ_viergePolygone = readline(48)
+ champ_viergeLigne = readline(49)
+ champ_viergePoint = readline(50)
+
+ if self.dlg.couche_vierge_point.isChecked() == 1 :
+ champ_vierge = champ_viergePoint
+
+ if self.dlg.couche_vierge_ligne.isChecked() == 1 :
+ champ_vierge = champ_viergeLigne
+
+ if self.dlg.couche_vierge_polygone.isChecked() == 1 :
+ champ_vierge = champ_viergePolygone
+
+ SQL_vierge = "CREATE TABLE " + schema + "."+ tablename + champ_vierge
+ SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
+
+ SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
+ SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
+ SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
+ SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
+ SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
+
+ cur.execute(SQL_vierge)
+ cur.execute(SQL_pkey)
+
+ if self.dlg.couche_vierge_point.isChecked() == 1 :
+ cur.execute(SQL_trigger_coordonnees)
+
+ if self.dlg.couche_vierge_ligne.isChecked() == 1 :
+ cur.execute(SQL_trigger_length_m)
+ cur.execute(SQL_trigger_length_km)
+
+ if self.dlg.couche_vierge_polygone.isChecked() == 1 :
+ cur.execute(SQL_trigger_area_m2)
+ cur.execute(SQL_trigger_area_ha)
+
+ con.commit()
+
+ ### Affichage de la table
+ uri = QgsDataSourceURI()
+ # set host name, port, database name, username and password
+ uri.setConnection(host ,port ,dbname ,user ,password)
+ # set database schema, table name, geometry column and optionaly subset (WHERE clause)
+ uri.setDataSource(schema, tablename, geom)
+
+ layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
+
+ else :
+ con.commit()
+
+ con.close()
+ pass
+
+ ### Outil Aide
+ def doHelp(self):
+ webbrowser.open("http://plateformesig.cenra-outils.org/")
+
+ ### Outil Ajout de nouvelles couche a un dossier
+ def ajout(self):
+ import psycopg2
+
+ config = "//100.100.100.100/bd_sig/z_QGIS/config.txt" # Chemin du fichier config
+ # Fonction de lecture des lignes du fichier config
+ def readline(n):
+ with open(config, "r") as f:
+ for lineno, line in enumerate(f):
+ if lineno == n:
+ return line.strip() # Permet d'enlever les retours chariots
+
+ host = readline(10)
+ port = readline(12)
+ dbname = readline(14)
+ user = readline(16)
+ password = readline(18)
+
+ con = psycopg2.connect("dbname="+ dbname + " user=" + user + " host=" + host + " password=" + password)
+ cur = con.cursor()
+ # Creation de la liste des schemas de la base de donnees
+ SQL = """WITH list_schema AS (
+ SELECT catalog_name, schema_name
+ FROM information_schema.schemata
+ WHERE schema_name <> 'information_schema'
+ AND schema_name !~ E'^pg_'
+ ORDER BY schema_name
+ )
+
+ SELECT string_agg(schema_name,',')
+ FROM list_schema
+ GROUP BY catalog_name"""
+
+ cur.execute(SQL)
+
+ list_brut = str(next(cur))
+
+ list = list_brut [3:-3]
+ listItems = list.split(",")
+
+ con.close()
+
+ self.dlgAjout.ui.schema.clear()
+ self.dlgAjout.ui.schema.addItems(listItems)
+ self.dlgAjout.ui.schema.setCurrentIndex(-1) # Pour ne pas commencer la liste au premier schema
+
+ # show the dialog
+ self.dlgAjout.show()
+ # Run the dialog event loop
+ result = self.dlgAjout.exec_()
+ # See if OK was pressed
+ if result == 1:
+#******************************debut script*********************************
+ ### config.txt
+ config = "//100.100.100.100/bd_sig/z_QGIS/config.txt" # Chemin du fichier config
+
+ # Fonction de lecture des lignes du fichier config
+ def readline(n):
+ with open(config, "r") as f:
+ for lineno, line in enumerate(f):
+ if lineno == n:
+ return line.strip() # Permet d'enlever les retours chariots
+
+ # Recuperation des donnees
+ host = readline(10)
+ port = readline(12)
+ dbname = readline(14)
+ user = readline(16)
+ password = readline(18)
+
+ con = psycopg2.connect("dbname="+ dbname + " user=" + user + " host=" + host + " password=" + password)
+ cur = con.cursor()
+
+ if self.dlgAjout.ui.schema.currentIndex() == -1 :
+ QMessageBox.warning(None, "Oups :", "Veuillez choisir un nom de dossier.")
+ return
+
+ schema = self.dlgAjout.ui.schema.currentText()
+
+ ### Creation de la table contour
+ if self.dlgAjout.ui.couche_contour.isChecked(): # Verifie si la checkbox est cochee
+ if self.dlgAjout.ui.annee_1.text() == 'aaaa' or self.dlgAjout.ui.annee_1.text() == '':
+ tablename = schema + "_contour"
+ else :
+ tablename = schema + "_contour_" + self.dlgAjout.ui.annee_1.text()
+ tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
+ geom = readline(6)
+ style = readline(21)
+ champ_contour = readline(32)
+
+ SQL_contour = "CREATE TABLE " + schema + "."+ tablename + champ_contour
+ SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
+ SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
+ SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
+ SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
+ SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
+
+ SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
+ SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
+ FROM layer_styles
+ WHERE description = 'contour_modele'"""
+
+ cur.execute(SQL_contour)
+ cur.execute(SQL_pkey)
+ cur.execute(SQL_trigger_area_m2)
+ cur.execute(SQL_trigger_area_ha)
+ cur.execute(SQL_trigger_date_creation)
+ cur.execute(SQL_trigger_date_maj)
+ cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
+
+ con.commit()
+
+ ## Affichage de la table
+ uri = QgsDataSourceURI()
+ # set host name, port, database name, username and password
+ uri.setConnection(host ,port ,dbname ,user ,password)
+ # set database schema, table name, geometry column and optionaly subset (WHERE clause)
+ uri.setDataSource(schema, tablename, geom)
+
+ layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
+
+ ### Creation de la table habitat
+ if self.dlgAjout.ui.couche_habitat.isChecked():
+ if self.dlgAjout.ui.annee_2.text() == 'aaaa' or self.dlgAjout.ui.annee_2.text() == '':
+ tablename = schema + "_habitat"
+ else :
+ tablename = schema + "_habitat_" + self.dlgAjout.ui.annee_2.text()
+ tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
+ geom = readline(6)
+ style = readline(22)
+ champ_habitat = readline(35)
+
+ SQL_habitat = "CREATE TABLE " + schema + "."+ tablename + champ_habitat
+ SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
+ SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
+ SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
+ SQL_trigger_concat_cd_cb = "CREATE TRIGGER concat_cd_cb" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.concat_cd_cb();"
+ SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
+ SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
+
+ SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
+ SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
+ FROM layer_styles
+ WHERE description = 'habitat_modele'"""
+
+ cur.execute(SQL_habitat)
+ cur.execute(SQL_pkey)
+ cur.execute(SQL_trigger_area_m2)
+ cur.execute(SQL_trigger_area_ha)
+ cur.execute(SQL_trigger_concat_cd_cb)
+ cur.execute(SQL_trigger_date_creation)
+ cur.execute(SQL_trigger_date_maj)
+ cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
+
+ con.commit()
+
+ ## Affichage de la table
+ uri = QgsDataSourceURI()
+ # set host name, port, database name, username and password
+ uri.setConnection(host ,port ,dbname ,user ,password)
+ # set database schema, table name, geometry column and optionaly subset (WHERE clause)
+ uri.setDataSource(schema, tablename, geom)
+
+ layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
+
+ ### Creation de la table travaux prevus
+ if self.dlgAjout.ui.couche_travaux_prevus.isChecked():
+ #**********Poly
+ if self.dlgAjout.ui.annee_5.text() == 'aaaa' or self.dlgAjout.ui.annee_5.text() == '':
+ tablename = schema + "_travaux_prevus_poly"
+ else :
+ tablename = schema + "_travaux_prevus_poly_" + self.dlgAjout.ui.annee_5.text()
+ tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
+ geom = readline(6)
+ style = readline(26)
+ champ_travaux_prevus = readline(43)
+
+ SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus
+ SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
+ SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
+ SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
+ SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
+ SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
+
+ SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
+ SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
+ FROM layer_styles
+ WHERE description = 'travaux_prevus_poly_modele'"""
+
+ cur.execute(SQL_travaux_prevus)
+ cur.execute(SQL_pkey)
+ cur.execute(SQL_trigger_date_creation)
+ cur.execute(SQL_trigger_date_maj)
+ cur.execute(SQL_trigger_area_m2)
+ cur.execute(SQL_trigger_area_ha)
+ cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
+
+ con.commit()
+
+ ## Affichage de la table
+ uri = QgsDataSourceURI()
+ # set host name, port, database name, username and password
+ uri.setConnection(host ,port ,dbname ,user ,password)
+ # set database schema, table name, geometry column and optionaly subset (WHERE clause)
+ uri.setDataSource(schema, tablename, geom)
+
+ layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
+
+ #**********ligne
+ if self.dlgAjout.ui.annee_5.text() == 'aaaa' or self.dlgAjout.ui.annee_5.text() == '':
+ tablename = schema + "_travaux_prevus_ligne"
+ else :
+ tablename = schema + "_travaux_prevus_ligne_" + self.dlgAjout.ui.annee_5.text()
+ tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
+ geom = readline(6)
+ style = readline(27)
+ champ_travaux_prevus = readline(44)
+
+ SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus
+ SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
+ SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
+ SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
+ SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
+ SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
+
+ SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
+ SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
+ FROM layer_styles
+ WHERE description = 'travaux_prevus_ligne_modele'"""
+
+ cur.execute(SQL_travaux_prevus)
+ cur.execute(SQL_pkey)
+ cur.execute(SQL_trigger_date_creation)
+ cur.execute(SQL_trigger_date_maj)
+ cur.execute(SQL_trigger_length_m)
+ cur.execute(SQL_trigger_length_km)
+ cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
+
+ con.commit()
+
+ ## Affichage de la table
+ uri = QgsDataSourceURI()
+ # set host name, port, database name, username and password
+ uri.setConnection(host ,port ,dbname ,user ,password)
+ # set database schema, table name, geometry column and optionaly subset (WHERE clause)
+ uri.setDataSource(schema, tablename, geom)
+
+ layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
+
+ #**********point
+ if self.dlgAjout.ui.annee_5.text() == 'aaaa' or self.dlgAjout.ui.annee_5.text() == '':
+ tablename = schema + "_travaux_prevus_point"
+ else :
+ tablename = schema + "_travaux_prevus_point_" + self.dlgAjout.ui.annee_5.text()
+ tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
+ geom = readline(6)
+ style = readline(28)
+ champ_travaux_prevus = readline(45)
+
+ SQL_travaux_prevus = "CREATE TABLE " + schema + "."+ tablename + champ_travaux_prevus
+ SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
+ SQL_trigger_date_creation = "CREATE TRIGGER date_creation" + tablename + " BEFORE INSERT ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_creation();"
+ SQL_trigger_date_maj = "CREATE TRIGGER date_maj" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.date_maj();"
+ SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
+
+ SQL_style = """INSERT INTO layer_styles (f_table_catalog, f_table_schema, f_table_name, f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, update_time)
+ SELECT f_table_catalog, '""" + schema + "', '" + tablename + """', f_geometry_column, stylename, styleqml, stylesld, useasdefault, "owner", ui, now()
+ FROM layer_styles
+ WHERE description = 'travaux_prevus_point_modele'"""
+
+ cur.execute(SQL_travaux_prevus)
+ cur.execute(SQL_pkey)
+ cur.execute(SQL_trigger_date_creation)
+ cur.execute(SQL_trigger_date_maj)
+ cur.execute(SQL_trigger_coordonnees)
+ cur.execute(SQL_style) ## Enregistrement du style (comme style par defaut) dans la table layer_styles
+
+ con.commit()
+
+ ## Affichage de la table
+ uri = QgsDataSourceURI()
+ # set host name, port, database name, username and password
+ uri.setConnection(host ,port ,dbname ,user ,password)
+ # set database schema, table name, geometry column and optionaly subset (WHERE clause)
+ uri.setDataSource(schema, tablename, geom)
+
+ layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
+
+ ### Creation de la table vierge
+ if self.dlgAjout.ui.couche_vierge.isChecked():
+ if self.dlgAjout.ui.annee_4.text() == 'aaaa' or self.dlgAjout.ui.annee_4.text() == '':
+ tablename = schema + "_" + self.dlgAjout.ui.nom_couche_vierge.text().lower()
+ else :
+ tablename = schema + "_" + self.dlgAjout.ui.nom_couche_vierge.text().lower() + "_" + self.dlgAjout.ui.annee_4.text()
+ tablename_qgis = tablename[1:] # Permet d'enlever le "_", ajouter a la premiere etape, dans qgis
+ geom = readline(6)
+ style = readline(29)
+ champ_viergePolygone = readline(48)
+ champ_viergeLigne = readline(49)
+ champ_viergePoint = readline(50)
+
+ if self.dlgAjout.ui.couche_vierge_point.isChecked() == 1 :
+ champ_vierge = champ_viergePoint
+
+ if self.dlgAjout.ui.couche_vierge_ligne.isChecked() == 1 :
+ champ_vierge = champ_viergeLigne
+
+ if self.dlgAjout.ui.couche_vierge_polygone.isChecked() == 1 :
+ champ_vierge = champ_viergePolygone
+
+ SQL_vierge = "CREATE TABLE " + schema + "."+ tablename + champ_vierge
+ SQL_pkey = "ALTER TABLE " + schema + "." + tablename + " ADD CONSTRAINT " + tablename + "_pkey" + " PRIMARY KEY (gid)"
+
+ SQL_trigger_area_m2 = "CREATE TRIGGER area_m2" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_m2();"
+ SQL_trigger_area_ha = "CREATE TRIGGER area_ha" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.area_ha();"
+ SQL_trigger_length_m = "CREATE TRIGGER length_m" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_m();"
+ SQL_trigger_length_km = "CREATE TRIGGER length_km" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.length_km();"
+ SQL_trigger_coordonnees = "CREATE TRIGGER coordonnees" + tablename + " BEFORE INSERT OR UPDATE ON " + schema + "." + tablename + " FOR EACH ROW EXECUTE PROCEDURE ref.coordonnees();"
+
+ cur.execute(SQL_vierge)
+ cur.execute(SQL_pkey)
+
+ if self.dlgAjout.ui.couche_vierge_point.isChecked() == 1 :
+ cur.execute(SQL_trigger_coordonnees)
+
+ if self.dlgAjout.ui.couche_vierge_ligne.isChecked() == 1 :
+ cur.execute(SQL_trigger_length_m)
+ cur.execute(SQL_trigger_length_km)
+
+ if self.dlgAjout.ui.couche_vierge_polygone.isChecked() == 1 :
+ cur.execute(SQL_trigger_area_m2)
+ cur.execute(SQL_trigger_area_ha)
+
+ con.commit()
+
+ ### Affichage de la table
+ uri = QgsDataSourceURI()
+ # set host name, port, database name, username and password
+ uri.setConnection(host ,port ,dbname ,user ,password)
+ # set database schema, table name, geometry column and optionaly subset (WHERE clause)
+ uri.setDataSource(schema, tablename, geom)
+
+ layer = self.iface.addVectorLayer(uri.uri(), tablename_qgis, "postgres")
+
+ else :
+ con.commit()
+
+ con.close()
+ pass
\ No newline at end of file
diff --git a/CenRa_POSTGIS/cenradialog.py.bak b/CenRa_POSTGIS/cenradialog.py.bak
new file mode 100644
index 00000000..e29830d2
--- /dev/null
+++ b/CenRa_POSTGIS/cenradialog.py.bak
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+"""
+/***************************************************************************
+ CenRaDialog
+ A QGIS plugin
+ Conservatoire d'Espaces Naturels de Rhône-Alpes
+ -------------------
+ begin : 2014-03-27
+ copyright : (C) 2014 by Conservatoire d'Espaces Naturels de Rhône-Alpes
+ 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 PyQt4 import QtCore, QtGui
+from ui_cenra import Ui_cenra
+# create the dialog for zoom to point
+
+
+class CenRaDialog(QtGui.QDialog, Ui_cenra):
+ def __init__(self):
+ QtGui.QDialog.__init__(self)
+ # Set up the user interface from Designer.
+ # After setupUI you can access any designer object by doing
+ # self.
+Your QGIS plugin directory is located at:
+ C:/Users/gcostes/.qgis2/python/plugins
+
+What's Next +
+For more information, see the PyQGIS Developer Cookbook at: +http://www.qgis.org/pyqgis-cookbook/index.html. +
+
+©2011-2014 GeoApt LLC - geoapt.com
+
+
diff --git a/CenRa_SICEN/forms/about_form.py b/CenRa_SICEN/forms/about_form.py
new file mode 100644
index 00000000..89329d3f
--- /dev/null
+++ b/CenRa_SICEN/forms/about_form.py
@@ -0,0 +1,46 @@
+import os.path
+
+from pathlib import Path
+
+from qgis.PyQt import uic
+from qgis.PyQt.QtGui import QPixmap
+from qgis.PyQt.QtWidgets import QDialog
+
+from ..tools.resources import devlog
+
+ABOUT_FORM_CLASS, _ = uic.loadUiType(
+ os.path.join(
+ str(Path(__file__).resolve().parent.parent),
+ 'forms',
+ 'sicen_about_form.ui'
+ )
+)
+
+
+class SicenAboutDialog(QDialog, ABOUT_FORM_CLASS):
+
+ """ About - Let the user display the about dialog. """
+
+ def __init__(self, iface, parent=None):
+ super().__init__(parent)
+ self.iface = iface
+ self.setupUi(self)
+
+ self.viewer.setHtml(devlog('CenRa_SICEN'))
+
+ self.rejected.connect(self.onReject)
+ self.buttonBox.rejected.connect(self.onReject)
+ self.buttonBox.accepted.connect(self.onAccept)
+
+ def onAccept(self):
+ """
+ Save options when pressing OK button
+ """
+ self.accept()
+
+ def onReject(self):
+ """
+ Run some actions when
+ the user closes the dialog
+ """
+ self.close()
\ No newline at end of file
diff --git a/CenRa_SICEN/forms/sicen_about_form.ui b/CenRa_SICEN/forms/sicen_about_form.ui
new file mode 100644
index 00000000..a99c3eab
--- /dev/null
+++ b/CenRa_SICEN/forms/sicen_about_form.ui
@@ -0,0 +1,96 @@
+
+