Skip to content

Commit 83c8b5b

Browse files
authoredJun 12, 2019
Merge pull request #30173 from olivierdalang/dbmanager_fix_generic_geom
[dbmanager] allow to import GEOMETRY tables
2 parents 4ff8429 + 86f8bdb commit 83c8b5b

File tree

1 file changed

+31
-3
lines changed
  • python/plugins/db_manager/db_plugins

1 file changed

+31
-3
lines changed
 

‎python/plugins/db_manager/db_plugins/plugin.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
Qgis,
3232
QgsApplication,
3333
QgsSettings,
34-
QgsMapLayerType
34+
QgsMapLayerType,
35+
QgsWkbTypes
3536
)
3637
from ..db_plugins import createDbPlugin
3738

@@ -522,8 +523,28 @@ def rasterTablesFactory(self, row, db, schema=None):
522523
def tables(self, schema=None, sys_tables=False):
523524
tables = self.connector.getTables(schema.name if schema else None, sys_tables)
524525
if tables is not None:
525-
tables = [self.tablesFactory(x, self, schema) for x in tables]
526-
return tables
526+
ret = []
527+
for t in tables:
528+
table = self.tablesFactory(t, self, schema)
529+
ret.append(table)
530+
531+
# Similarly to what to browser does, if the geom type is generic geometry,
532+
# we additionnly add three copies of the layer to allow importing
533+
if isinstance(table, VectorTable):
534+
if table.geomType == 'GEOMETRY':
535+
point_table = self.tablesFactory(t, self, schema)
536+
point_table.geomType = 'POINT'
537+
ret.append(point_table)
538+
539+
line_table = self.tablesFactory(t, self, schema)
540+
line_table.geomType = 'LINESTRING'
541+
ret.append(line_table)
542+
543+
poly_table = self.tablesFactory(t, self, schema)
544+
poly_table.geomType = 'POLYGON'
545+
ret.append(poly_table)
546+
547+
return ret
527548

528549
def createTable(self, table, fields, schema=None):
529550
field_defs = [x.definition() for x in fields]
@@ -692,6 +713,13 @@ def uri(self):
692713
geomCol = self.geomColumn if self.type in [Table.VectorType, Table.RasterType] else ""
693714
uniqueCol = self.getValidQgisUniqueFields(True) if self.isView else None
694715
uri.setDataSource(schema, self.name, geomCol if geomCol else None, None, uniqueCol.name if uniqueCol else "")
716+
uri.setSrid(str(self.srid))
717+
for f in self.fields():
718+
if f.primaryKey:
719+
uri.setKeyColumn(f.name)
720+
break
721+
uri.setWkbType(QgsWkbTypes.parseType(self.geomType))
722+
695723
return uri
696724

697725
def mimeUri(self):

0 commit comments

Comments
 (0)
Please sign in to comment.