Bug report #16730
python error in DB Manager when connecting to a Geopackage datasource
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | Even Rouault | ||
Category: | DB Manager | ||
Affected QGIS version: | 2.18.9 | Regression?: | No |
Operating System: | Easy fix?: | No | |
Pull Request or Patch supplied: | No | Resolution: | fixed/implemented |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 24629 |
Description
It happens that I created (via ogr2ogr) a GPKG file from a KML one.
This GPKG file works ok in QGIS when layers are added via the "add vector layer" dialog.
In DB Manager the connection to this datasource can be established, but then when expanding it an error is returned.
Master and 2.18.9 both affected.
UnboundLocalError: local variable 'geomname' referenced before assignment Traceback (most recent call last): File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\db_manager\db_model.py", line 440, in rowCount self._refreshIndex(parent, True) File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\db_manager\db_model.py", line 491, in _refreshIndex if item.populate(): File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\db_manager\db_model.py", line 182, in populate tables = database.tables() File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\db_manager\db_plugins\plugin.py", line 513, in tables tables = self.connector.getTables(schema.name if schema else None, sys_tables) File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\db_manager\db_plugins\gpkg\connector.py", line 275, in getTables vectors = self.getVectorTables(schema) File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\db_manager\db_plugins\gpkg\connector.py", line 362, in getVectorTables geomname, UnboundLocalError: local variable 'geomname' referenced before assignment
History
#1 Updated by Luigi Pirelli over 7 years ago
confirmed
#2 Updated by Luigi Pirelli over 7 years ago
without much debug I can see that geomname is set only if:
if geomtype_flatten == ogr.wkbPoint: geomname = 'POINT' elif geomtype_flatten == ogr.wkbLineString: geomname = 'LINESTRING' elif geomtype_flatten == ogr.wkbPolygon: geomname = 'POLYGON' elif geomtype_flatten == ogr.wkbMultiPoint: geomname = 'MULTIPOINT' elif geomtype_flatten == ogr.wkbMultiLineString: geomname = 'MULTILINESTRING' elif geomtype_flatten == ogr.wkbMultiPolygon: geomname = 'MULTIPOLYGON' elif geomtype_flatten == ogr.wkbGeometryCollection: geomname = 'GEOMETRYCOLLECTION' if self.gdal2: if geomtype_flatten == ogr.wkbCircularString: geomname = 'CIRCULARSTRING' elif geomtype_flatten == ogr.wkbCompoundCurve: geomname = 'COMPOUNDCURVE' elif geomtype_flatten == ogr.wkbCurvePolygon: geomname = 'CURVEPOLYGON' elif geomtype_flatten == ogr.wkbMultiCurve: geomname = 'MULTICURVE' elif geomtype_flatten == ogr.wkbMultiSurface: geomname = 'MULTISURFACE'
=> only for tables with geom => should generate erro r in case gem is not defined as for some table in the test db. I'll give more investigation later
#3 Updated by Luigi Pirelli over 7 years ago
btw tables whould be managed by https://issues.qgis.org/projects/qgis/repository/revisions/8c7ca625cce39a6d38dd808f22d625cdeb79ebca/entry/python/plugins/db_manager/db_plugins/gpkg/connector.py#L350 so, the problem is generated from another point of from the nature of the generated gpkg
#4 Updated by Luigi Pirelli over 7 years ago
the layer that fail is: "Zagros, Elam, and Iran" (the firt enountered in the GDAL GetLayers)
the
geomtype = 0 (wkbUnknown) but it should be Polygon or Point
#5 Updated by Even Rouault over 7 years ago
- Assignee set to Even Rouault
#6 Updated by Even Rouault over 7 years ago
- Resolution set to fixed/implemented
Fixed per 2fb0b16364122badf1b797c77bb89cc1eddffcfe / 6cfd1a0f51251691e46741fef519ca6eace11405
The layers are indeed loosely typed regarding their geometry types. The reason is that KML itself is loosely typed. And in that example, a few layers have different geometry types (POINT and POLYGON)
#7 Updated by Luigi Pirelli over 7 years ago
@even make it sense to use a custom code instead of using directly Dataprovider qgis api that seems they work manageing gpkg?
#8 Updated by Jürgen Fischer over 7 years ago
- Description updated (diff)
#9 Updated by Even Rouault almost 7 years ago
- Status changed from Open to Closed