mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[DBManager] Remove geopackage support from spatialite plugin
This commit is contained in:
parent
d10e564b57
commit
2c1356cd1d
@ -55,7 +55,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
|
||||
self._checkSpatial()
|
||||
self._checkRaster()
|
||||
self._checkGeopackage()
|
||||
|
||||
def _connectionInfo(self):
|
||||
return str(self.dbname)
|
||||
@ -92,11 +91,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
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()
|
||||
@ -118,36 +112,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
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 = list(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()")
|
||||
@ -159,7 +123,7 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
- geos version
|
||||
- proj version
|
||||
"""
|
||||
if not self.has_spatial and not self.is_gpkg:
|
||||
if not self.has_spatial:
|
||||
return
|
||||
|
||||
c = self._get_cursor()
|
||||
@ -187,9 +151,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
def hasCreateSpatialViewSupport(self):
|
||||
return True
|
||||
|
||||
def isGpkg(self):
|
||||
return self.is_gpkg
|
||||
|
||||
def fieldTypes(self):
|
||||
return [
|
||||
"integer", "bigint", "smallint", # integers
|
||||
@ -307,14 +268,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
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 []
|
||||
|
||||
@ -340,8 +293,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
srid
|
||||
"""
|
||||
|
||||
if self.is_gpkg:
|
||||
return [] # Not implemented
|
||||
if not self.has_geometry_columns:
|
||||
return []
|
||||
if not self.has_raster:
|
||||
@ -447,10 +398,7 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
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
|
||||
@ -503,8 +451,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
""" 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)
|
||||
@ -518,8 +464,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
""" 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)
|
||||
@ -532,8 +476,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
|
||||
if self.isRasterTable(table):
|
||||
return False
|
||||
if self.is_gpkg:
|
||||
return False # Not implemented
|
||||
|
||||
c = self._get_cursor()
|
||||
|
||||
@ -573,8 +515,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
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
|
||||
@ -654,8 +594,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
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)
|
||||
@ -665,8 +603,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
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)" % (
|
||||
@ -704,8 +640,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
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))
|
||||
@ -714,8 +648,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
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:
|
||||
@ -729,8 +661,6 @@ class SpatiaLiteDBConnector(DBConnector):
|
||||
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 @@ class SLDatabaseInfo(DatabaseInfo):
|
||||
]
|
||||
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.")))
|
||||
|
@ -52,7 +52,7 @@ class SpatiaLiteDBPlugin(DBPlugin):
|
||||
|
||||
@classmethod
|
||||
def typeNameString(self):
|
||||
return 'SpatiaLite/Geopackage'
|
||||
return 'SpatiaLite'
|
||||
|
||||
@classmethod
|
||||
def providerName(self):
|
||||
@ -90,7 +90,7 @@ class SpatiaLiteDBPlugin(DBPlugin):
|
||||
def addConnectionActionSlot(self, item, action, parent, index):
|
||||
QApplication.restoreOverrideCursor()
|
||||
try:
|
||||
filename, selected_filter = QFileDialog.getOpenFileName(parent, "Choose Sqlite/Spatialite/Geopackage file")
|
||||
filename, selected_filter = QFileDialog.getOpenFileName(parent, "Choose Sqlite/Spatialite file")
|
||||
if not filename:
|
||||
return
|
||||
finally:
|
||||
@ -184,21 +184,13 @@ class SLTable(Table):
|
||||
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)
|
||||
|
||||
@ -283,12 +275,8 @@ class SLRasterTable(SLTable, RasterTable):
|
||||
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():
|
||||
|
Loading…
x
Reference in New Issue
Block a user