Allow loading GPKG layers with GEOMETRY type (#42253)

This commit is contained in:
Marco Bernasocchi 2021-03-16 15:58:55 +01:00 committed by GitHub
parent 8731c7e60a
commit 60f788c91d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -209,12 +209,21 @@ class GPKGTable(Table):
# QGIS has no provider to load Geopackage vectors, let's use OGR
return u"vector:ogr:%s:%s" % (self.name, self.ogrUri())
def toMapLayer(self):
def toMapLayer(self, geometryType=None, crs=None):
from qgis.core import QgsVectorLayer
provider = "ogr"
uri = self.ogrUri()
if geometryType:
geom_mapping = {
'POINT': 'Point',
'LINESTRING': 'LineString',
'POLYGON': 'Polygon',
}
geometryType = geom_mapping[geometryType]
uri = "{}|geometrytype={}".format(uri, geometryType)
return QgsVectorLayer(uri, self.name, provider)
def tableFieldsFactory(self, row, table):