diff --git a/python/plugins/db_manager/db_plugins/postgis/plugin.py b/python/plugins/db_manager/db_plugins/postgis/plugin.py index f710997c00c6..43595c2e0778 100644 --- a/python/plugins/db_manager/db_plugins/postgis/plugin.py +++ b/python/plugins/db_manager/db_plugins/postgis/plugin.py @@ -308,6 +308,24 @@ def runAction(self, action): return True return VectorTable.runAction(self, action) + def geometryType(self): + """ Returns the proper WKT type. + PostGIS records type like this: + | WKT Type | geomType | geomDim | + |--------------|-------------|---------| + | LineString | LineString | 2 | + | LineStringZ | LineString | 3 | + | LineStringM | LineStringM | 3 | + | LineStringZM | LineString | 4 | + """ + geometryType = self.geomType + if self.geomDim == 3 and self.geomType[-1] != "M": + geometryType += "Z" + elif self.geomDim == 4: + geometryType += "ZM" + + return geometryType + class PGRasterTable(PGTable, RasterTable): diff --git a/python/plugins/db_manager/db_tree.py b/python/plugins/db_manager/db_tree.py index 87a0bd7727ec..97a4f3e4824c 100644 --- a/python/plugins/db_manager/db_tree.py +++ b/python/plugins/db_manager/db_tree.py @@ -159,7 +159,7 @@ def delete(self): def addLayer(self): table = self.currentTable() if table is not None: - layer = table.toMapLayer() + layer = table.toMapLayer(table.geometryType()) layers = QgsProject.instance().addMapLayers([layer]) if len(layers) != 1: QgsMessageLog.logMessage(