Skip to content
Permalink
Browse files

[processing] Add multi layer outputs to Package Layers and Vector Spl…

…it algorithms
  • Loading branch information
nyalldawson committed Feb 11, 2018
1 parent 4bcc9df commit 54a99c27a3a10909bd1d60af10319a076b20edce
@@ -33,6 +33,7 @@
QgsProcessingParameterField,
QgsProcessingParameterFolderDestination,
QgsProcessingOutputFolder,
QgsProcessingOutputMultipleLayers,
QgsExpression,
QgsFeatureRequest)

@@ -47,6 +48,7 @@ class VectorSplit(QgisAlgorithm):
INPUT = 'INPUT'
FIELD = 'FIELD'
OUTPUT = 'OUTPUT'
OUTPUT_LAYERS = 'OUTPUT_LAYERS'

def group(self):
return self.tr('Vector general')
@@ -66,6 +68,7 @@ def initAlgorithm(self, config=None):

self.addParameter(QgsProcessingParameterFolderDestination(self.OUTPUT,
self.tr('Output directory')))
self.addOutput(QgsProcessingOutputMultipleLayers(self.OUTPUT_LAYERS, self.tr('Output layers')))

def name(self):
return 'splitvectorlayer'
@@ -89,6 +92,7 @@ def processAlgorithm(self, parameters, context, feedback):
geomType = source.wkbType()

total = 100.0 / len(uniqueValues) if uniqueValues else 1
output_layers = []

for current, i in enumerate(uniqueValues):
if feedback.isCanceled():
@@ -108,8 +112,9 @@ def processAlgorithm(self, parameters, context, feedback):
sink.addFeature(f, QgsFeatureSink.FastInsert)
count += 1
feedback.pushInfo(self.tr('Added {} features to layer').format(count))
output_layers.append(fName)
del sink

feedback.setProgress(int(current * total))

return {self.OUTPUT: directory}
return {self.OUTPUT: directory, self.OUTPUT_LAYERS: output_layers}
@@ -53,6 +53,7 @@ void QgsPackageAlgorithm::initAlgorithm( const QVariantMap & )
addParameter( new QgsProcessingParameterFileDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Destination GeoPackage" ), QObject::tr( "GeoPackage files (*.gpkg)" ) ) );
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "OVERWRITE" ), QObject::tr( "Overwrite existing GeoPackage" ), false ) );
addOutput( new QgsProcessingOutputFile( QStringLiteral( "OUTPUT" ), QObject::tr( "GeoPackage" ) ) );
addOutput( new QgsProcessingOutputMultipleLayers( QStringLiteral( "OUTPUT_LAYERS" ), QObject::tr( "Layers within new package" ) ) );
}

QString QgsPackageAlgorithm::shortHelpString() const
@@ -97,6 +98,7 @@ QVariantMap QgsPackageAlgorithm::processAlgorithm( const QVariantMap &parameters

QgsProcessingMultiStepFeedback multiStepFeedback( layers.count(), feedback );

QStringList outputLayers;
int i = 0;
for ( QgsMapLayer *layer : layers )
{
@@ -123,6 +125,8 @@ QVariantMap QgsPackageAlgorithm::processAlgorithm( const QVariantMap &parameters
if ( !packageVectorLayer( qobject_cast< QgsVectorLayer * >( layer ), packagePath,
context, &multiStepFeedback ) )
errored = true;
else
outputLayers.append( QStringLiteral( "%1|layername=%2" ).arg( packagePath, layer->name() ) );
break;
}

@@ -147,6 +151,7 @@ QVariantMap QgsPackageAlgorithm::processAlgorithm( const QVariantMap &parameters

QVariantMap outputs;
outputs.insert( QStringLiteral( "OUTPUT" ), packagePath );
outputs.insert( QStringLiteral( "OUTPUT_LAYERS" ), outputLayers );
return outputs;
}

0 comments on commit 54a99c2

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