Skip to content

Commit ad2f760

Browse files
committed
GPKG: proper handling of unknown geometry
This handles the test use case for layer: Layer name: geometry2d Geometry: Unknown (any) Feature Count: 8 The browser tree will now show the different geometry layers and allow them to be added in the canvas, GeometryCollections are skipped.
1 parent 97d168e commit ad2f760

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/providers/ogr/qgsgeopackagedataitems.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,19 @@ QVector<QgsDataItem *> QgsGeoPackageConnectionItem::createChildren()
156156
layerType = layerTypeFromDb( geometryType );
157157
if ( layerType != QgsLayerItem::LayerType::NoType )
158158
{
159-
// example URI: '/path/gdal_sample_v1.2_no_extensions.gpkg|layerid=7'
160-
QString uri = QStringLiteral( "%1|layerid=%2" ).arg( mPath, layerId );
161-
QgsGeoPackageVectorLayerItem *item = new QgsGeoPackageVectorLayerItem( this, name, mPath, uri, layerType );
162-
QgsDebugMsg( QStringLiteral( "Adding GPKG Vector item %1 %2 %3" ).arg( name, uri, geometryType ) );
163-
children.append( item );
159+
if ( geometryType.contains( QStringLiteral( "Collection" ), Qt::CaseInsensitive ) )
160+
{
161+
QgsDebugMsgLevel( QStringLiteral( "Layer %1 is a geometry collection: skipping %2" ).arg( name, mPath ), 3 );
162+
}
163+
else
164+
{
165+
// example URI: '/path/gdal_sample_v1.2_no_extensions.gpkg|layerid=7|geometrytype=Point'
166+
QString uri = QStringLiteral( "%1|layerid=%2|geometrytype=%3" ).arg( mPath, layerId, geometryType );
167+
// TODO?: not sure, but if it's a collection, an expandable node would be better?
168+
QgsGeoPackageVectorLayerItem *item = new QgsGeoPackageVectorLayerItem( this, name, mPath, uri, layerType );
169+
QgsDebugMsgLevel( QStringLiteral( "Adding GPKG Vector item %1 %2 %3" ).arg( name, uri, geometryType ), 3 );
170+
children.append( item );
171+
}
164172
}
165173
else
166174
{

0 commit comments

Comments
 (0)