|
31 | 31 | Qgis,
|
32 | 32 | QgsApplication,
|
33 | 33 | QgsSettings,
|
34 |
| - QgsMapLayerType |
| 34 | + QgsMapLayerType, |
| 35 | + QgsWkbTypes |
35 | 36 | )
|
36 | 37 | from ..db_plugins import createDbPlugin
|
37 | 38 |
|
@@ -522,8 +523,28 @@ def rasterTablesFactory(self, row, db, schema=None):
|
522 | 523 | def tables(self, schema=None, sys_tables=False):
|
523 | 524 | tables = self.connector.getTables(schema.name if schema else None, sys_tables)
|
524 | 525 | 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 |
527 | 548 |
|
528 | 549 | def createTable(self, table, fields, schema=None):
|
529 | 550 | field_defs = [x.definition() for x in fields]
|
@@ -692,6 +713,13 @@ def uri(self):
|
692 | 713 | geomCol = self.geomColumn if self.type in [Table.VectorType, Table.RasterType] else ""
|
693 | 714 | uniqueCol = self.getValidQgisUniqueFields(True) if self.isView else None
|
694 | 715 | 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 | + |
695 | 723 | return uri
|
696 | 724 |
|
697 | 725 | def mimeUri(self):
|
|
0 commit comments