Skip to content

Commit 2c1356c

Browse files
committedOct 18, 2016
[DBManager] Remove geopackage support from spatialite plugin
1 parent d10e564 commit 2c1356c

File tree

3 files changed

+9
-94
lines changed

3 files changed

+9
-94
lines changed
 

‎python/plugins/db_manager/db_plugins/spatialite/connector.py

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def __init__(self, uri):
5555

5656
self._checkSpatial()
5757
self._checkRaster()
58-
self._checkGeopackage()
5958

6059
def _connectionInfo(self):
6160
return str(self.dbname)
@@ -92,11 +91,6 @@ def _checkRaster(self):
9291
self.has_raster = self._checkRasterTables()
9392
return self.has_raster
9493

95-
def _checkGeopackage(self):
96-
""" check if it's a geopackage db """
97-
self.is_gpkg = self._checkGeopackageTables()
98-
return self.is_gpkg
99-
10094
def _checkGeometryColumnsTable(self):
10195
try:
10296
c = self._get_cursor()
@@ -118,36 +112,6 @@ def _checkRasterTables(self):
118112
ret = c.fetchone()
119113
return ret and ret[0]
120114

121-
def _checkGeopackageTables(self):
122-
try:
123-
sql = u"SELECT HasGeoPackage()"
124-
result = self._execute(None, sql).fetchone()[0] == 1
125-
except ConnectionError:
126-
result = False
127-
except Exception:
128-
# SpatiaLite < 4.2 does not have HasGeoPackage() function
129-
result = False
130-
131-
if result:
132-
try:
133-
sql = u"SELECT CheckGeoPackageMetaData()"
134-
result = self._execute(None, sql).fetchone()[0] == 1
135-
except ConnectionError:
136-
result = False
137-
else:
138-
# Spatialite < 4.2 has no GeoPackage support, check for filename and GPKG layout
139-
ver = list(map(int, self.getInfo()[0].split('.')[0:2]))
140-
if ver[0] < 4 or (ver[0] == 4 and ver[1] < 2):
141-
hasGpkgFileExt = self.dbname[-5:] == ".gpkg" or self.dbname[-11:] == ".geopackage"
142-
143-
sql = u"SELECT count(*) = 3 FROM sqlite_master WHERE name IN ('gpkg_geometry_columns', 'gpkg_spatial_ref_sys', 'gpkg_contents')"
144-
ret = self._execute(None, sql).fetchone()
145-
hasGpkgLayout = ret and ret[0]
146-
147-
result = hasGpkgFileExt and hasGpkgLayout
148-
149-
return result
150-
151115
def getInfo(self):
152116
c = self._get_cursor()
153117
self._execute(c, u"SELECT sqlite_version()")
@@ -159,7 +123,7 @@ def getSpatialInfo(self):
159123
- geos version
160124
- proj version
161125
"""
162-
if not self.has_spatial and not self.is_gpkg:
126+
if not self.has_spatial:
163127
return
164128

165129
c = self._get_cursor()
@@ -187,9 +151,6 @@ def hasTableColumnEditingSupport(self):
187151
def hasCreateSpatialViewSupport(self):
188152
return True
189153

190-
def isGpkg(self):
191-
return self.is_gpkg
192-
193154
def fieldTypes(self):
194155
return [
195156
"integer", "bigint", "smallint", # integers
@@ -307,14 +268,6 @@ def getVectorTables(self, schema=None):
307268
WHERE m.type in ('table', 'view')
308269
ORDER BY m.name, g.f_geometry_column""" % cols
309270

310-
elif self.is_gpkg:
311-
# get info from gpkg_geometry_columns table
312-
dim = " 'XY' || CASE z WHEN 1 THEN 'Z' END || CASE m WHEN 1 THEN 'M' END AS coord_dimension "
313-
sql = u"""SELECT m.name, m.type = 'view', g.table_name, g.column_name, g.geometry_type_name AS gtype, %s, g.srs_id
314-
FROM sqlite_master AS m JOIN gpkg_geometry_columns AS g ON upper(m.name) = upper(g.table_name)
315-
WHERE m.type in ('table', 'view')
316-
ORDER BY m.name, g.column_name""" % dim
317-
318271
else:
319272
return []
320273

@@ -340,8 +293,6 @@ def getRasterTables(self, schema=None):
340293
srid
341294
"""
342295

343-
if self.is_gpkg:
344-
return [] # Not implemented
345296
if not self.has_geometry_columns:
346297
return []
347298
if not self.has_raster:
@@ -447,10 +398,7 @@ def getViewDefinition(self, view):
447398
return ret[0] if ret is not None else None
448399

449400
def getSpatialRefInfo(self, srid):
450-
if self.is_gpkg:
451-
sql = u"SELECT srs_name FROM gpkg_spatial_ref_sys WHERE srs_id = %s" % self.quoteString(srid)
452-
else:
453-
sql = u"SELECT ref_sys_name FROM spatial_ref_sys WHERE srid = %s" % self.quoteString(srid)
401+
sql = u"SELECT ref_sys_name FROM spatial_ref_sys WHERE srid = %s" % self.quoteString(srid)
454402
c = self._execute(None, sql)
455403
ret = c.fetchone()
456404
return ret[0] if ret is not None else None
@@ -503,8 +451,6 @@ def deleteTable(self, table):
503451
""" delete table from the database """
504452
if self.isRasterTable(table):
505453
return False
506-
if self.is_gpkg:
507-
return False # Not implemented
508454

509455
c = self._get_cursor()
510456
sql = u"DROP TABLE %s" % self.quoteId(table)
@@ -518,8 +464,6 @@ def emptyTable(self, table):
518464
""" delete all rows from table """
519465
if self.isRasterTable(table):
520466
return False
521-
if self.is_gpkg:
522-
return False # Not implemented
523467

524468
sql = u"DELETE FROM %s" % self.quoteId(table)
525469
self._execute_and_commit(sql)
@@ -532,8 +476,6 @@ def renameTable(self, table, new_table):
532476

533477
if self.isRasterTable(table):
534478
return False
535-
if self.is_gpkg:
536-
return False # Not implemented
537479

538480
c = self._get_cursor()
539481

@@ -573,8 +515,6 @@ def renameView(self, view, new_name):
573515
return self.renameTable(view, new_name)
574516

575517
def createSpatialView(self, view, query):
576-
if self.is_gpkg:
577-
return False # Not implemented
578518

579519
self.createView(view, query)
580520
# get type info about the view
@@ -654,8 +594,6 @@ def setColumnNull(self, table, column, is_null):
654594
return False # column editing not supported
655595

656596
def isGeometryColumn(self, table, column):
657-
if self.is_gpkg:
658-
return False # Not implemented
659597

660598
c = self._get_cursor()
661599
schema, tablename = self.getSchemaTableName(table)
@@ -665,8 +603,6 @@ def isGeometryColumn(self, table, column):
665603
return c.fetchone()[0] == 't'
666604

667605
def addGeometryColumn(self, table, geom_column='geometry', geom_type='POINT', srid=-1, dim=2):
668-
if self.is_gpkg:
669-
return False # Not implemented
670606

671607
schema, tablename = self.getSchemaTableName(table)
672608
sql = u"SELECT AddGeometryColumn(%s, %s, %d, %s, %s)" % (
@@ -704,8 +640,6 @@ def deleteTableIndex(self, table, name):
704640
def createSpatialIndex(self, table, geom_column='geometry'):
705641
if self.isRasterTable(table):
706642
return False
707-
if self.is_gpkg:
708-
return False # Not implemented
709643

710644
schema, tablename = self.getSchemaTableName(table)
711645
sql = u"SELECT CreateSpatialIndex(%s, %s)" % (self.quoteString(tablename), self.quoteString(geom_column))
@@ -714,8 +648,6 @@ def createSpatialIndex(self, table, geom_column='geometry'):
714648
def deleteSpatialIndex(self, table, geom_column='geometry'):
715649
if self.isRasterTable(table):
716650
return False
717-
if self.is_gpkg:
718-
return False # Not implemented
719651

720652
schema, tablename = self.getSchemaTableName(table)
721653
try:
@@ -729,8 +661,6 @@ def deleteSpatialIndex(self, table, geom_column='geometry'):
729661
self.deleteTable(idx_table_name)
730662

731663
def hasSpatialIndex(self, table, geom_column='geometry'):
732-
if self.is_gpkg:
733-
return False # Not implemented
734664
if not self.has_geometry_columns or self.isRasterTable(table):
735665
return False
736666
c = self._get_cursor()

‎python/plugins/db_manager/db_plugins/spatialite/info_model.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ def spatialInfo(self):
5858
]
5959
ret.append(HtmlTable(tbl))
6060

61-
if self.db.connector.is_gpkg:
62-
pass
63-
64-
elif not self.db.connector.has_geometry_columns:
61+
if not self.db.connector.has_geometry_columns:
6562
ret.append(HtmlParagraph(
6663
QApplication.translate("DBManagerPlugin", "<warning> geometry_columns table doesn't exist!\n"
6764
"This table is essential for many GIS applications for enumeration of tables.")))

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def typeName(self):
5252

5353
@classmethod
5454
def typeNameString(self):
55-
return 'SpatiaLite/Geopackage'
55+
return 'SpatiaLite'
5656

5757
@classmethod
5858
def providerName(self):
@@ -90,7 +90,7 @@ def addConnection(self, conn_name, uri):
9090
def addConnectionActionSlot(self, item, action, parent, index):
9191
QApplication.restoreOverrideCursor()
9292
try:
93-
filename, selected_filter = QFileDialog.getOpenFileName(parent, "Choose Sqlite/Spatialite/Geopackage file")
93+
filename, selected_filter = QFileDialog.getOpenFileName(parent, "Choose Sqlite/Spatialite file")
9494
if not filename:
9595
return
9696
finally:
@@ -184,21 +184,13 @@ def ogrUri(self):
184184
return ogrUri
185185

186186
def mimeUri(self):
187-
if self.database().connector.isGpkg():
188-
# QGIS has no provider to load Geopackage vectors, let's use OGR
189-
return u"vector:ogr:%s:%s" % (self.name, self.ogrUri())
190187
return Table.mimeUri(self)
191188

192189
def toMapLayer(self):
193190
from qgis.core import QgsVectorLayer
194191

195-
if self.database().connector.isGpkg():
196-
# QGIS has no provider to load Geopackage vectors, let's use OGR
197-
provider = "ogr"
198-
uri = self.ogrUri()
199-
else:
200-
provider = self.database().dbplugin().providerName()
201-
uri = self.uri().uri()
192+
provider = self.database().dbplugin().providerName()
193+
uri = self.uri().uri()
202194

203195
return QgsVectorLayer(uri, self.name, provider)
204196

@@ -283,12 +275,8 @@ def mimeUri(self):
283275
def toMapLayer(self):
284276
from qgis.core import QgsRasterLayer, QgsContrastEnhancement
285277

286-
if self.database().connector.isGpkg():
287-
# QGIS has no provider to load Geopackage rasters, let's use GDAL
288-
uri = self.ogrUri()
289-
else:
290-
# QGIS has no provider to load Rasterlite rasters, let's use GDAL
291-
uri = self.rasterliteGdalUri()
278+
# QGIS has no provider to load Rasterlite rasters, let's use GDAL
279+
uri = self.rasterliteGdalUri()
292280

293281
rl = QgsRasterLayer(uri, self.name)
294282
if rl.isValid():

0 commit comments

Comments
 (0)
Please sign in to comment.