mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[processing] Add multi layer outputs to Package Layers and Vector Split algorithms
This commit is contained in:
parent
4bcc9df5b4
commit
54a99c27a3
@ -33,6 +33,7 @@ from qgis.core import (QgsProcessingUtils,
|
||||
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 @@ class VectorSplit(QgisAlgorithm):
|
||||
|
||||
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 @@ class VectorSplit(QgisAlgorithm):
|
||||
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 @@ class VectorSplit(QgisAlgorithm):
|
||||
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 ¶meters
|
||||
|
||||
QgsProcessingMultiStepFeedback multiStepFeedback( layers.count(), feedback );
|
||||
|
||||
QStringList outputLayers;
|
||||
int i = 0;
|
||||
for ( QgsMapLayer *layer : layers )
|
||||
{
|
||||
@ -123,6 +125,8 @@ QVariantMap QgsPackageAlgorithm::processAlgorithm( const QVariantMap ¶meters
|
||||
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 ¶meters
|
||||
|
||||
QVariantMap outputs;
|
||||
outputs.insert( QStringLiteral( "OUTPUT" ), packagePath );
|
||||
outputs.insert( QStringLiteral( "OUTPUT_LAYERS" ), outputLayers );
|
||||
return outputs;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user