fonction de filtre par empris du canva QGIS

This commit is contained in:
Tom LAVEILLE 2025-02-05 14:33:42 +01:00
parent 80a563357d
commit a90a45a0b9
4 changed files with 66 additions and 23 deletions

View File

@ -160,6 +160,7 @@ class Flux_Editor(QDialog, EDITOR_CLASS):
def initialisation_flux(self):
if dbtype == sigdb:
# self.toolButton.setEnabled(1)
if self.comboBox.currentText() == 'toutes les catégories':
custom_list=schemaname_list
elif self.comboBox.currentText() == 'travaux':
@ -184,7 +185,11 @@ class Flux_Editor(QDialog, EDITOR_CLASS):
if dbtype == sigdb:
type_val = str(value[0])[1:3]
schema_name=str(value[0])[4:]
table_name=str(value[1])
table_name=str(value[1][len(value[0])+1:])
if value[0] == value[1][:len(value[0])]:
table_name=str(value[1][len(value[0])+1:])
else:
table_name=str(value[1])
else:
type_val = ''
schema_name=str(value[0])
@ -192,7 +197,10 @@ class Flux_Editor(QDialog, EDITOR_CLASS):
if type_val == 'fo':
type_val=str(value[0])[1:5]
schema_name=str(value[0])[6:]
table_name=str(value[1])
if value[0] == value[1][:len(value[0])]:
table_name=str(value[1][len(value[0])+1:])
else:
table_name=str(value[1])
elif type_val == 'ra':
type_val='travaux'
schema_name=str(value[0])
@ -285,7 +293,10 @@ class Flux_Editor(QDialog, EDITOR_CLASS):
schema = '_'+code+'_'+self.tableWidget_2.item(row,1).text()
if code == 'travaux' or code == 'agregation':
schema = self.tableWidget_2.item(row,1).text()
table = self.tableWidget_2.item(row,2).text()#.split("?", 1)[0]
table = self.tableWidget_2.item(row,2).text()
else:
table = self.tableWidget_2.item(row,2).text()
table = schema+'_'+table
if dbtype == refdb:
# code = self.tableWidget_2.item(row,0).text()
schema = self.tableWidget_2.item(row,1).text()
@ -302,7 +313,6 @@ class Flux_Editor(QDialog, EDITOR_CLASS):
geom_type ='SELECT right(st_geometrytype(geom),-3) as a FROM '+schema+'.'+table+' GROUP BY a'
cur.execute(geom_type)
list_typegeom = cur.fetchall()
print(len(list_typegeom))
if len(list_typegeom) > 1:
for typegeom in list_typegeom:
if typegeom[0] == 'MultiPolygon':
@ -329,6 +339,7 @@ class Flux_Editor(QDialog, EDITOR_CLASS):
def combobox_custom(self):
if dbtype == sigdb:
self.toolButton.setEnabled(1)
self.comboBox.clear()
self.comboBox.addItem("toutes les catégories")
self.comboBox.addItem('00')
@ -341,6 +352,7 @@ class Flux_Editor(QDialog, EDITOR_CLASS):
self.comboBox.addItem('travaux')
self.comboBox.addItem('form')
if dbtype == refdb:
self.toolButton.setEnabled(0)
custom_list=schemaname_distinct
cur.execute(custom_list)
list_schema = cur.fetchall()
@ -348,8 +360,10 @@ class Flux_Editor(QDialog, EDITOR_CLASS):
self.comboBox.addItem("toutes les catégories")
for baxval in list_schema:
self.comboBox.addItem(baxval[0])
def filtre_dynamique(self, filter_text):
def filtre_dynamique(self, filter_text):
if filter_text.find(' ') >= 0:
filter_text=filter_text.replace(" ","_")
for i in range(self.tableWidget.rowCount()):
for j in range(self.tableWidget.columnCount()):
item = self.tableWidget.item(i, j)
@ -359,19 +373,48 @@ class Flux_Editor(QDialog, EDITOR_CLASS):
break
def getCanevas(self):
print(iface.mapCanvas().extent())
# SQL_EXTENT = ''
# SQL_GEOM = "SELECT f_table_schema,f_table_name FROM geometry_columns WHERE f_geometry_column = 'geom'"
# cur.execute(SQL_GEOM)
# TableHaveGeom = cur.fetchall()
# for e in TableHaveGeom:
# SchemaName = e[0]
# TableName = e[1]
# if SchemaName[0:5] != '_form':
# if SchemaName[0:4] == '_01_' or SchemaName[0:4] == '_42_' or SchemaName[0:4] == '_69_':
# SQL_EXTENT=SQL_EXTENT+"SELECT st_envelope(st_union(geom)),'"+TableName+"' AS table_name FROM "+'"'+SchemaName+'"."'+TableName+'"'+' UNION ALL '
# SQL_EXTENT = SQL_EXTENT[:-11]
# print(SQL_EXTENT)
poly = iface.mapCanvas().extent()
geom = (str(poly.xMinimum())+','+str(poly.yMinimum())+','+str(poly.xMaximum())+','+str(poly.yMaximum()))
SQL_GEOM_CONTOUR = """SELECT DISTINCT tschema,tname FROM "_agregation_ra"."_agreg_contour" WHERE st_intersects(geom,ST_MakeEnvelope("""+geom+",2154)) ORDER BY tname"
SQL_GEOM_HABITAT = """SELECT DISTINCT tschema,tname FROM "_agregation_ra"."_agreg_habitat" WHERE st_intersects(geom,ST_MakeEnvelope("""+geom+",2154)) ORDER BY tname"
SQL_GEOM_EU_HABITAT = """SELECT DISTINCT tschema,tname FROM "_agregation_ra"."_agreg_eu_habitat" WHERE st_intersects(geom,ST_MakeEnvelope("""+geom+",2154)) ORDER BY tname"
SQL_GEOM_TRAVAUX_PREVUS_LIGNE = """SELECT DISTINCT tschema,tname FROM "_agregation_ra"."_agreg_travaux_prevus_ligne" WHERE st_intersects(geom,ST_MakeEnvelope("""+geom+",2154)) ORDER BY tname"
SQL_GEOM_TRAVAUX_PREVUS_POINT = """SELECT DISTINCT tschema,tname FROM "_agregation_ra"."_agreg_travaux_prevus_point" WHERE st_intersects(geom,ST_MakeEnvelope("""+geom+",2154)) ORDER BY tname"
SQL_GEOM_TRAVAUX_PREVUS_POLY = """SELECT DISTINCT tschema,tname FROM "_agregation_ra"."_agreg_travaux_prevus_poly" WHERE st_intersects(geom,ST_MakeEnvelope("""+geom+",2154)) ORDER BY tname"
cur.execute(SQL_GEOM_CONTOUR)
TableContour = cur.fetchall()
cur.execute(SQL_GEOM_HABITAT)
TableHabitat = cur.fetchall()
cur.execute(SQL_GEOM_EU_HABITAT)
TableEuHabitat = cur.fetchall()
cur.execute(SQL_GEOM_TRAVAUX_PREVUS_LIGNE)
TableTravauxLigne = cur.fetchall()
cur.execute(SQL_GEOM_TRAVAUX_PREVUS_POINT)
TableTravauxPoint = cur.fetchall()
cur.execute(SQL_GEOM_TRAVAUX_PREVUS_POLY)
TableTravauxPoly = cur.fetchall()
TableHaveGeom = sorted(TableContour+TableHabitat+TableEuHabitat+TableTravauxLigne+TableTravauxPoint+TableTravauxPoly)
row_count = 0
self.tableWidget.setRowCount(0)
for e in TableHaveGeom:
if e[0][1:3] != 'fo':
DepName = QTableWidgetItem(e[0][1:3])
SchemaName = QTableWidgetItem(e[0][4:])
else:
DepName = QTableWidgetItem('form')
SchemaName = QTableWidgetItem(e[0][6:])
TableName = QTableWidgetItem(e[1][len(e[0])+1:])
self.tableWidget.insertRow(row_count)
self.tableWidget.setItem(row_count,0,DepName)
self.tableWidget.setItem(row_count,1,SchemaName)
self.tableWidget.setItem(row_count,2,TableName)
row_count = row_count+1
if self.lineEdit.text() != 'Recherche par mots-clés':
self.filtre_dynamique(self.lineEdit.text())
def popup(self):
self.dialog = Popup() # +++ - self

View File

@ -6,7 +6,7 @@
name=CenRa_FLUX
qgisMinimumVersion=3.0
description=Permet d'ouvrire une table dans la base PostGis
version=2.2
version=2.3
author=Conservatoire d'Espaces Naturels de Rhône-Alpes
email=si_besoin@cen-rhonealpes.fr
@ -32,7 +32,7 @@ icon=icon.png
# experimental flag
experimental=False
changelog=<h1>CenRA_FLUX:</h1></br><p><h3>07/01/2025 - Version 2.2: </h3> - ByPass du certif ssl ci erreur.</br></p><p><h3>22/10/2024 - Version 2.1:</h3> - Correctif de bug.</br> - Evolution de la limit de 3 à 5. </br></p></br><p><h3>22/10/2024 - Version 2.0:</h3> - Reformatage du code.</br></p></br><p><h3>03/10/2024 - Version 1.14:</h3> - Remonte la fênetre dans la pille.</br></p><p><h3>13/09/2024 - Version 1.13:</h3>- MAJ sur le lien du changelog</br>- Bug-fix: Ouvre MultiPolygone et Polygon séparément.</p></br><p><h3>10/09/2024 - Version 1.11:</h3>- Ouverture de table contenant plusieurs géométries.</p></br><p><h3>26/08/2024 - Version 1.10:</h3>- Ajoute d'un changelog et vérification de mise à jour.</p>
changelog=<h1>CenRA_FLUX:</h1></br><p><h3>05/02/2025 - Version 2.3: </h3> - Bouton de visualisation des couches se trouvent uniquement dans le canva de la carte.</p></br><p><h3>07/01/2025 - Version 2.2: </h3> - ByPass du certif ssl ci erreur.</p></br><p><h3>22/10/2024 - Version 2.1:</h3> - Correctif de bug.</br> - Evolution de la limit de 3 à 5. </br></p></br><p><h3>22/10/2024 - Version 2.0:</h3> - Reformatage du code.</br></p></br><p><h3>03/10/2024 - Version 1.14:</h3> - Remonte la fênetre dans la pille.</br></p><p><h3>13/09/2024 - Version 1.13:</h3>- MAJ sur le lien du changelog</br>- Bug-fix: Ouvre MultiPolygone et Polygon séparément.</p></br><p><h3>10/09/2024 - Version 1.11:</h3>- Ouverture de table contenant plusieurs géométries.</p></br><p><h3>26/08/2024 - Version 1.10:</h3>- Ajoute d'un changelog et vérification de mise à jour.</p>
# deprecated flag (applies to the whole plugin, not just a single version)
deprecated=False

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -51,9 +51,9 @@
<tags>cenra,sicen</tags>
</pyqgis_plugin>
<pyqgis_plugin name="CenRa_FLUX" version="2.2">
<pyqgis_plugin name="CenRa_FLUX" version="2.3">
<description><![CDATA[Dépôt pour les extensiont QGIS du CEN Rhone-Alpes, sur GitHub.]]></description>
<version>2.2</version>
<version>2.3</version>
<qgis_minimum_version>3.16</qgis_minimum_version>
<homepage>https://plateformesig.cenra-outils.org/</homepage>
<file_name>CenRa_FLUX.zip</file_name>
@ -62,7 +62,7 @@
<download_url>https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS/releases/download/latest/CenRa_FLUX.zip</download_url>
<uploaded_by>CEN-Rhone-Alpes</uploaded_by>
<create_date>2024-02-06</create_date>
<update_date>2025-01-07</update_date>
<update_date>2025-02-05</update_date>
<experimental>False</experimental>
<deprecated>False</deprecated>
<tags>cenra,flux</tags>