Skip to content
Permalink
Browse files

[DBManager] Remove geopackage support from spatialite plugin

  • Loading branch information
rouault committed Oct 25, 2016
1 parent e08f981 commit a1bff2955bcb3e5ec54fb43c6f26e8a99ad2a8f8
@@ -50,7 +50,6 @@ def __init__(self, uri):

self._checkSpatial()
self._checkRaster()
self._checkGeopackage()

def _connectionInfo(self):
return unicode(self.dbname)
@@ -87,11 +86,6 @@ def _checkRaster(self):
self.has_raster = self._checkRasterTables()
return self.has_raster

def _checkGeopackage(self):
""" check if it's a geopackage db """
self.is_gpkg = self._checkGeopackageTables()
return self.is_gpkg

def _checkGeometryColumnsTable(self):
try:
c = self._get_cursor()
@@ -113,36 +107,6 @@ def _checkRasterTables(self):
ret = c.fetchone()
return ret and ret[0]

def _checkGeopackageTables(self):
try:
sql = u"SELECT HasGeoPackage()"
result = self._execute(None, sql).fetchone()[0] == 1
except ConnectionError:
result = False
except Exception:
# SpatiaLite < 4.2 does not have HasGeoPackage() function
result = False

if result:
try:
sql = u"SELECT CheckGeoPackageMetaData()"
result = self._execute(None, sql).fetchone()[0] == 1
except ConnectionError:
result = False
else:
# Spatialite < 4.2 has no GeoPackage support, check for filename and GPKG layout
ver = map(int, self.getInfo()[0].split('.')[0:2])
if ver[0] < 4 or (ver[0] == 4 and ver[1] < 2):
hasGpkgFileExt = self.dbname[-5:] == ".gpkg" or self.dbname[-11:] == ".geopackage"

sql = u"SELECT count(*) = 3 FROM sqlite_master WHERE name IN ('gpkg_geometry_columns', 'gpkg_spatial_ref_sys', 'gpkg_contents')"
ret = self._execute(None, sql).fetchone()
hasGpkgLayout = ret and ret[0]

result = hasGpkgFileExt and hasGpkgLayout

return result

def getInfo(self):
c = self._get_cursor()
self._execute(c, u"SELECT sqlite_version()")
@@ -154,7 +118,7 @@ def getSpatialInfo(self):
- geos version
- proj version
"""
if not self.has_spatial and not self.is_gpkg:
if not self.has_spatial:
return

c = self._get_cursor()
@@ -182,9 +146,6 @@ def hasTableColumnEditingSupport(self):
def hasCreateSpatialViewSupport(self):
return True

def isGpkg(self):
return self.is_gpkg

def fieldTypes(self):
return [
"integer", "bigint", "smallint", # integers
@@ -302,14 +263,6 @@ def getVectorTables(self, schema=None):
WHERE m.type in ('table', 'view')
ORDER BY m.name, g.f_geometry_column""" % cols

elif self.is_gpkg:
# get info from gpkg_geometry_columns table
dim = " 'XY' || CASE z WHEN 1 THEN 'Z' END || CASE m WHEN 1 THEN 'M' END AS coord_dimension "
sql = u"""SELECT m.name, m.type = 'view', g.table_name, g.column_name, g.geometry_type_name AS gtype, %s, g.srs_id
FROM sqlite_master AS m JOIN gpkg_geometry_columns AS g ON upper(m.name) = upper(g.table_name)
WHERE m.type in ('table', 'view')
ORDER BY m.name, g.column_name""" % dim

else:
return []

@@ -335,8 +288,6 @@ def getRasterTables(self, schema=None):
srid
"""

if self.is_gpkg:
return [] # Not implemented
if not self.has_geometry_columns:
return []
if not self.has_raster:
@@ -442,10 +393,7 @@ def getViewDefinition(self, view):
return ret[0] if ret is not None else None

def getSpatialRefInfo(self, srid):
if self.is_gpkg:
sql = u"SELECT srs_name FROM gpkg_spatial_ref_sys WHERE srs_id = %s" % self.quoteString(srid)
else:
sql = u"SELECT ref_sys_name FROM spatial_ref_sys WHERE srid = %s" % self.quoteString(srid)
sql = u"SELECT ref_sys_name FROM spatial_ref_sys WHERE srid = %s" % self.quoteString(srid)
c = self._execute(None, sql)
ret = c.fetchone()
return ret[0] if ret is not None else None
@@ -498,8 +446,6 @@ def deleteTable(self, table):
""" delete table from the database """
if self.isRasterTable(table):
return False
if self.is_gpkg:
return False # Not implemented

c = self._get_cursor()
sql = u"DROP TABLE %s" % self.quoteId(table)
@@ -513,8 +459,6 @@ def emptyTable(self, table):
""" delete all rows from table """
if self.isRasterTable(table):
return False
if self.is_gpkg:
return False # Not implemented

sql = u"DELETE FROM %s" % self.quoteId(table)
self._execute_and_commit(sql)
@@ -527,8 +471,6 @@ def renameTable(self, table, new_table):

if self.isRasterTable(table):
return False
if self.is_gpkg:
return False # Not implemented

c = self._get_cursor()

@@ -568,8 +510,6 @@ def renameView(self, view, new_name):
return self.renameTable(view, new_name)

def createSpatialView(self, view, query):
if self.is_gpkg:
return False # Not implemented

self.createView(view, query)
# get type info about the view
@@ -649,8 +589,6 @@ def setColumnNull(self, table, column, is_null):
return False # column editing not supported

def isGeometryColumn(self, table, column):
if self.is_gpkg:
return False # Not implemented

c = self._get_cursor()
schema, tablename = self.getSchemaTableName(table)
@@ -660,8 +598,6 @@ def isGeometryColumn(self, table, column):
return c.fetchone()[0] == 't'

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

schema, tablename = self.getSchemaTableName(table)
sql = u"SELECT AddGeometryColumn(%s, %s, %d, %s, %s)" % (
@@ -699,8 +635,6 @@ def deleteTableIndex(self, table, name):
def createSpatialIndex(self, table, geom_column='geometry'):
if self.isRasterTable(table):
return False
if self.is_gpkg:
return False # Not implemented

schema, tablename = self.getSchemaTableName(table)
sql = u"SELECT CreateSpatialIndex(%s, %s)" % (self.quoteString(tablename), self.quoteString(geom_column))
@@ -709,8 +643,6 @@ def createSpatialIndex(self, table, geom_column='geometry'):
def deleteSpatialIndex(self, table, geom_column='geometry'):
if self.isRasterTable(table):
return False
if self.is_gpkg:
return False # Not implemented

schema, tablename = self.getSchemaTableName(table)
try:
@@ -724,8 +656,6 @@ def deleteSpatialIndex(self, table, geom_column='geometry'):
self.deleteTable(idx_table_name)

def hasSpatialIndex(self, table, geom_column='geometry'):
if self.is_gpkg:
return False # Not implemented
if not self.has_geometry_columns or self.isRasterTable(table):
return False
c = self._get_cursor()
@@ -58,10 +58,7 @@ def spatialInfo(self):
]
ret.append(HtmlTable(tbl))

if self.db.connector.is_gpkg:
pass

elif not self.db.connector.has_geometry_columns:
if not self.db.connector.has_geometry_columns:
ret.append(HtmlParagraph(
QApplication.translate("DBManagerPlugin", "<warning> geometry_columns table doesn't exist!\n"
"This table is essential for many GIS applications for enumeration of tables.")))
@@ -51,7 +51,7 @@ def typeName(self):

@classmethod
def typeNameString(self):
return 'SpatiaLite/Geopackage'
return 'SpatiaLite'

@classmethod
def providerName(self):
@@ -89,7 +89,7 @@ def addConnection(self, conn_name, uri):
def addConnectionActionSlot(self, item, action, parent, index):
QApplication.restoreOverrideCursor()
try:
filename = QFileDialog.getOpenFileName(parent, "Choose Sqlite/Spatialite/Geopackage file")
filename = QFileDialog.getOpenFileName(parent, "Choose Sqlite/Spatialite file")
if not filename:
return
finally:
@@ -183,21 +183,13 @@ def ogrUri(self):
return ogrUri

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

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

if self.database().connector.isGpkg():
# QGIS has no provider to load Geopackage vectors, let's use OGR
provider = "ogr"
uri = self.ogrUri()
else:
provider = self.database().dbplugin().providerName()
uri = self.uri().uri()
provider = self.database().dbplugin().providerName()
uri = self.uri().uri()

return QgsVectorLayer(uri, self.name, provider)

@@ -282,12 +274,8 @@ def mimeUri(self):
def toMapLayer(self):
from qgis.core import QgsRasterLayer, QgsContrastEnhancement

if self.database().connector.isGpkg():
# QGIS has no provider to load Geopackage rasters, let's use GDAL
uri = self.ogrUri()
else:
# QGIS has no provider to load Rasterlite rasters, let's use GDAL
uri = self.rasterliteGdalUri()
# QGIS has no provider to load Rasterlite rasters, let's use GDAL
uri = self.rasterliteGdalUri()

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

0 comments on commit a1bff29

Please sign in to comment.
You can’t perform that action at this time.