Skip to content

Commit 737ab30

Browse files
committed
[processing][gdal] Correctly handle geopackage paths with layername argument
Fixes #19938
1 parent 7a45702 commit 737ab30

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

python/plugins/processing/algs/gdal/GdalAlgorithm.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
QgsProcessingFeatureSourceDefinition,
3636
QgsProcessingAlgorithm,
3737
QgsProcessingContext,
38-
QgsProcessingFeedback)
38+
QgsProcessingFeedback,
39+
QgsProviderRegistry)
3940

4041
from processing.algs.gdal.GdalAlgorithmDialog import GdalAlgorithmDialog
4142
from processing.algs.gdal.GdalUtils import GdalUtils
@@ -106,7 +107,12 @@ def getOgrCompatibleSource(self, parameter_name, parameters, context, feedback,
106107
ogr_data_path = self.parameterAsCompatibleSourceLayerPath(parameters, parameter_name, context,
107108
QgsVectorFileWriter.supportedFormatExtensions(),
108109
feedback=feedback)
109-
ogr_layer_name = GdalUtils.ogrLayerName(input_layer.dataProvider().dataSourceUri())
110+
parts = QgsProviderRegistry.instance().decodeUri('ogr', ogr_data_path)
111+
ogr_data_path = parts['path']
112+
if 'layerName' in parts and parts['layerName']:
113+
ogr_layer_name = parts['layerName']
114+
else:
115+
ogr_layer_name = GdalUtils.ogrLayerName(ogr_data_path)
110116
else:
111117
#not executing - don't worry about 'selected features only' handling. It has no meaning
112118
#for the command line preview since it has no meaning outside of a QGIS session!
Binary file not shown.

src/core/processing/qgsprocessingutils.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "qgsexpressioncontextscopegenerator.h"
3030
#include "qgsfileutils.h"
3131
#include "qgsvectorlayer.h"
32+
#include "qgsproviderregistry.h"
3233

3334
QList<QgsRasterLayer *> QgsProcessingUtils::compatibleRasterLayers( QgsProject *project, bool sort )
3435
{
@@ -631,8 +632,16 @@ QString QgsProcessingUtils::convertToCompatibleFormat( const QgsVectorLayer *vl,
631632
bool requiresTranslation = selectedFeaturesOnly;
632633
if ( !selectedFeaturesOnly )
633634
{
634-
QFileInfo fi( vl->source() );
635-
requiresTranslation = !compatibleFormats.contains( fi.suffix(), Qt::CaseInsensitive );
635+
const QVariantMap parts = QgsProviderRegistry::instance()->decodeUri( vl->dataProvider()->name(), vl->source() );
636+
if ( parts.contains( QLatin1String( "path" ) ) )
637+
{
638+
QFileInfo fi( parts.value( QLatin1String( "path" ) ).toString() );
639+
requiresTranslation = !compatibleFormats.contains( fi.suffix(), Qt::CaseInsensitive );
640+
}
641+
else
642+
{
643+
requiresTranslation = true; // not a disk-based format
644+
}
636645
}
637646

638647
if ( requiresTranslation )

0 commit comments

Comments
 (0)