Skip to content

Commit

Permalink
[processing] Ensure driverName is passed to QgsVectorLayerExporter
Browse files Browse the repository at this point in the history
so that GPKG specific optimisations can be applied when saving outputs
to geopackage
  • Loading branch information
nyalldawson committed Oct 17, 2020
1 parent a0711d7 commit 501c63f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -657,10 +657,12 @@ void QgsProcessingUtils::parseDestinationString( QString &destination, QString &
uri = dsUri.database();
extension = QFileInfo( uri ).completeSuffix();
format = QgsVectorFileWriter::driverForExtension( extension );
options.insert( QStringLiteral( "driverName" ), format );
}
else
{
extension = QFileInfo( uri ).completeSuffix();
options.insert( QStringLiteral( "driverName" ), QgsVectorFileWriter::driverForExtension( extension ) );
}
options.insert( QStringLiteral( "update" ), true );
}
Expand Down
7 changes: 5 additions & 2 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -1764,29 +1764,32 @@ void TestQgsProcessing::parseDestinationString()
QCOMPARE( providerKey, QStringLiteral( "ogr" ) );
QCOMPARE( uri, QStringLiteral( "d:/test.shp" ) );
QCOMPARE( options.value( QStringLiteral( "update" ) ).toBool(), true );
QCOMPARE( options.value( QStringLiteral( "driverName" ) ).toString(), QStringLiteral( "ESRI Shapefile" ) );
QVERIFY( !options.contains( QStringLiteral( "layerName" ) ) );
QVERIFY( !useWriter );
QCOMPARE( extension, QStringLiteral( "shp" ) );

// full uri geopackage output
// full uri geopackage output
options.clear();
destination = QStringLiteral( "ogr:d:/test.gpkg" );
QgsProcessingUtils::parseDestinationString( destination, providerKey, uri, layerName, format, options, useWriter, extension );
QCOMPARE( providerKey, QStringLiteral( "ogr" ) );
QCOMPARE( uri, QStringLiteral( "d:/test.gpkg" ) );
QCOMPARE( options.value( QStringLiteral( "update" ) ).toBool(), true );
QVERIFY( !options.contains( QStringLiteral( "layerName" ) ) );
QCOMPARE( options.value( QStringLiteral( "driverName" ) ).toString(), QStringLiteral( "GPKG" ) );
QVERIFY( !useWriter );
QCOMPARE( extension, QStringLiteral( "gpkg" ) );

// full uri geopackage table output with layer name
// full uri geopackage table output with layer name
options.clear();
destination = QStringLiteral( "ogr:dbname='d:/package.gpkg' table=\"mylayer\" (geom) sql=" );
QgsProcessingUtils::parseDestinationString( destination, providerKey, uri, layerName, format, options, useWriter, extension );
QCOMPARE( providerKey, QStringLiteral( "ogr" ) );
QCOMPARE( uri, QStringLiteral( "d:/package.gpkg" ) );
QCOMPARE( options.value( QStringLiteral( "update" ) ).toBool(), true );
QCOMPARE( options.value( QStringLiteral( "layerName" ) ).toString(), QStringLiteral( "mylayer" ) );
QCOMPARE( options.value( QStringLiteral( "driverName" ) ).toString(), QStringLiteral( "GPKG" ) );
QVERIFY( !useWriter );
QCOMPARE( extension, QStringLiteral( "gpkg" ) );
}
Expand Down

0 comments on commit 501c63f

Please sign in to comment.