Skip to content
Permalink
Browse files

[FEATURE] [OGR provider] Add support for open options

With "|option:FOO=BAR|option:FOO2=BAR2" in the URI

Also use more extensive encodeUri()/decodeUri() to avoid manual
manipulations
  • Loading branch information
rouault authored and nyalldawson committed Oct 5, 2020
1 parent c23843d commit f3476d9a7e35d0e26dcfe1f564661d84c159f9c8
@@ -39,8 +39,18 @@ inline QString qgsConnectionPool_ConnectionToName( QgsOgrConn *c )
inline void qgsConnectionPool_ConnectionCreate( const QString &connInfo, QgsOgrConn *&c )
{
c = new QgsOgrConn;
QString filePath = connInfo.left( connInfo.indexOf( QLatin1String( "|" ) ) );
c->ds = QgsOgrProviderUtils::GDALOpenWrapper( filePath.toUtf8().constData(), false, nullptr, nullptr );

QVariantMap parts = QgsOgrProviderMetadata().decodeUri( connInfo );
QString filePath = parts.value( QStringLiteral( "path" ) ).toString();
const QStringList openOptions = parts.value( QStringLiteral( "openOptions" ) ).toStringList();
char **papszOpenOptions = nullptr;
for ( const QString &option : openOptions )
{
papszOpenOptions = CSLAddString( papszOpenOptions,
option.toUtf8().constData() );
}
c->ds = QgsOgrProviderUtils::GDALOpenWrapper( filePath.toUtf8().constData(), false, papszOpenOptions, nullptr );
CSLDestroy( papszOpenOptions );
c->path = connInfo;
c->valid = true;
}
@@ -133,6 +133,8 @@ QList<QgsOgrDbLayerInfo *> QgsOgrLayerItem::subLayers( const QString &path, cons
QgsVectorLayer layer( path, QStringLiteral( "ogr_tmp" ), QStringLiteral( "ogr" ), layerOptions );
if ( layer.isValid( ) )
{
QVariantMap oriParts = QgsOgrProviderMetadata().decodeUri( path );

// Collect mixed-geom layers
QMultiMap<int, QStringList> subLayersMap;
QgsOgrProvider *ogrProvider = qobject_cast<QgsOgrProvider *>( layer.dataProvider() );
@@ -177,7 +179,6 @@ QList<QgsOgrDbLayerInfo *> QgsOgrLayerItem::subLayers( const QString &path, cons
// example URI for mixed-geoms geoms: '/path/gdal_sample_v1.2_no_extensions.gpkg|layerid=7|geometrytype=Point'
// example URI for mixed-geoms attr table: '/path/gdal_sample_v1.2_no_extensions.gpkg|layername=MyLayer|layerid=7'
// example URI for single geoms: '/path/gdal_sample_v1.2_no_extensions.gpkg|layerid=6'
QString uri;
if ( layerType != QgsLayerItem::LayerType::NoType )
{
if ( geometryType.contains( QStringLiteral( "Collection" ), Qt::CaseInsensitive ) )
@@ -186,25 +187,29 @@ QList<QgsOgrDbLayerInfo *> QgsOgrLayerItem::subLayers( const QString &path, cons
}
else
{
QVariantMap parts( oriParts );
if ( uniqueNames )
uri = QStringLiteral( "%1|layername=%2" ).arg( path, name );
parts.insert( QStringLiteral( "layerName" ), name );
else
uri = QStringLiteral( "%1|layerid=%2" ).arg( path, layerId );
parts.insert( QStringLiteral( "layerId" ), layerId );
if ( values.size() > 1 )
{
uri += QStringLiteral( "|geometrytype=" ) + geometryType;
parts.insert( QStringLiteral( "geometryType" ), geometryType );
}
QString uri = QgsOgrProviderMetadata().encodeUri( parts );
QgsDebugMsgLevel( QStringLiteral( "Adding %1 Vector item %2 %3 %4" ).arg( driver, name, uri, geometryType ), 3 );
children.append( new QgsOgrDbLayerInfo( path, uri, name, geometryColumn, geometryType, layerType, driver ) );
}
}
else
{
QgsDebugMsgLevel( QStringLiteral( "Layer type is not a supported %1 Vector layer %2" ).arg( driver, path ), 3 );
uri = QStringLiteral( "%1|layerid=%2|layername=%3" ).arg( path, layerId, name );
QVariantMap parts( oriParts );
parts.insert( QStringLiteral( "layerId" ), layerId );
parts.insert( QStringLiteral( "layerName" ), name );
QString uri = QgsOgrProviderMetadata().encodeUri( parts );
children.append( new QgsOgrDbLayerInfo( path, uri, name, geometryColumn, geometryType, QgsLayerItem::LayerType::TableLayer, driver ) );
}
QgsDebugMsgLevel( QStringLiteral( "Adding %1 Vector item %2 %3 %4" ).arg( driver, name, uri, geometryType ), 3 );
}
}
}

0 comments on commit f3476d9

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