Git ignore fonctione
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
#/***************************************************************************
|
||||
# SICEN
|
||||
#
|
||||
# Filtre sur données SICEN
|
||||
# -------------------
|
||||
# begin : 2014-10-17
|
||||
# copyright : (C) 2014 by Guillaume COSTES
|
||||
# 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. *
|
||||
# * *
|
||||
# ***************************************************************************/
|
||||
|
||||
# CONFIGURATION
|
||||
PLUGIN_UPLOAD = $(CURDIR)/plugin_upload.py
|
||||
|
||||
QGISDIR=.qgis2
|
||||
|
||||
# Makefile for a PyQGIS plugin
|
||||
|
||||
# translation
|
||||
SOURCES = sicen.py ui_sicen.py __init__.py sicendialog.py
|
||||
#TRANSLATIONS = i18n/sicen_en.ts
|
||||
TRANSLATIONS =
|
||||
|
||||
# global
|
||||
|
||||
PLUGINNAME = sicen
|
||||
|
||||
PY_FILES = sicen.py sicendialog.py __init__.py
|
||||
|
||||
EXTRAS = cenra.png metadata.txt
|
||||
|
||||
UI_FILES = ui_sicen.py
|
||||
|
||||
RESOURCE_FILES = resources_rc.py
|
||||
|
||||
HELP = help/build/html
|
||||
|
||||
default: compile
|
||||
|
||||
compile: $(UI_FILES) $(RESOURCE_FILES)
|
||||
|
||||
%_rc.py : %.qrc
|
||||
pyrcc4 -o $*_rc.py $<
|
||||
|
||||
%.py : %.ui
|
||||
pyuic4 -o $@ $<
|
||||
|
||||
%.qm : %.ts
|
||||
lrelease $<
|
||||
|
||||
# The deploy target only works on unix like operating system where
|
||||
# the Python plugin directory is located at:
|
||||
# $HOME/$(QGISDIR)/python/plugins
|
||||
deploy: compile doc transcompile
|
||||
mkdir -p $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
|
||||
cp -vf $(PY_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
|
||||
cp -vf $(UI_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
|
||||
cp -vf $(RESOURCE_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
|
||||
cp -vf $(EXTRAS) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
|
||||
cp -vfr i18n $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
|
||||
cp -vfr $(HELP) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)/help
|
||||
|
||||
# The dclean target removes compiled python files from plugin directory
|
||||
# also delets any .svn entry
|
||||
dclean:
|
||||
find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname "*.pyc" -delete
|
||||
find $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME) -iname ".svn" -prune -exec rm -Rf {} \;
|
||||
|
||||
# The derase deletes deployed plugin
|
||||
derase:
|
||||
rm -Rf $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
|
||||
|
||||
# The zip target deploys the plugin and creates a zip file with the deployed
|
||||
# content. You can then upload the zip file on http://plugins.qgis.org
|
||||
zip: deploy dclean
|
||||
rm -f $(PLUGINNAME).zip
|
||||
cd $(HOME)/$(QGISDIR)/python/plugins; zip -9r $(CURDIR)/$(PLUGINNAME).zip $(PLUGINNAME)
|
||||
|
||||
# Create a zip package of the plugin named $(PLUGINNAME).zip.
|
||||
# This requires use of git (your plugin development directory must be a
|
||||
# git repository).
|
||||
# To use, pass a valid commit or tag as follows:
|
||||
# make package VERSION=Version_0.3.2
|
||||
package: compile
|
||||
rm -f $(PLUGINNAME).zip
|
||||
git archive --prefix=$(PLUGINNAME)/ -o $(PLUGINNAME).zip $(VERSION)
|
||||
echo "Created package: $(PLUGINNAME).zip"
|
||||
|
||||
upload: zip
|
||||
$(PLUGIN_UPLOAD) $(PLUGINNAME).zip
|
||||
|
||||
# transup
|
||||
# update .ts translation files
|
||||
transup:
|
||||
pylupdate4 Makefile
|
||||
|
||||
# transcompile
|
||||
# compile translation files into .qm binary format
|
||||
transcompile: $(TRANSLATIONS:.ts=.qm)
|
||||
|
||||
# transclean
|
||||
# deletes all .qm files
|
||||
transclean:
|
||||
rm -f i18n/*.qm
|
||||
|
||||
clean:
|
||||
rm $(UI_FILES) $(RESOURCE_FILES)
|
||||
|
||||
# build documentation with sphinx
|
||||
doc:
|
||||
cd help; make html
|
||||
@@ -0,0 +1,32 @@
|
||||
<html>
|
||||
<body style='background-color:##D7ECF8;'>
|
||||
<h3>Plugin Builder Results</h3>
|
||||
<div id='help' style='font-size:.9em;'>
|
||||
Your plugin <b>SICEN</b> was created in:<br>
|
||||
<b>C:\Users\gcostes\.qgis2\python\plugins\SICEN</b>
|
||||
<p>
|
||||
Your QGIS plugin directory is located at:<br>
|
||||
<b>C:/Users/gcostes/.qgis2/python/plugins</b>
|
||||
<p>
|
||||
<b>What's Next</b>
|
||||
<ol>
|
||||
<li>Copy the entire directory containing your new plugin to the QGIS plugin directory
|
||||
<li>Compile the ui file using pyuic4
|
||||
<li>Compile the resources file using pyrcc4
|
||||
<li>Test the plugin by enabling it in the QGIS plugin manager
|
||||
<li>Customize it by editing the implementation file <b>sicen.py</b>
|
||||
<li>Create your own custom icon, replacing the default <b>icon.png</b>
|
||||
<li>Modify your user interface by opening <b>sicen.ui</b> in Qt Designer (don't forget to compile it with pyuic4 after changing it)
|
||||
<li>You can use the <b>Makefile</b> to compile your Ui and resource files when you make changes. This requires GNU make (gmake)
|
||||
</ul>
|
||||
</div>
|
||||
<div style='font-size:.9em;'>
|
||||
<p>
|
||||
For more information, see the PyQGIS Developer Cookbook at:
|
||||
<a href="http://www.qgis.org/pyqgis-cookbook/index.html">http://www.qgis.org/pyqgis-cookbook/index.html</a>.
|
||||
</p>
|
||||
</div>
|
||||
<img src="http://geoapt.com/geoapt_logo_p.png" alt='GeoApt LLC' title='GeoApt LLC' align='absmiddle'>
|
||||
©2011-2014 GeoApt LLC - geoapt.com
|
||||
</body>
|
||||
</html>
|
||||
@@ -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()
|
||||
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CenRa_Metabase_editorwidget_base</class>
|
||||
<widget class="QDialog" name="CenRa_Metabase_editorwidget_base">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>471</width>
|
||||
<height>594</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>SICEN</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normaloff>../../CenRa_Metabase/tools/ui/icon.svg</normaloff>../../CenRa_Metabase/tools/ui/icon.svg</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::NoFocus</enum>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>453</width>
|
||||
<height>547</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>451</width>
|
||||
<height>541</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>DevLog</string>
|
||||
</property>
|
||||
<widget class="QWebView" name="viewer" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>20</y>
|
||||
<width>431</width>
|
||||
<height>511</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="url" stdset="0">
|
||||
<url>
|
||||
<string>about:blank</string>
|
||||
</url>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QWebView</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">QtWebKitWidgets/QWebView</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,130 @@
|
||||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = build
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
PAPEROPT_letter = -D latex_paper_size=letter
|
||||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
|
||||
|
||||
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " singlehtml to make a single large HTML file"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||
@echo " qthelp to make HTML files and a qthelp project"
|
||||
@echo " devhelp to make HTML files and a Devhelp project"
|
||||
@echo " epub to make an epub"
|
||||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||
@echo " latexpdf to make LaTeX files and run them through pdflatex"
|
||||
@echo " text to make text files"
|
||||
@echo " man to make manual pages"
|
||||
@echo " changes to make an overview of all changed/added/deprecated items"
|
||||
@echo " linkcheck to check all external links for integrity"
|
||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||
|
||||
clean:
|
||||
-rm -rf $(BUILDDIR)/*
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
|
||||
|
||||
singlehtml:
|
||||
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
|
||||
|
||||
pickle:
|
||||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
|
||||
@echo
|
||||
@echo "Build finished; now you can process the pickle files."
|
||||
|
||||
json:
|
||||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
|
||||
@echo
|
||||
@echo "Build finished; now you can process the JSON files."
|
||||
|
||||
htmlhelp:
|
||||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run HTML Help Workshop with the" \
|
||||
".hhp project file in $(BUILDDIR)/htmlhelp."
|
||||
|
||||
qthelp:
|
||||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/templateclass.qhcp"
|
||||
@echo "To view the help file:"
|
||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/templateclass.qhc"
|
||||
|
||||
devhelp:
|
||||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
||||
@echo
|
||||
@echo "Build finished."
|
||||
@echo "To view the help file:"
|
||||
@echo "# mkdir -p $$HOME/.local/share/devhelp/templateclass"
|
||||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/templateclass"
|
||||
@echo "# devhelp"
|
||||
|
||||
epub:
|
||||
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
|
||||
@echo
|
||||
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
|
||||
|
||||
latex:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo
|
||||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
|
||||
@echo "Run \`make' in that directory to run these through (pdf)latex" \
|
||||
"(use \`make latexpdf' here to do that automatically)."
|
||||
|
||||
latexpdf:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through pdflatex..."
|
||||
make -C $(BUILDDIR)/latex all-pdf
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
text:
|
||||
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
|
||||
@echo
|
||||
@echo "Build finished. The text files are in $(BUILDDIR)/text."
|
||||
|
||||
man:
|
||||
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
|
||||
@echo
|
||||
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
|
||||
|
||||
changes:
|
||||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
|
||||
@echo
|
||||
@echo "The overview file is in $(BUILDDIR)/changes."
|
||||
|
||||
linkcheck:
|
||||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
|
||||
@echo
|
||||
@echo "Link check complete; look for any errors in the above output " \
|
||||
"or in $(BUILDDIR)/linkcheck/output.txt."
|
||||
|
||||
doctest:
|
||||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
|
||||
@echo "Testing of doctests in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/doctest/output.txt."
|
||||
@@ -0,0 +1,155 @@
|
||||
@ECHO OFF
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set BUILDDIR=build
|
||||
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source
|
||||
if NOT "%PAPER%" == "" (
|
||||
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
|
||||
)
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
if "%1" == "help" (
|
||||
:help
|
||||
echo.Please use `make ^<target^>` where ^<target^> is one of
|
||||
echo. html to make standalone HTML files
|
||||
echo. dirhtml to make HTML files named index.html in directories
|
||||
echo. singlehtml to make a single large HTML file
|
||||
echo. pickle to make pickle files
|
||||
echo. json to make JSON files
|
||||
echo. htmlhelp to make HTML files and a HTML help project
|
||||
echo. qthelp to make HTML files and a qthelp project
|
||||
echo. devhelp to make HTML files and a Devhelp project
|
||||
echo. epub to make an epub
|
||||
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
|
||||
echo. text to make text files
|
||||
echo. man to make manual pages
|
||||
echo. changes to make an overview over all changed/added/deprecated items
|
||||
echo. linkcheck to check all external links for integrity
|
||||
echo. doctest to run all doctests embedded in the documentation if enabled
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "clean" (
|
||||
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
|
||||
del /q /s %BUILDDIR%\*
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "html" (
|
||||
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "dirhtml" (
|
||||
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "singlehtml" (
|
||||
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "pickle" (
|
||||
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
|
||||
echo.
|
||||
echo.Build finished; now you can process the pickle files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "json" (
|
||||
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
|
||||
echo.
|
||||
echo.Build finished; now you can process the JSON files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "htmlhelp" (
|
||||
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
|
||||
echo.
|
||||
echo.Build finished; now you can run HTML Help Workshop with the ^
|
||||
.hhp project file in %BUILDDIR%/htmlhelp.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "qthelp" (
|
||||
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
|
||||
echo.
|
||||
echo.Build finished; now you can run "qcollectiongenerator" with the ^
|
||||
.qhcp project file in %BUILDDIR%/qthelp, like this:
|
||||
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\templateclass.qhcp
|
||||
echo.To view the help file:
|
||||
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\templateclass.ghc
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "devhelp" (
|
||||
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
|
||||
echo.
|
||||
echo.Build finished.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "epub" (
|
||||
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
|
||||
echo.
|
||||
echo.Build finished. The epub file is in %BUILDDIR%/epub.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latex" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
echo.
|
||||
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "text" (
|
||||
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
|
||||
echo.
|
||||
echo.Build finished. The text files are in %BUILDDIR%/text.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "man" (
|
||||
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
|
||||
echo.
|
||||
echo.Build finished. The manual pages are in %BUILDDIR%/man.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "changes" (
|
||||
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
|
||||
echo.
|
||||
echo.The overview file is in %BUILDDIR%/changes.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "linkcheck" (
|
||||
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
|
||||
echo.
|
||||
echo.Link check complete; look for any errors in the above output ^
|
||||
or in %BUILDDIR%/linkcheck/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "doctest" (
|
||||
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
|
||||
echo.
|
||||
echo.Testing of doctests in the sources finished, look at the ^
|
||||
results in %BUILDDIR%/doctest/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
:end
|
||||
@@ -0,0 +1,216 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# sicen documentation build configuration file, created by
|
||||
# sphinx-quickstart on Sun Feb 12 17:11:03 2012.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import sys, os
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
# -- General configuration -----------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be extensions
|
||||
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
extensions = ['sphinx.ext.todo', 'sphinx.ext.pngmath', 'sphinx.ext.viewcode']
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The encoding of source files.
|
||||
#source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'sicen'
|
||||
copyright = u'2013, Guillaume COSTES'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '0.1'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '0.1'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
#today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
#today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
exclude_patterns = []
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all documents.
|
||||
#default_role = None
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
#add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
#add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
#show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
#modindex_common_prefix = []
|
||||
|
||||
|
||||
# -- Options for HTML output ---------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
html_theme = 'default'
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
#html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
#html_theme_path = []
|
||||
|
||||
# The name for this set of Sphinx documents. If None, it defaults to
|
||||
# "<project> v<release> documentation".
|
||||
#html_title = None
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
#html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
#html_logo = None
|
||||
|
||||
# The name of an image file (within the static path) to use as favicon of the
|
||||
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
#html_favicon = None
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||
# using the given strftime format.
|
||||
#html_last_updated_fmt = '%b %d, %Y'
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
#html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
#html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
#html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
#html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
#html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
#html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
#html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
#html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
#html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
#html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
#html_file_suffix = None
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'templateclassdoc'
|
||||
|
||||
|
||||
# -- Options for LaTeX output --------------------------------------------------
|
||||
|
||||
# The paper size ('letter' or 'a4').
|
||||
#latex_paper_size = 'letter'
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#latex_font_size = '10pt'
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title, author, documentclass [howto/manual]).
|
||||
latex_documents = [
|
||||
('index', 'sicen.tex', u'sicen Documentation',
|
||||
u'Guillaume COSTES', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
#latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
#latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
#latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#latex_show_urls = False
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#latex_preamble = ''
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output --------------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
('index', 'templateclass', u'sicen Documentation',
|
||||
[u'Guillaume COSTES'], 1)
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
.. sicen documentation master file, created by
|
||||
sphinx-quickstart on Sun Feb 12 17:11:03 2012.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
Welcome to sicen's documentation!
|
||||
============================================
|
||||
|
||||
Contents:
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<RCC>
|
||||
<qresource prefix="/plugins/sicen" >
|
||||
<file>sicen.png</file>
|
||||
</qresource>
|
||||
<qresource prefix="/plugins/sicen" >
|
||||
<file>sicen_export.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -0,0 +1,852 @@
|
||||
# -*- 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. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
"""
|
||||
# Import the PyQt and QGIS libraries
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
from qgis.core import *
|
||||
from qgis.gui import *
|
||||
from qgis.utils import iface
|
||||
|
||||
# Initialize Qt resources from file resources.py
|
||||
import resources_rc
|
||||
# Import the code for the dialog
|
||||
from sicendialog import SICENDialog
|
||||
|
||||
import os.path
|
||||
import psycopg2
|
||||
import qgis
|
||||
import datetime
|
||||
import csv
|
||||
|
||||
class SICEN:
|
||||
|
||||
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', 'sicen_{}.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 = SICENDialog()
|
||||
|
||||
def initGui(self):
|
||||
self.toolBar = self.iface.addToolBar("SICEN")
|
||||
self.toolBar.setObjectName("SICEN")
|
||||
|
||||
## Create action that will start plugin configuration
|
||||
self.action = QAction(
|
||||
QIcon(":/plugins/sicen/sicen.png"),
|
||||
u"Ouverture des données SICEN", self.iface.mainWindow())
|
||||
# connect the action to the run method
|
||||
self.action.triggered.connect(self.ouverture)
|
||||
|
||||
# Add toolbar button and menu item
|
||||
self.toolBar.addAction(self.action)
|
||||
self.iface.addPluginToMenu(u"SICEN", self.action)
|
||||
|
||||
## 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())
|
||||
# connect the action to the run method
|
||||
self.action.triggered.connect(self.export)
|
||||
|
||||
# Add toolbar button and menu item
|
||||
self.toolBar.addAction(self.action)
|
||||
self.iface.addPluginToMenu(u"SICEN", self.action)
|
||||
|
||||
self.menu = QMenu()
|
||||
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.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 )
|
||||
|
||||
self.sicen_ouverture.triggered.connect(self.ouverture)
|
||||
self.sicen_export.triggered.connect(self.export)
|
||||
|
||||
def unload(self):
|
||||
# Remove the plugin menu item and icon
|
||||
self.iface.removePluginMenu(u"&SICEN", self.action)
|
||||
self.iface.removeToolBarIcon(self.action)
|
||||
|
||||
# run method that performs all the real work
|
||||
def ouverture(self):
|
||||
|
||||
### 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)
|
||||
|
||||
# Connexion a la BD
|
||||
con = psycopg2.connect("dbname="+ dbname + " user=" + user + " host=" + host + " password=" + password + " port=" + port)
|
||||
cur = con.cursor()
|
||||
|
||||
## Creation des listes deroulantes
|
||||
# Listing de valeur des champs
|
||||
SQL_observateur = u"""SELECT DISTINCT nom || '_' || prenom as nom FROM md.personne WHERE nom LIKE '%CenRA%' 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
|
||||
cur.execute(SQL_observateur)
|
||||
list_observateur = cur.fetchall()
|
||||
|
||||
cur.execute(SQL_nom_com)
|
||||
list_nom_com = cur.fetchall()
|
||||
|
||||
cur.execute(SQL_nom_vern)
|
||||
list_nom_vern = cur.fetchall()
|
||||
|
||||
cur.execute(SQL_nom_complet)
|
||||
list_nom_complet = cur.fetchall()
|
||||
|
||||
cur.execute(SQL_ordre)
|
||||
list_ordre = cur.fetchall()
|
||||
|
||||
con.close()
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
self.dlg.observateur_2.clear()
|
||||
i = 0
|
||||
while i < len(list_observateur):
|
||||
self.dlg.observateur_2.addItems(list_observateur[i])
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
self.dlg.ordre.setCurrentIndex(-1)
|
||||
|
||||
# show the dialog
|
||||
self.dlg.show()
|
||||
# Run the dialog event loop
|
||||
result = self.dlg.exec_()
|
||||
# See if OK was pressed
|
||||
if result == 1:
|
||||
|
||||
### 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)
|
||||
|
||||
# Requete filtre observateur
|
||||
if self.dlg.observateur_1.currentIndex() != -1 :
|
||||
sql_obs1 = """ "observateur" LIKE '%""" + self.dlg.observateur_1.currentText() + "%' "
|
||||
else :
|
||||
sql_obs1 = ''
|
||||
|
||||
if self.dlg.observateur_2.currentIndex() != -1 :
|
||||
sql_obs2 = """ "observateur" LIKE '%""" + self.dlg.observateur_2.currentText() + "%' "
|
||||
else :
|
||||
sql_obs2 = ''
|
||||
|
||||
if self.dlg.observateur_3.currentIndex() != -1 :
|
||||
sql_obs3 = """ "observateur" LIKE '%""" + self.dlg.observateur_3.currentText() + "%' "
|
||||
else :
|
||||
sql_obs3 = ''
|
||||
|
||||
if self.dlg.observateur_4.currentIndex() != -1 :
|
||||
sql_obs4 = """ "observateur" LIKE '%""" + self.dlg.observateur_4.currentText() + "%' "
|
||||
else :
|
||||
sql_obs4 = ''
|
||||
|
||||
reqwhere_obs = sql_obs1 + 'OR' + sql_obs2 + 'OR' + sql_obs3 + 'OR' + sql_obs4
|
||||
|
||||
while reqwhere_obs[-2:] == 'OR' :
|
||||
reqwhere_obs = reqwhere_obs[:-2]
|
||||
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()
|
||||
|
||||
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)
|
||||
list_code_INSEE = cur.fetchall()
|
||||
code_INSEE = list_code_INSEE[0][0]
|
||||
|
||||
sql_insee_1 = """ "code_insee" = '""" + code_INSEE + "' "
|
||||
else :
|
||||
sql_insee_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)
|
||||
list_code_INSEE = cur.fetchall()
|
||||
code_INSEE = list_code_INSEE[0][0]
|
||||
|
||||
sql_insee_2 = """ "code_insee" = '""" + code_INSEE + "' "
|
||||
else :
|
||||
sql_insee_2 = ''
|
||||
|
||||
reqwhere_insee = sql_insee_1 + 'OR' + sql_insee_2
|
||||
|
||||
while reqwhere_insee[-2:] == 'OR' :
|
||||
reqwhere_insee = reqwhere_insee[:-2]
|
||||
while reqwhere_insee[:2] == 'OR' :
|
||||
reqwhere_insee = reqwhere_insee[2:]
|
||||
|
||||
con.close()
|
||||
|
||||
# Requete date
|
||||
today = datetime.datetime.now().strftime("%Y-%m-%d")
|
||||
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 :
|
||||
sql_date_min = """ "date_obs" >= '""" + date_min + "' "
|
||||
else :
|
||||
sql_date_min = ''
|
||||
|
||||
if date_max != today :
|
||||
sql_date_max = """ "date_obs" <= '""" + date_max + "' "
|
||||
else :
|
||||
sql_date_max = ''
|
||||
|
||||
reqwhere_date = sql_date_min + 'AND' + sql_date_max
|
||||
|
||||
while reqwhere_obs[-3:] == 'AND' :
|
||||
reqwhere_obs = reqwhere_obs[:-3]
|
||||
while reqwhere_obs[:3] == 'AND' :
|
||||
reqwhere_obs = reqwhere_obs[3:]
|
||||
|
||||
# Requete regne
|
||||
if self.dlg.Animalia.isChecked() == 1 :
|
||||
sql_Animalia = """"regne" = 'Animalia'"""
|
||||
else :
|
||||
sql_Animalia = ''
|
||||
|
||||
if self.dlg.Plantae.isChecked() == 1 :
|
||||
sql_Plantae = """"regne" = 'Plantae'"""
|
||||
else :
|
||||
sql_Plantae = ''
|
||||
|
||||
reqwhere_regne = sql_Animalia + 'OR' + sql_Plantae
|
||||
|
||||
while reqwhere_regne[-2:] == 'OR' :
|
||||
reqwhere_regne = reqwhere_regne[:-2]
|
||||
while reqwhere_regne[:2] == 'OR' :
|
||||
reqwhere_regne = reqwhere_regne[2:]
|
||||
|
||||
# Requete ordre
|
||||
if self.dlg.ordre.currentIndex() != -1 :
|
||||
reqwhere_ordre = """"ordre" = '""" + self.dlg.ordre.currentText() + "'"
|
||||
else :
|
||||
reqwhere_ordre = ''
|
||||
|
||||
# Requete sp
|
||||
if self.dlg.nom_vern.currentIndex() != -1 :
|
||||
sql_nom_vern = """"nom_vern" = '""" + self.dlg.nom_vern.currentText() + "'"
|
||||
else :
|
||||
sql_nom_vern = ''
|
||||
|
||||
if self.dlg.nom_complet.currentIndex() != -1 :
|
||||
sql_nom_complet = """"nom_complet" = '""" + self.dlg.nom_complet.currentText() + "'"
|
||||
else :
|
||||
sql_nom_complet = ''
|
||||
|
||||
reqwhere_sp = sql_nom_vern + 'OR' + sql_nom_complet
|
||||
|
||||
while reqwhere_sp[-2:] == 'OR' :
|
||||
reqwhere_sp = reqwhere_sp[:-2]
|
||||
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 :
|
||||
sql_lrd01 = ''
|
||||
|
||||
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 :
|
||||
sql_lrd26 = ''
|
||||
|
||||
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 :
|
||||
sql_lrd42 = ''
|
||||
|
||||
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 :
|
||||
sql_lrd73 = ''
|
||||
|
||||
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 :
|
||||
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 :
|
||||
sql_LRR_Flore = ''
|
||||
|
||||
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 :
|
||||
sql_LRR_Oiseaux = ''
|
||||
|
||||
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 :
|
||||
sql_LRR_Autre = ''
|
||||
|
||||
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 :
|
||||
sql_LRN_Flore = ''
|
||||
|
||||
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 :
|
||||
sql_LRN_Oiseaux = ''
|
||||
|
||||
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 :
|
||||
sql_LRN_Ortho = ''
|
||||
|
||||
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 :
|
||||
sql_LRN_Autre = ''
|
||||
|
||||
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 :
|
||||
sql_UICN = ''
|
||||
|
||||
|
||||
if self.dlg.PATRIMONIALITE.isChecked() == 1 :
|
||||
sql_patrimonialite = """"patrimonialite" IS NOT NULL """
|
||||
else :
|
||||
sql_patrimonialite = ''
|
||||
|
||||
if self.dlg.PATRI01.isChecked() == 1 :
|
||||
sql_patri01 = """"patri01" IS NOT NULL """
|
||||
else :
|
||||
sql_patri01 = ''
|
||||
|
||||
if self.dlg.PATRI07.isChecked() == 1 :
|
||||
sql_patri07 = """"patri07" IS NOT NULL """
|
||||
else :
|
||||
sql_patri07 = ''
|
||||
|
||||
if self.dlg.PATRI26.isChecked() == 1 :
|
||||
sql_patri26 = """"patri26" IS NOT NULL """
|
||||
else :
|
||||
sql_patri26 = ''
|
||||
|
||||
if self.dlg.PATRI38.isChecked() == 1 :
|
||||
sql_patri38 = """"patri38" IS NOT NULL """
|
||||
else :
|
||||
sql_patri38 = ''
|
||||
|
||||
if self.dlg.PATRI42.isChecked() == 1 :
|
||||
sql_patri42 = """"patri42" IS NOT NULL """
|
||||
else :
|
||||
sql_patri42 = ''
|
||||
|
||||
if self.dlg.PATRI69.isChecked() == 1 :
|
||||
sql_patri69 = """"patri69" IS NOT NULL """
|
||||
else :
|
||||
sql_patri69 = ''
|
||||
|
||||
if self.dlg.PATRI73.isChecked() == 1 :
|
||||
sql_patri73 = """"patri73" IS NOT NULL """
|
||||
else :
|
||||
sql_patri73 = ''
|
||||
|
||||
if self.dlg.PATRI74.isChecked() == 1 :
|
||||
sql_patri74 = """"patri74" IS NOT NULL """
|
||||
else :
|
||||
sql_patri74 = ''
|
||||
|
||||
|
||||
if self.dlg.ZNIEFF.isChecked() == 1 :
|
||||
sql_znieff = """"znieff" IS NOT NULL """
|
||||
else :
|
||||
sql_znieff = ''
|
||||
|
||||
if self.dlg.DH_AnnII.isChecked() == 1 :
|
||||
sql_dh_an2 = """"dh_an2" IS NOT NULL """
|
||||
else :
|
||||
sql_dh_an2 = ''
|
||||
|
||||
if self.dlg.PD_38.isChecked() == 1 :
|
||||
sql_pd38 = """"pd38" IS NOT NULL """
|
||||
else :
|
||||
sql_pd38 = ''
|
||||
|
||||
if self.dlg.PD_42.isChecked() == 1 :
|
||||
sql_pd42 = """"pd42" IS NOT NULL """
|
||||
else :
|
||||
sql_pd42 = ''
|
||||
|
||||
if self.dlg.PN.isChecked() == 1 :
|
||||
sql_pn = """"pn" IS NOT NULL """
|
||||
else :
|
||||
sql_pn = ''
|
||||
|
||||
if self.dlg.PR.isChecked() == 1 :
|
||||
sql_pr = """"pr" IS NOT NULL """
|
||||
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
|
||||
|
||||
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' :
|
||||
reqwhere_pat = reqwhere_pat[2:]
|
||||
|
||||
# Requete geom
|
||||
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)
|
||||
|
||||
else :
|
||||
selection = layer.selectedFeatures()
|
||||
if layer.selectedFeatureCount() == 1 :
|
||||
for feature in selection:
|
||||
geom = feature.geometry()
|
||||
poly = geom.exportToWkt()
|
||||
|
||||
buffer = self.dlg.buffer.text()
|
||||
reqwhere_geom = " ST_intersects(geometrie,ST_Buffer(ST_geomFromText('" + poly + "',2154), " + 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
|
||||
|
||||
# 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' :
|
||||
reqwhere_final = reqwhere_final[:-3]
|
||||
while reqwhere_final[:5] == '()AND' :
|
||||
reqwhere_final = reqwhere_final[5:]
|
||||
while reqwhere_final[-5:] == 'AND()' :
|
||||
reqwhere_final = reqwhere_final[:-5]
|
||||
while reqwhere_final[:3] == 'AND' :
|
||||
reqwhere_final = reqwhere_final[3:]
|
||||
|
||||
## Affichage des tables
|
||||
table_name = 'observations'
|
||||
|
||||
uri = QgsDataSourceURI()
|
||||
uri.setConnection(host ,port ,dbname ,user ,password)
|
||||
|
||||
if self.dlg.centroide.isChecked() == 1 :
|
||||
### Centroide
|
||||
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 :
|
||||
con = psycopg2.connect("dbname="+ dbname + " user=" + user + " host=" + host + " password=" + password + " port=" + port)
|
||||
cur = con.cursor()
|
||||
|
||||
# Creation group de couches
|
||||
i = qgis.utils.iface
|
||||
legende = i.legendInterface()
|
||||
nomgroupe = 'Observations'
|
||||
groupe = legende.addGroup(nomgroupe,False)
|
||||
|
||||
# Récupération de la liste de groupes
|
||||
toc = qgis.utils.iface.legendInterface()
|
||||
groups = toc.groups()
|
||||
index = groups.index(nomgroupe)
|
||||
|
||||
### Polygone
|
||||
reqwhere_final_poly = '(' + reqwhere_final + " AND GeometryType(geometrie) LIKE '%POLYGON%'" + ')'
|
||||
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
|
||||
cur.execute(SQL_count_poly)
|
||||
list_count_poly = cur.fetchall()
|
||||
count_poly = list_count_poly[0][0]
|
||||
|
||||
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")
|
||||
legende.moveLayer(layer_poly,index)
|
||||
|
||||
### Point
|
||||
reqwhere_final_point = '(' + reqwhere_final + " AND GeometryType(geometrie) LIKE '%POINT%'" + ')'
|
||||
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
|
||||
cur.execute(SQL_count_point)
|
||||
list_count_point = cur.fetchall()
|
||||
count_point = list_count_point[0][0]
|
||||
|
||||
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")
|
||||
legende.moveLayer(layer_point,index)
|
||||
|
||||
### Ligne
|
||||
reqwhere_final_ligne = '(' + reqwhere_final + " AND GeometryType(geometrie) LIKE '%LINE%'" + ')'
|
||||
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
|
||||
cur.execute(SQL_count_ligne)
|
||||
list_count_ligne = cur.fetchall()
|
||||
count_ligne = list_count_ligne[0][0]
|
||||
|
||||
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")
|
||||
legende.moveLayer(layer_ligne,index)
|
||||
|
||||
# ajout des couches dans le groupe Observations
|
||||
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)
|
||||
|
||||
|
||||
elif layer.selectedFeatureCount() == 0 :
|
||||
self.iface.messageBar().pushMessage(u"Vous devez sélectionner au moins un polygone !", level=QgsMessageBar.WARNING, duration=5)
|
||||
reqwhere_geom = ''
|
||||
|
||||
else :
|
||||
self.iface.messageBar().pushMessage(u"Vous devez sélectionner qu'un seul polygone !", level=QgsMessageBar.WARNING, duration=5)
|
||||
reqwhere_geom = ''
|
||||
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
|
||||
|
||||
# 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' :
|
||||
reqwhere_final = reqwhere_final[:-3]
|
||||
while reqwhere_final[:5] == '()AND' :
|
||||
reqwhere_final = reqwhere_final[5:]
|
||||
while reqwhere_final[-5:] == 'AND()' :
|
||||
reqwhere_final = reqwhere_final[:-5]
|
||||
while reqwhere_final[:3] == 'AND' :
|
||||
reqwhere_final = reqwhere_final[3:]
|
||||
|
||||
## Affichage des tables
|
||||
table_name = 'observations'
|
||||
|
||||
uri = QgsDataSourceURI()
|
||||
uri.setConnection(host ,port ,dbname ,user ,password)
|
||||
|
||||
## 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 :
|
||||
con = psycopg2.connect("dbname="+ dbname + " user=" + user + " host=" + host + " password=" + password + " port=" + port)
|
||||
cur = con.cursor()
|
||||
|
||||
# Creation group de couches
|
||||
i = qgis.utils.iface
|
||||
legende = i.legendInterface()
|
||||
nomgroupe = 'Observations'
|
||||
groupe = legende.addGroup(nomgroupe,False)
|
||||
|
||||
# Récupération de la liste de groupes
|
||||
toc = qgis.utils.iface.legendInterface()
|
||||
groups = toc.groups()
|
||||
index = groups.index(nomgroupe)
|
||||
|
||||
### Polygone
|
||||
reqwhere_final_poly = '(' + reqwhere_final + " AND GeometryType(geometrie) LIKE '%POLYGON%'" + ')'
|
||||
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
|
||||
cur.execute(SQL_count_poly)
|
||||
list_count_poly = cur.fetchall()
|
||||
count_poly = list_count_poly[0][0]
|
||||
|
||||
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")
|
||||
legende.moveLayer(layer_poly,index)
|
||||
|
||||
### Point
|
||||
reqwhere_final_point = '(' + reqwhere_final + " AND GeometryType(geometrie) LIKE '%POINT%'" + ')'
|
||||
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
|
||||
cur.execute(SQL_count_point)
|
||||
list_count_point = cur.fetchall()
|
||||
count_point = list_count_point[0][0]
|
||||
|
||||
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")
|
||||
legende.moveLayer(layer_point,index)
|
||||
|
||||
### Ligne
|
||||
reqwhere_final_ligne = '(' + reqwhere_final + " AND GeometryType(geometrie) LIKE '%LINE%'" + ')'
|
||||
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
|
||||
cur.execute(SQL_count_ligne)
|
||||
list_count_ligne = cur.fetchall()
|
||||
count_ligne = list_count_ligne[0][0]
|
||||
|
||||
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")
|
||||
legende.moveLayer(layer_ligne,index)
|
||||
|
||||
# ajout des couches dans le groupe Observations
|
||||
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)
|
||||
|
||||
pass
|
||||
|
||||
def export(self):
|
||||
|
||||
### 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)
|
||||
|
||||
layer = self.iface.activeLayer()
|
||||
|
||||
if layer == None :
|
||||
self.iface.messageBar().pushMessage(u"Vous devez sélectionner une table !", level=QgsMessageBar.WARNING, duration=5)
|
||||
|
||||
else :
|
||||
selection = layer.selectedFeatures()
|
||||
if (layer.selectedFeatureCount() == 1) :
|
||||
for feature in selection:
|
||||
geom = feature.geometry()
|
||||
poly = geom.exportToWkt()
|
||||
|
||||
buffer = '100'
|
||||
|
||||
con = psycopg2.connect("dbname="+ dbname + " user=" + user + " host=" + host + " password=" + password + " port=" + port)
|
||||
cur = con.cursor()
|
||||
|
||||
SQL_list_sp = u"""SELECT DISTINCT classe::text, ordre::text, nom_complet::text, nom_vern::text, max(date_obs)::text AS derniere_obs FROM _agregation_ra.observations_table WHERE ST_intersects(geometrie,ST_Buffer(ST_geomFromText('""" + poly + "',2154), " + buffer + " )) GROUP BY classe, ordre, nom_complet, nom_vern ORDER BY nom_vern"""
|
||||
cur.execute(SQL_list_sp)
|
||||
data_sp = cur.fetchall()
|
||||
|
||||
chemin_fichier = QFileDialog.getSaveFileName(None, 'Enregistrer sous...', "C:\Users\\" + str(os.environ.get("USERNAME")) + '\Desktop\liste_sp.csv', "Fichiers CSV (*.csv)")
|
||||
file = open(chemin_fichier, 'wb')
|
||||
file.write(u'\ufeff'.encode('utf8')) # BOM (optionel...Permet a Excel d'ouvrir proprement le fichier en UTF-8)
|
||||
writer = csv.writer(file, delimiter = ';') # délimiteur ';' pour faciliter l'ouverture avec Excel
|
||||
writer.writerow(['Classe', 'Ordre', 'Nom Complet', 'Nom Vernaculaire', u'Date Derniere Observation']) # Création des entêtes
|
||||
|
||||
for row in data_sp : # Boucle d'écriture ligne par ligne dans le csv
|
||||
list_sp = []
|
||||
if row[0] == None : # Si la valeur est 'None' l'encodage ne peut se faire donc boucle d'évitement
|
||||
row0 = str(row[0])
|
||||
row0 = ''
|
||||
else :
|
||||
row0 = row[0]
|
||||
list_sp.append(row0.encode('utf-8'))
|
||||
if row[1] == None : # Si la valeur est 'None' l'encodage ne peut se faire donc boucle d'évitement
|
||||
row1 = str(row[1])
|
||||
row1 = ''
|
||||
else :
|
||||
row1 = row[1]
|
||||
list_sp.append(row1.encode('utf-8'))
|
||||
if row[2] == None : # Si la valeur est 'None' l'encodage ne peut se faire donc boucle d'évitement
|
||||
row2 = str(row[2])
|
||||
row2 = ''
|
||||
else :
|
||||
row2 = row[2]
|
||||
list_sp.append(row2.encode('utf-8'))
|
||||
if row[3] == None : # Si la valeur est 'None' l'encodage ne peut se faire donc boucle d'évitement
|
||||
row3 = str(row[3])
|
||||
row3 = ''
|
||||
else :
|
||||
row3 = row[3]
|
||||
list_sp.append(row3.encode('utf-8'))
|
||||
if row[4] == None :
|
||||
row4 = str(row[4])
|
||||
row4 = ''
|
||||
else :
|
||||
row4 = row[4]
|
||||
list_sp.append(row4.encode('utf-8'))
|
||||
writer.writerow(list_sp)
|
||||
|
||||
file.close()
|
||||
self.iface.messageBar().pushMessage(u"Export réussi dans " + chemin_fichier , level=QgsMessageBar.INFO, duration=5)
|
||||
|
||||
elif (layer.selectedFeatureCount() == 0) :
|
||||
self.iface.messageBar().pushMessage(u"Vous devez sélectionner au moins un polygone !", level=QgsMessageBar.WARNING, duration=5)
|
||||
|
||||
else :
|
||||
self.iface.messageBar().pushMessage(u"Vous devez sélectionner qu'un seul polygone !", level=QgsMessageBar.WARNING, duration=5)
|
||||
Reference in New Issue
Block a user