From b43c7a72eb2c68f4b1a394e6a73999bdfcb6ffbb Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 16 Sep 2024 23:41:35 +0200 Subject: [PATCH] Save as vector file: fix re-opening a GeoJSON Newline delimited file Fixes #58760 --- src/app/qgisapp.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 1fc4e64a11e69..65077ce58b54e 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -487,6 +487,7 @@ // // GDAL/OGR includes // +#include #include #include #include @@ -8638,9 +8639,23 @@ QString QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbology QgsVectorFileWriterTask *writerTask = new QgsVectorFileWriterTask( vlayer, vectorFilename, options ); // when writer is successful: - connect( writerTask, &QgsVectorFileWriterTask::completed, this, [onSuccess, addToCanvas, encoding, vectorFilename]( const QString & newFilename, const QString & newLayer ) + connect( writerTask, &QgsVectorFileWriterTask::completed, this, [onSuccess, addToCanvas, encoding, vectorFilename, format]( const QString & newFilename, const QString & newLayer ) { - onSuccess( newFilename, addToCanvas, newLayer, encoding, vectorFilename ); + QString layerName = newLayer; +#ifdef GDAL_DCAP_MULTIPLE_VECTOR_LAYERS + GDALDriverH hDriver = GDALGetDriverByName( format.toUtf8().constData() ); + if ( hDriver ) + { + // If the driver doesn't advertize supporting multiple vector layers, + // do not attempt to append the layer name to the connection URI + // This would for example break for the GeoJSONSeq driver. + if ( !GDALGetMetadataItem( hDriver, GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, nullptr ) ) + { + layerName.clear(); + } + } +#endif + onSuccess( newFilename, addToCanvas, layerName, encoding, vectorFilename ); } ); // when an error occurs: