diff --git a/CenRa_FLUX/flux_editor.py b/CenRa_FLUX/flux_editor.py index 18db1d6..ec2abed 100644 --- a/CenRa_FLUX/flux_editor.py +++ b/CenRa_FLUX/flux_editor.py @@ -22,6 +22,7 @@ except: from qgis.core import * from qgis.core import QgsDataSourceUri +from qgis.PyQt.QtSvg import QSvgWidget from qgis.PyQt.QtWidgets import ( QDialog, QAction, @@ -455,6 +456,13 @@ var Travaux = L.geoJSON(TravauxJSON,{ cur.execute(custom_list) list_schema = cur.fetchall() + SQLraster = """SELECT concat(r_table_schema,'.',r_table_name) from public.raster_columns; """ + cur.execute(SQLraster) + list_raster = cur.fetchall() + RasterList = [] + for rasterFind in list_raster: + RasterList.append(rasterFind[0]) + self.tableWidget.setRowCount(len(list_schema)) self.tableWidget.setColumnCount(3) i=0 @@ -483,12 +491,24 @@ var Travaux = L.geoJSON(TravauxJSON,{ schema_name=str(value[0]) table_name=str(value[1]) elif type_val != '00' and type_val != '01' and type_val != '07' and type_val != '26' and type_val != '42' and type_val != '69' and type_val != 'ra': - type_val='agregation' + if dbtype == refdb: + if (schema_name+'.'+table_name) in RasterList: + SVG = 'mIconRaster.svg' + else: + SVG = 'mIconWfs.svg' + svgWidget = QSvgWidget(resources_path('icons',SVG)) + else: + type_val='agregation' schema_name=str(value[0]) table_name=str(value[1]) item = QTableWidgetItem(type_val) - self.tableWidget.setItem(i,0,item) + if dbtype == refdb: + self.tableWidget.setCellWidget(i,0,svgWidget) + self.tableWidget.setItem(i,0,QTableWidgetItem('')) + else: + self.tableWidget.setCellWidget(i,0,None) + self.tableWidget.setItem(i,0,item) item = QTableWidgetItem(schema_name) self.tableWidget.setItem(i,1,item) item = QTableWidgetItem(table_name) @@ -504,6 +524,7 @@ var Travaux = L.geoJSON(TravauxJSON,{ selected_items = self.tableWidget.selectedItems() # Assuming you want to compare items in the first column for uniqueness + svgTake = (selected_items[2].tableWidget().cellWidget(0,0)) new_item_text = selected_items[2].text() if not self.item_already_exists(new_item_text): @@ -547,10 +568,17 @@ var Travaux = L.geoJSON(TravauxJSON,{ def openPostGIS(self,schema,table): uri = QgsDataSourceUri() uri.setConnection(host ,port ,sigdb ,user ,mdp) - uri.setDataSource(schema, table, "geom") - uri.setKeyColumn('gid') - uri.setSrid('2154') - layer = QgsVectorLayer(uri.uri(), table, "postgres") + + if (schema+'.'+table) in RasterList: + uri.setDataSource(schema, table, "rast") + uri.setKeyColumn('rid') + uri.setSrid('2154') + layer = QgsRasterLayer(uri.uri(), table, "postgresraster") + else: + uri.setDataSource(schema, table, "geom") + uri.setKeyColumn('gid') + uri.setSrid('2154') + layer = QgsVectorLayer(uri.uri(), table, "postgres") # Ajout de la couche au canevas QGIS QgsProject.instance().addMapLayer(layer) @@ -574,6 +602,13 @@ var Travaux = L.geoJSON(TravauxJSON,{ def displayOnWindows(type, uri, name): p = [] + SQLraster = """SELECT concat(r_table_schema,'.',r_table_name) from public.raster_columns; """ + cur.execute(SQLraster) + list_raster = cur.fetchall() + RasterList = [] + for rasterFind in list_raster: + RasterList.append(rasterFind[0]) + for row in range(0, self.tableWidget_2.rowCount()): color_rgba = 855030089 if self.tableWidget_2.item(row, 0).background().color().rgba() != 855030089: @@ -596,36 +631,43 @@ var Travaux = L.geoJSON(TravauxJSON,{ # nom du schéma à remplacer: "hydrographie" à supprimer et mettre "couches_collaboratives" lorsqu'on aura regroupé les couches à modifier dans un même schéma - uri.setDataSource(schema, table, "geom") - uri.setKeyColumn('gid') - - # Chargement de la couche PostGIS - geom_type ='SELECT right(st_geometrytype(geom),-3) as a FROM '+schema+'.'+table+' GROUP BY a' - cur.execute(geom_type) - list_typegeom = cur.fetchall() - if len(list_typegeom) > 1: - for typegeom in list_typegeom: - if typegeom[0] == 'MultiPolygon': - uri.setWkbType(QgsWkbTypes.MultiPolygon) - elif typegeom[0] == 'MultiLineString': - uri.setWkbType(QgsWkbTypes.MultiLineString) - elif typegeom[0] == 'Point': - uri.setWkbType(QgsWkbTypes.Point) - if typegeom[0] == 'Polygon': - uri.setWkbType(QgsWkbTypes.Polygon) - elif typegeom[0] == 'LineString': - uri.setWkbType(QgsWkbTypes.LineString) - elif typegeom[0] == 'MultiPoint': - uri.setWkbType(QgsWkbTypes.MultiPoint) - if (typegeom[0] != None and typegeom[0] != 'Polygon'): - uri.setSrid('2154') - layer = QgsVectorLayer(uri.uri(), table, "postgres") - # Ajout de la couche au canevas QGIS - QgsProject.instance().addMapLayer(layer) - else: - layer = QgsVectorLayer(uri.uri(), table, "postgres") - # Ajout de la couche au canevas QGIS + if (schema+'.'+table) in RasterList: + uri.setDataSource(schema, table, "rast") + uri.setKeyColumn('rid') + uri.setSrid('2154') + layer = QgsRasterLayer(uri.uri(), table, "postgresraster") QgsProject.instance().addMapLayer(layer) + else: + uri.setDataSource(schema, table, "geom") + uri.setKeyColumn('gid') + + # Chargement de la couche PostGIS + geom_type ='SELECT right(st_geometrytype(geom),-3) as a FROM '+schema+'.'+table+' GROUP BY a' + cur.execute(geom_type) + list_typegeom = cur.fetchall() + if len(list_typegeom) > 1: + for typegeom in list_typegeom: + if typegeom[0] == 'MultiPolygon': + uri.setWkbType(QgsWkbTypes.MultiPolygon) + elif typegeom[0] == 'MultiLineString': + uri.setWkbType(QgsWkbTypes.MultiLineString) + elif typegeom[0] == 'Point': + uri.setWkbType(QgsWkbTypes.Point) + if typegeom[0] == 'Polygon': + uri.setWkbType(QgsWkbTypes.Polygon) + elif typegeom[0] == 'LineString': + uri.setWkbType(QgsWkbTypes.LineString) + elif typegeom[0] == 'MultiPoint': + uri.setWkbType(QgsWkbTypes.MultiPoint) + if (typegeom[0] != None and typegeom[0] != 'Polygon'): + uri.setSrid('2154') + layer = QgsVectorLayer(uri.uri(), table, "postgres") + # Ajout de la couche au canevas QGIS + QgsProject.instance().addMapLayer(layer) + else: + layer = QgsVectorLayer(uri.uri(), table, "postgres") + # Ajout de la couche au canevas QGIS + QgsProject.instance().addMapLayer(layer) else: self.QMBquestion = QMessageBox.question(iface.mainWindow(), u"Attention !","La couche «" + str(self.tableWidget_2.item(row,1).text()) +' '+ str(self.tableWidget_2.item(row,2).text()) + "» ne ce trouve pas dans cette BD !",QMessageBox.StandardButton(0x00004000)) def combobox_custom(self): diff --git a/CenRa_FLUX/tools/icons/mIconRaster.svg b/CenRa_FLUX/tools/icons/mIconRaster.svg new file mode 100644 index 0000000..f7ef960 --- /dev/null +++ b/CenRa_FLUX/tools/icons/mIconRaster.svg @@ -0,0 +1,230 @@ + + + + + GIS icon theme 0.2 + + + + + + + + + + + + + + + + image/svg+xml + + GIS icon theme 0.2 + + + Robert Szczepanek + + + + + Robert Szczepanek + + + + + GIS icons + + + GIS icons + http://robert.szczepanek.pl/ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CenRa_FLUX/tools/icons/mIconWfs.svg b/CenRa_FLUX/tools/icons/mIconWfs.svg new file mode 100644 index 0000000..0e0014b --- /dev/null +++ b/CenRa_FLUX/tools/icons/mIconWfs.svg @@ -0,0 +1,312 @@ + + + + + GIS icon theme 0.2 + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + GIS icon theme 0.2 + + + Robert Szczepanek + + + + + Robert Szczepanek + + + + + GIS icons + + + GIS icons + http://robert.szczepanek.pl/ + + + + + + + + + + + + + + + + + + + + + + + + + + + +