Skip to content
Permalink
Browse files

[processing] Ensure driverName is passed to QgsVectorLayerExporter

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 501c63feb3887e18da35188062546186d8a767ac
Showing with 7 additions and 2 deletions.
  1. +2 −0 src/core/processing/qgsprocessingutils.cpp
  2. +5 −2 tests/src/analysis/testqgsprocessing.cpp
@@ -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 );
}
@@ -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" ) );
}

0 comments on commit 501c63f

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