Fix Z/M dimension URI via DB Manager. Fixes #34894 (#45223)

This commit is contained in:
Loïc Bartoletti 2021-09-28 21:14:45 +02:00 committed by GitHub
parent 644dfcf8ea
commit 98ff01ea1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -308,6 +308,24 @@ class PGVectorTable(PGTable, VectorTable):
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):

View File

@ -159,7 +159,7 @@ class DBTree(QTreeView):
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(