From 2538612a21aa0d4b2812b8085250392d15820044 Mon Sep 17 00:00:00 2001 From: Andrea Giudiceandrea Date: Fri, 23 Apr 2021 08:14:57 +0200 Subject: [PATCH 1/2] =?UTF-8?q?[DB=20Manager]=20Fix=20recognition=20of=20p?= =?UTF-8?q?roject=20layers=20with=20Z/M=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …or CurvePolygon/MultyCurve/... geometry types as spatial layers. --- .../db_plugins/vlayers/connector.py | 53 +++++-------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/python/plugins/db_manager/db_plugins/vlayers/connector.py b/python/plugins/db_manager/db_plugins/vlayers/connector.py index 20c604b0642..e6ff502b9b4 100644 --- a/python/plugins/db_manager/db_plugins/vlayers/connector.py +++ b/python/plugins/db_manager/db_plugins/vlayers/connector.py @@ -215,45 +215,20 @@ class VLayerConnector(DBConnector): geomType = None dim = None - g = l.dataProvider().wkbType() - if g == QgsWkbTypes.Point: - geomType = 'POINT' - dim = 'XY' - elif g == QgsWkbTypes.LineString: - geomType = 'LINESTRING' - dim = 'XY' - elif g == QgsWkbTypes.Polygon: - geomType = 'POLYGON' - dim = 'XY' - elif g == QgsWkbTypes.MultiPoint: - geomType = 'MULTIPOINT' - dim = 'XY' - elif g == QgsWkbTypes.MultiLineString: - geomType = 'MULTILINESTRING' - dim = 'XY' - elif g == QgsWkbTypes.MultiPolygon: - geomType = 'MULTIPOLYGON' - dim = 'XY' - elif g == QgsWkbTypes.Point25D: - geomType = 'POINT' - dim = 'XYZ' - elif g == QgsWkbTypes.LineString25D: - geomType = 'LINESTRING' - dim = 'XYZ' - elif g == QgsWkbTypes.Polygon25D: - geomType = 'POLYGON' - dim = 'XYZ' - elif g == QgsWkbTypes.MultiPoint25D: - geomType = 'MULTIPOINT' - dim = 'XYZ' - elif g == QgsWkbTypes.MultiLineString25D: - geomType = 'MULTILINESTRING' - dim = 'XYZ' - elif g == QgsWkbTypes.MultiPolygon25D: - geomType = 'MULTIPOLYGON' - dim = 'XYZ' - lst.append( - (Table.VectorType, lname, False, False, l.id(), 'geometry', geomType, dim, l.crs().postgisSrid())) + if l.isSpatial(): + g = l.dataProvider().wkbType() + g_flat = QgsWkbTypes.flatType(g) + geomType = QgsWkbTypes.displayString(g_flat).upper() + if geomType: + dim = 'XY' + if QgsWkbTypes.hasZ(g): + dim += 'Z' + if QgsWkbTypes.hasM(g): + dim += 'M' + lst.append( + (Table.VectorType, lname, False, False, l.id(), 'geometry', geomType, dim, l.crs().postgisSrid())) + else: + lst.append((Table.TableType, lname, False, False)) return lst def getRasterTables(self, schema=None): From 828638f6614c5b34d673b4e837d6120d9cc9d35c Mon Sep 17 00:00:00 2001 From: Andrea Giudiceandrea Date: Fri, 23 Apr 2021 08:25:14 +0200 Subject: [PATCH 2/2] [DB Manager] Fix No Geometry tables Avoid to add a nonexistent 'geometry' field to the fields list of No Geometry tables. --- python/plugins/db_manager/db_plugins/vlayers/connector.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/plugins/db_manager/db_plugins/vlayers/connector.py b/python/plugins/db_manager/db_plugins/vlayers/connector.py index e6ff502b9b4..2ad1de1d184 100644 --- a/python/plugins/db_manager/db_plugins/vlayers/connector.py +++ b/python/plugins/db_manager/db_plugins/vlayers/connector.py @@ -251,7 +251,8 @@ class VLayerConnector(DBConnector): n = l.dataProvider().fields().size() f = [(i, f.name(), f.typeName(), False, None, False) for i, f in enumerate(l.dataProvider().fields())] - f += [(n, "geometry", "geometry", False, None, False)] + if l.isSpatial(): + f += [(n, "geometry", "geometry", False, None, False)] return f def getTableIndexes(self, table):