Skip to content

Commit

Permalink
[processing][gdal] Correctly handle geopackage paths with layername a…
Browse files Browse the repository at this point in the history
…rgument

Fixes #19938
  • Loading branch information
nyalldawson committed Sep 28, 2018
1 parent 7a45702 commit 737ab30
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
10 changes: 8 additions & 2 deletions python/plugins/processing/algs/gdal/GdalAlgorithm.py
Expand Up @@ -35,7 +35,8 @@
QgsProcessingFeatureSourceDefinition,
QgsProcessingAlgorithm,
QgsProcessingContext,
QgsProcessingFeedback)
QgsProcessingFeedback,
QgsProviderRegistry)

from processing.algs.gdal.GdalAlgorithmDialog import GdalAlgorithmDialog
from processing.algs.gdal.GdalUtils import GdalUtils
Expand Down Expand Up @@ -106,7 +107,12 @@ def getOgrCompatibleSource(self, parameter_name, parameters, context, feedback,
ogr_data_path = self.parameterAsCompatibleSourceLayerPath(parameters, parameter_name, context,
QgsVectorFileWriter.supportedFormatExtensions(),
feedback=feedback)
ogr_layer_name = GdalUtils.ogrLayerName(input_layer.dataProvider().dataSourceUri())
parts = QgsProviderRegistry.instance().decodeUri('ogr', ogr_data_path)
ogr_data_path = parts['path']
if 'layerName' in parts and parts['layerName']:
ogr_layer_name = parts['layerName']
else:
ogr_layer_name = GdalUtils.ogrLayerName(ogr_data_path)
else:
#not executing - don't worry about 'selected features only' handling. It has no meaning
#for the command line preview since it has no meaning outside of a QGIS session!
Expand Down
Binary file not shown.
13 changes: 11 additions & 2 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -29,6 +29,7 @@
#include "qgsexpressioncontextscopegenerator.h"
#include "qgsfileutils.h"
#include "qgsvectorlayer.h"
#include "qgsproviderregistry.h"

QList<QgsRasterLayer *> QgsProcessingUtils::compatibleRasterLayers( QgsProject *project, bool sort )
{
Expand Down Expand Up @@ -631,8 +632,16 @@ QString QgsProcessingUtils::convertToCompatibleFormat( const QgsVectorLayer *vl,
bool requiresTranslation = selectedFeaturesOnly;
if ( !selectedFeaturesOnly )
{
QFileInfo fi( vl->source() );
requiresTranslation = !compatibleFormats.contains( fi.suffix(), Qt::CaseInsensitive );
const QVariantMap parts = QgsProviderRegistry::instance()->decodeUri( vl->dataProvider()->name(), vl->source() );
if ( parts.contains( QLatin1String( "path" ) ) )
{
QFileInfo fi( parts.value( QLatin1String( "path" ) ).toString() );
requiresTranslation = !compatibleFormats.contains( fi.suffix(), Qt::CaseInsensitive );
}
else
{
requiresTranslation = true; // not a disk-based format
}
}

if ( requiresTranslation )
Expand Down

0 comments on commit 737ab30

Please sign in to comment.