Skip to content

Commit

Permalink
[dbmanager] allow to import GEOMETRY tables
Browse files Browse the repository at this point in the history
UI is similar to the browser, where generic geometry tables
are display several times, one for each type.
  • Loading branch information
olivierdalang authored and m-kuhn committed Jun 12, 2019
1 parent dc84c87 commit 0f15a1f
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions python/plugins/db_manager/db_plugins/plugin.py
Expand Up @@ -27,7 +27,13 @@
from qgis.PyQt.QtGui import QKeySequence, QIcon

from qgis.gui import QgsMessageBar
from qgis.core import Qgis, QgsApplication, QgsSettings
from qgis.core import (
Qgis,
QgsApplication,
QgsSettings,
QgsMapLayerType,
QgsWkbTypes
)
from ..db_plugins import createDbPlugin


Expand Down Expand Up @@ -517,8 +523,28 @@ def rasterTablesFactory(self, row, db, schema=None):
def tables(self, schema=None, sys_tables=False):
tables = self.connector.getTables(schema.name if schema else None, sys_tables)
if tables is not None:
tables = [self.tablesFactory(x, self, schema) for x in tables]
return tables
ret = []
for t in tables:
table = self.tablesFactory(t, self, schema)
ret.append(table)

# Similarly to what to browser does, if the geom type is generic geometry,
# we additionnly add three copies of the layer to allow importing
if isinstance(table, VectorTable):
if table.geomType == 'GEOMETRY':
point_table = self.tablesFactory(t, self, schema)
point_table.geomType = 'POINT'
ret.append(point_table)

line_table = self.tablesFactory(t, self, schema)
line_table.geomType = 'LINESTRING'
ret.append(line_table)

poly_table = self.tablesFactory(t, self, schema)
poly_table.geomType = 'POLYGON'
ret.append(poly_table)

return ret

def createTable(self, table, fields, schema=None):
field_defs = [x.definition() for x in fields]
Expand Down Expand Up @@ -683,6 +709,13 @@ def uri(self):
geomCol = self.geomColumn if self.type in [Table.VectorType, Table.RasterType] else ""
uniqueCol = self.getValidQgisUniqueFields(True) if self.isView else None
uri.setDataSource(schema, self.name, geomCol if geomCol else None, None, uniqueCol.name if uniqueCol else "")
uri.setSrid(str(self.srid))
for f in self.fields():
if f.primaryKey:
uri.setKeyColumn(f.name)
break
uri.setWkbType(QgsWkbTypes.parseType(self.geomType))

return uri

def mimeUri(self):
Expand Down

0 comments on commit 0f15a1f

Please sign in to comment.