Skip to content

Commit

Permalink
Add WKB geometry type to exported table
Browse files Browse the repository at this point in the history
  • Loading branch information
effjot committed Jan 22, 2024
1 parent 57fb660 commit 40cdbfd
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 37 deletions.
4 changes: 2 additions & 2 deletions data_sources_panel/dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, data: LayerSources):
def data(self, index, role):
if role == Qt.DisplayRole:
src = self._data.by_index(index.row())
item = src.by_index(index.column() + 1) # skip layerid field
item = src.by_index(index.column() + 2) # skip layerid and geom_type fields
if index.column() == 2:
return nice_provider_name(item)
return str(item)
Expand All @@ -71,7 +71,7 @@ def rowCount(self, index):
return self._data.num_layers()

def columnCount(self, index):
return self._data.num_fields() - 2 # skip layerid, icon fields
return self._data.num_fields() - 3 # skip layerid, geom_type, icon fields

def headerData(self, index, orientation, role):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
Expand Down
70 changes: 40 additions & 30 deletions data_sources_panel/i18n/data_sources_panel_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,137 +14,137 @@
<translation>Layer</translation>
</message>
<message>
<location filename="../layer_sources.py" line="195"/>
<location filename="../layer_sources.py" line="207"/>
<source>Provider</source>
<translation>Datenanbieter</translation>
</message>
<message>
<location filename="../layer_sources.py" line="195"/>
<location filename="../layer_sources.py" line="207"/>
<source>Storage Location</source>
<translation>Speicherort</translation>
</message>
<message>
<location filename="../dockwidget.py" line="540"/>
<location filename="../dockwidget.py" line="553"/>
<source>Data Sources</source>
<translation>Datenquellen</translation>
</message>
<message>
<location filename="../dockwidget.py" line="413"/>
<location filename="../dockwidget.py" line="426"/>
<source>&amp;Table View</source>
<translation>&amp;Tabellenansicht</translation>
</message>
<message>
<location filename="../dockwidget.py" line="416"/>
<location filename="../dockwidget.py" line="429"/>
<source>T&amp;ree View</source>
<translation>&amp;Baumansicht</translation>
</message>
<message>
<location filename="../dockwidget.py" line="419"/>
<location filename="../dockwidget.py" line="432"/>
<source>&amp;Expand All</source>
<translation>Alle &amp;ausklappen</translation>
</message>
<message>
<location filename="../dockwidget.py" line="422"/>
<location filename="../dockwidget.py" line="435"/>
<source>&amp;Collapse All</source>
<translation>Alle &amp;einklappen</translation>
</message>
<message>
<location filename="../dockwidget.py" line="428"/>
<location filename="../dockwidget.py" line="441"/>
<source>Export</source>
<translation>Export</translation>
</message>
<message>
<location filename="../dockwidget.py" line="431"/>
<location filename="../dockwidget.py" line="444"/>
<source>Export as &amp;Excel file</source>
<translation>Als &amp;Excel-Datei exportieren</translation>
</message>
<message>
<location filename="../dockwidget.py" line="433"/>
<location filename="../dockwidget.py" line="446"/>
<source>Export as &amp;CSV file</source>
<translation>Als &amp;CSV-Datei exportieren</translation>
</message>
<message>
<location filename="../dockwidget.py" line="543"/>
<location filename="../dockwidget.py" line="556"/>
<source>Comma Separated Values (*.csv)</source>
<translation>CSV (Komma-getrennte Werte)</translation>
</message>
<message>
<location filename="../dockwidget.py" line="544"/>
<location filename="../dockwidget.py" line="557"/>
<source>Excel workbook (*.xlsx)</source>
<translation>Excel-Arbeitsmappe (*.xlsx)</translation>
</message>
<message>
<location filename="../dockwidget.py" line="548"/>
<location filename="../dockwidget.py" line="561"/>
<source>Export Data Sources Table</source>
<translation>Datenquellen-Tabelle exportieren</translation>
</message>
<message>
<location filename="../dockwidget.py" line="553"/>
<location filename="../dockwidget.py" line="566"/>
<source>Export cancelled</source>
<translation>Export abgebrochen</translation>
</message>
<message>
<location filename="../dockwidget.py" line="565"/>
<location filename="../dockwidget.py" line="578"/>
<source>Data sources table successfully exported to {output_file}</source>
<translation>Datenquellen-Tabelle erfolgreich nach {output_file} exportiert</translation>
</message>
<message>
<location filename="../dockwidget.py" line="573"/>
<location filename="../dockwidget.py" line="586"/>
<source>Export to {output_file} failed: {error} {message}</source>
<translation>Export nach {output_file} fehlgeschlagen: {error} {message}</translation>
</message>
<message>
<location filename="../layer_sources.py" line="149"/>
<location filename="../layer_sources.py" line="155"/>
<source>(unknown)</source>
<translation>(unbekannt)</translation>
</message>
<message>
<location filename="../layer_sources.py" line="195"/>
<location filename="../layer_sources.py" line="207"/>
<source>layerid</source>
<translation>layerid</translation>
</message>
<message>
<location filename="../layer_sources.py" line="195"/>
<location filename="../layer_sources.py" line="207"/>
<source>Name</source>
<translation>Name</translation>
</message>
<message>
<location filename="../layer_sources.py" line="224"/>
<location filename="../layer_sources.py" line="237"/>
<source>WMS/WMTS</source>
<translation>WMS/WMTS</translation>
</message>
<message>
<location filename="../layer_sources.py" line="225"/>
<location filename="../layer_sources.py" line="238"/>
<source>WFS</source>
<translation>WFS</translation>
</message>
<message>
<location filename="../layer_sources.py" line="226"/>
<location filename="../layer_sources.py" line="239"/>
<source>PostgreSQL</source>
<translation>PostgreSQL</translation>
</message>
<message>
<location filename="../layer_sources.py" line="227"/>
<location filename="../layer_sources.py" line="240"/>
<source>PostgreSQL Raster</source>
<translation>PostgreSQL-Raster</translation>
</message>
<message>
<location filename="../layer_sources.py" line="228"/>
<location filename="../layer_sources.py" line="241"/>
<source>SpatiaLite</source>
<translation>SpatiaLite</translation>
</message>
<message>
<location filename="../layer_sources.py" line="229"/>
<location filename="../layer_sources.py" line="242"/>
<source>Memory / Scratch Layer</source>
<translation>Temporärlayer</translation>
</message>
<message>
<location filename="../layer_sources.py" line="133"/>
<location filename="../layer_sources.py" line="139"/>
<source>DB</source>
<translation>DB</translation>
</message>
<message>
<location filename="../layer_sources.py" line="133"/>
<location filename="../layer_sources.py" line="139"/>
<source>Schema</source>
<translation>Schema</translation>
</message>
Expand All @@ -154,20 +154,30 @@
<translation>&amp;Datenquellen</translation>
</message>
<message>
<location filename="../layer_sources.py" line="222"/>
<location filename="../layer_sources.py" line="235"/>
<source>Vector Files (OGR)</source>
<translation>Vektordateien (OGR)</translation>
</message>
<message>
<location filename="../layer_sources.py" line="223"/>
<location filename="../layer_sources.py" line="236"/>
<source>Raster Files (GDAL)</source>
<translation>Rasterdateien (GDAL)</translation>
</message>
<message>
<location filename="../layer_sources.py" line="195"/>
<location filename="../layer_sources.py" line="207"/>
<source>CRS</source>
<translation>KBS</translation>
</message>
<message>
<location filename="../layer_sources.py" line="65"/>
<source>no CRS</source>
<translation>kein KBS</translation>
</message>
<message>
<location filename="../layer_sources.py" line="207"/>
<source>Geometry (WKB type)</source>
<translation>Geometrie (WKB-Typ)</translation>
</message>
</context>
<context>
<name>DataSourceDockWidget</name>
Expand Down
22 changes: 18 additions & 4 deletions data_sources_panel/layer_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
QgsMessageLog,
QgsProject,
QgsProviderRegistry,
QgsRasterLayer,
QgsVectorLayer,
QgsVectorLayerUtils
QgsVectorLayerUtils,
QgsWkbTypes
)
from qgis.PyQt.QtCore import QVariant
from qgis.PyQt.QtGui import QIcon
Expand Down Expand Up @@ -51,12 +53,17 @@ def __str__(self):
@dataclass
class LayerSource:
layerid: str
geom_type: str
name: str
crs_authid: str
provider: str
location: StorageLocation
icon: QIcon

def __post_init__(self):
if not self.crs_authid and self.geom_type != 'NoGeometry':
self.crs_authid = tr('no CRS')

def num_fields(self):
return len(fields(self))

Expand Down Expand Up @@ -148,9 +155,15 @@ def get_source_from_layer(self, layer, layerid: str = None):
location = StorageLocation(None, tr('(unknown)'))
icon = QgsIconUtils.iconForLayer(
QgsProject.instance().mapLayer(layerid))
if isinstance(layer, QgsVectorLayer):
geom_type = QgsWkbTypes.displayString(layer.wkbType())
elif isinstance(layer, QgsRasterLayer):
geom_type = 'Raster'
else:
geom_type = ''
crs_authid = provider.crs().authid()
return LayerSource(
layerid=layerid, name=layer.name(), crs_authid=crs_authid,
layerid=layerid, name=layer.name(), geom_type=geom_type, crs_authid=crs_authid,
provider=provider_name, location=location, icon=icon)

def num_layers(self) -> int:
Expand Down Expand Up @@ -194,6 +207,7 @@ def as_memory_layer(self, name: str = 'Data Sources'):
prov.addAttributes([
QgsField(tr('layerid'), QVariant.String),
QgsField(tr('Name'), QVariant.String),
QgsField(tr('Geometry (WKB type)'), QVariant.String),
QgsField(tr('CRS'), QVariant.String),
QgsField(tr('Provider'), QVariant.String),
QgsField(tr('Storage Location'), QVariant.String)
Expand All @@ -202,8 +216,8 @@ def as_memory_layer(self, name: str = 'Data Sources'):
features = [
QgsVectorLayerUtils.createFeature(
mem_layer, QgsGeometry(), {
0: src.layerid, 1: src.name, 2: src.crs_authid,
3: nice_provider_name(src.provider), 4: str(src.location)
0: src.layerid, 1: src.name, 2: src.geom_type, 3: src.crs_authid,
4: nice_provider_name(src.provider), 5: str(src.location)
})
for src in self.sources
]
Expand Down
2 changes: 1 addition & 1 deletion data_sources_panel/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repository=https://github.com/effjot/qgis-data-sources-panel
hasProcessingProvider=no
# Uncomment the following line and add your changelog:
changelog=
0.2.1 Show CRS info, updated documentation
0.2.1 Show CRS info, export geometry type, updated documentation
0.2.0 German translation, other small improvements
0.1.0 Initial experimental release

Expand Down

0 comments on commit 40cdbfd

Please sign in to comment.