QGIS API Documentation 3.99.0-Master (752b475928d)
Loading...
Searching...
No Matches
qgsprocessingalgorithm.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingalgorithm.cpp
3 --------------------------
4 begin : December 2016
5 copyright : (C) 2016 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include <memory>
21
22#include "qgsapplication.h"
23#include "qgsexception.h"
25#include "qgsmeshlayer.h"
26#include "qgsmessagelog.h"
27#include "qgspointcloudlayer.h"
33#include "qgsprocessingutils.h"
34#include "qgsrasterfilewriter.h"
35#include "qgsrectangle.h"
36#include "qgsvectorlayer.h"
37
38#include <QRegularExpression>
39#include <QRegularExpressionMatch>
40
42{
43 qDeleteAll( mParameters );
44 qDeleteAll( mOutputs );
45}
46
47QgsProcessingAlgorithm *QgsProcessingAlgorithm::create( const QVariantMap &configuration ) const
48{
49 std::unique_ptr< QgsProcessingAlgorithm > creation( createInstance() );
50 if ( ! creation )
51 throw QgsProcessingException( QObject::tr( "Error creating algorithm from createInstance()" ) );
52 creation->setProvider( provider() );
53 creation->initAlgorithm( configuration );
54 return creation.release();
55}
56
58{
59 if ( mProvider )
60 return QStringLiteral( "%1:%2" ).arg( mProvider->id(), name() );
61 else
62 return name();
63}
64
66{
67 return QString();
68}
69
71{
72 return QString();
73}
74
76{
77 return QString();
78}
79
81{
82 return QString();
83}
84
89
91{
92 return QgsApplication::getThemeIcon( "/processingAlgorithm.svg" );
93}
94
96{
97 return QgsApplication::iconPath( QStringLiteral( "processingAlgorithm.svg" ) );
98}
99
104
106{
107 return true;
108}
109
110bool QgsProcessingAlgorithm::checkParameterValues( const QVariantMap &parameters, QgsProcessingContext &context, QString *message ) const
111{
112 for ( const QgsProcessingParameterDefinition *def : mParameters )
113 {
114 if ( !def->checkValueIsAcceptable( parameters.value( def->name() ), &context ) )
115 {
116 if ( message )
117 {
118 // TODO QGIS 4 - move the message handling to the parameter subclasses (but this
119 // requires a change in signature for the virtual checkValueIsAcceptable method)
121 *message = invalidSourceError( parameters, def->name() );
122 else if ( def->type() == QgsProcessingParameterFeatureSink::typeName() )
123 *message = invalidSinkError( parameters, def->name() );
124 else if ( def->type() == QgsProcessingParameterRasterLayer::typeName() )
125 *message = invalidRasterError( parameters, def->name() );
126 else if ( def->type() == QgsProcessingParameterPointCloudLayer::typeName() )
127 *message = invalidPointCloudError( parameters, def->name() );
128 else
129 *message = QObject::tr( "Incorrect parameter value for %1" ).arg( def->name() );
130 }
131 return false;
132 }
133 }
134 return true;
135}
136
137QVariantMap QgsProcessingAlgorithm::preprocessParameters( const QVariantMap &parameters )
138{
139 return parameters;
140}
141
142QVariantMap QgsProcessingAlgorithm::autogenerateParameterValues( const QVariantMap &, const QString &, Qgis::ProcessingMode ) const
143{
144 return {};
145}
146
148{
149 return mProvider;
150}
151
153{
154 mProvider = provider;
155
156 if ( mProvider && !mProvider->supportsNonFileBasedOutput() )
157 {
158 // need to update all destination parameters to turn off non file based outputs
159 for ( const QgsProcessingParameterDefinition *definition : std::as_const( mParameters ) )
160 {
161 if ( definition->isDestination() )
162 {
163 const QgsProcessingDestinationParameter *destParam = static_cast< const QgsProcessingDestinationParameter *>( definition );
164 const_cast< QgsProcessingDestinationParameter *>( destParam )->setSupportsNonFileBasedOutput( false );
165 }
166 }
167 }
168}
169
171{
172 return nullptr;
173}
174
176 QgsProcessingContext &context, QgsProcessingFeatureSource *source ) const
177{
178 // start with context's expression context
180
181 // If there's a source capable of generating a context scope, use it
182 if ( source )
183 {
185 if ( scope )
186 c << scope;
187 }
188 else if ( c.scopeCount() == 0 )
189 {
190 //empty scope, populate with initial scopes
193 }
194
195 c << QgsExpressionContextUtils::processingAlgorithmScope( this, parameters, context );
196 return c;
197}
198
199bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, QgsProcessingContext &context ) const
200{
202 {
203 // I'm a well behaved algorithm - I take work AWAY from users!
204 return true;
205 }
206
207 bool foundCrs = false;
209 for ( const QgsProcessingParameterDefinition *def : mParameters )
210 {
212 {
213 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( def, parameters, context );
214 if ( layer )
215 {
216 if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
217 {
218 return false;
219 }
220 else if ( !foundCrs && layer->crs().isValid() )
221 {
222 foundCrs = true;
223 crs = layer->crs();
224 }
225 }
226 }
227 else if ( def->type() == QgsProcessingParameterFeatureSource::typeName() )
228 {
229 std::unique_ptr< QgsFeatureSource > source( QgsProcessingParameters::parameterAsSource( def, parameters, context ) );
230 if ( source )
231 {
232 if ( foundCrs && source->sourceCrs().isValid() && crs != source->sourceCrs() )
233 {
234 return false;
235 }
236 else if ( !foundCrs && source->sourceCrs().isValid() )
237 {
238 foundCrs = true;
239 crs = source->sourceCrs();
240 }
241 }
242 }
243 else if ( def->type() == QgsProcessingParameterMultipleLayers::typeName() )
244 {
245 QList< QgsMapLayer *> layers = QgsProcessingParameters::parameterAsLayerList( def, parameters, context );
246 const auto constLayers = layers;
247 for ( QgsMapLayer *layer : constLayers )
248 {
249 if ( !layer )
250 continue;
251
252 if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
253 {
254 return false;
255 }
256 else if ( !foundCrs && layer->crs().isValid() )
257 {
258 foundCrs = true;
259 crs = layer->crs();
260 }
261 }
262 }
263 else if ( def->type() == QgsProcessingParameterExtent::typeName() )
264 {
266 if ( foundCrs && extentCrs.isValid() && crs != extentCrs )
267 {
268 return false;
269 }
270 else if ( !foundCrs && extentCrs.isValid() )
271 {
272 foundCrs = true;
273 crs = extentCrs;
274 }
275 }
276 else if ( def->type() == QgsProcessingParameterPoint::typeName() )
277 {
279 if ( foundCrs && pointCrs.isValid() && crs != pointCrs )
280 {
281 return false;
282 }
283 else if ( !foundCrs && pointCrs.isValid() )
284 {
285 foundCrs = true;
286 crs = pointCrs;
287 }
288 }
289 else if ( def->type() == QgsProcessingParameterGeometry::typeName() )
290 {
292 if ( foundCrs && geomCrs.isValid() && crs != geomCrs )
293 {
294 return false;
295 }
296 else if ( !foundCrs && geomCrs.isValid() )
297 {
298 foundCrs = true;
299 crs = geomCrs;
300 }
301 }
302
303 }
304 return true;
305}
306
307QString QgsProcessingAlgorithm::asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const
308{
309 QString s = QStringLiteral( "processing.run(\"%1\"," ).arg( id() );
310
311 QStringList parts;
312 for ( const QgsProcessingParameterDefinition *def : mParameters )
313 {
314 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
315 continue;
316
317 if ( !parameters.contains( def->name() ) )
318 continue;
319
320 parts << QStringLiteral( "'%1':%2" ).arg( def->name(), def->valueAsPythonString( parameters.value( def->name() ), context ) );
321 }
322
323 s += QStringLiteral( " {%1})" ).arg( parts.join( ',' ) );
324 return s;
325}
326
327QString QgsProcessingAlgorithm::asQgisProcessCommand( const QVariantMap &parameters, QgsProcessingContext &context, bool &ok ) const
328{
329 ok = true;
330 QStringList parts;
331 parts.append( QStringLiteral( "qgis_process" ) );
332 parts.append( QStringLiteral( "run" ) );
333 parts.append( id() );
334
336 // we only include the project path argument if a project is actually required by the algorithm
339
340 parts.append( context.asQgisProcessArguments( argumentFlags ) );
341
342 auto escapeIfNeeded = []( const QString & input ) -> QString
343 {
344 // play it safe and escape everything UNLESS it's purely alphanumeric characters (and a very select scattering of other common characters!)
345 const thread_local QRegularExpression nonAlphaNumericRx( QStringLiteral( "[^a-zA-Z0-9.\\-/_]" ) );
346 if ( nonAlphaNumericRx.match( input ).hasMatch() )
347 {
348 QString escaped = input;
349 escaped.replace( '\'', QLatin1String( "'\\''" ) );
350 return QStringLiteral( "'%1'" ).arg( escaped );
351 }
352 else
353 {
354 return input;
355 }
356 };
357
358 for ( const QgsProcessingParameterDefinition *def : mParameters )
359 {
360 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
361 continue;
362
363 if ( !parameters.contains( def->name() ) )
364 continue;
365
366 const QStringList partValues = def->valueAsStringList( parameters.value( def->name() ), context, ok );
367 if ( !ok )
368 return QString();
369
370 for ( const QString &partValue : partValues )
371 {
372 parts << QStringLiteral( "--%1=%2" ).arg( def->name(), escapeIfNeeded( partValue ) );
373 }
374 }
375
376 return parts.join( ' ' );
377}
378
379QVariantMap QgsProcessingAlgorithm::asMap( const QVariantMap &parameters, QgsProcessingContext &context ) const
380{
381 QVariantMap properties = context.exportToMap();
382
383 // we only include the project path argument if a project is actually required by the algorithm
385 properties.remove( QStringLiteral( "project_path" ) );
386
387 QVariantMap paramValues;
388 for ( const QgsProcessingParameterDefinition *def : mParameters )
389 {
390 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
391 continue;
392
393 if ( !parameters.contains( def->name() ) )
394 continue;
395
396 paramValues.insert( def->name(), def->valueAsJsonObject( parameters.value( def->name() ), context ) );
397 }
398
399 properties.insert( QStringLiteral( "inputs" ), paramValues );
400 return properties;
401}
402
404{
405 return addParameter( std::unique_ptr<QgsProcessingParameterDefinition>( definition ), createOutput );
406}
407
408bool QgsProcessingAlgorithm::addParameter( std::unique_ptr<QgsProcessingParameterDefinition> definition, bool createOutput )
409{
410 if ( !definition )
411 return false;
412
413 // check for duplicate named parameters
414 const QgsProcessingParameterDefinition *existingDef = QgsProcessingAlgorithm::parameterDefinition( definition->name() );
415 if ( existingDef && existingDef->name() == definition->name() ) // parameterDefinition is case-insensitive, but we DO allow case-different duplicate names
416 {
417 QgsMessageLog::logMessage( QObject::tr( "Duplicate parameter %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
418 return false;
419 }
420
421 if ( definition->isDestination() && mProvider )
422 {
423 QgsProcessingDestinationParameter *destParam = static_cast< QgsProcessingDestinationParameter *>( definition.get() );
424 if ( !mProvider->supportsNonFileBasedOutput() )
425 destParam->setSupportsNonFileBasedOutput( false );
426 }
427
428 definition->mAlgorithm = this;
429 mParameters << definition.release();
430 const QgsProcessingParameterDefinition *definitionRawPtr = mParameters.back();
431
432 if ( createOutput )
433 return createAutoOutputForParameter( definitionRawPtr );
434 else
435 return true;
436}
437
439{
441 if ( def )
442 {
443 delete def;
444 mParameters.removeAll( def );
445
446 // remove output automatically created when adding parameter
448 if ( outputDef && outputDef->autoCreated() )
449 {
450 delete outputDef;
451 mOutputs.removeAll( outputDef );
452 }
453 }
454}
455
457{
458 return addOutput( std::unique_ptr<QgsProcessingOutputDefinition>( definition ) );
459}
460
461bool QgsProcessingAlgorithm::addOutput( std::unique_ptr<QgsProcessingOutputDefinition> definition )
462{
463 if ( !definition )
464 return false;
465
466 // check for duplicate named outputs
467 if ( QgsProcessingAlgorithm::outputDefinition( definition->name() ) )
468 {
469 QgsMessageLog::logMessage( QObject::tr( "Duplicate output %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
470 return false;
471 }
472
473 mOutputs << definition.release();
474 return true;
475}
476
478{
479 return true;
480}
481
486
488{
489 // first pass - case sensitive match
490 for ( const QgsProcessingParameterDefinition *def : mParameters )
491 {
492 if ( def->name() == name )
493 return def;
494 }
495
496 // second pass - case insensitive
497 for ( const QgsProcessingParameterDefinition *def : mParameters )
498 {
499 if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
500 return def;
501 }
502 return nullptr;
503}
504
506{
507 int count = 0;
508 for ( const QgsProcessingParameterDefinition *def : mParameters )
509 {
510 if ( !( def->flags() & Qgis::ProcessingParameterFlag::Hidden ) )
511 count++;
512 }
513 return count;
514}
515
517{
519 for ( const QgsProcessingParameterDefinition *def : mParameters )
520 {
521 if ( def->isDestination() )
522 result << def;
523 }
524 return result;
525}
526
528{
529 for ( const QgsProcessingOutputDefinition *def : mOutputs )
530 {
531 if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
532 return def;
533 }
534 return nullptr;
535}
536
538{
539 for ( const QgsProcessingOutputDefinition *def : mOutputs )
540 {
541 if ( def->type() == QLatin1String( "outputHtml" ) )
542 return true;
543 }
544 return false;
545}
546
547QgsProcessingAlgorithm::VectorProperties QgsProcessingAlgorithm::sinkProperties( const QString &, const QVariantMap &, QgsProcessingContext &, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> & ) const
548{
549 return VectorProperties();
550}
551
552QVariantMap QgsProcessingAlgorithm::run( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok, const QVariantMap &configuration, bool catchExceptions ) const
553{
554 std::unique_ptr< QgsProcessingAlgorithm > alg( create( configuration ) );
555 if ( ok )
556 *ok = false;
557
558 bool res = alg->prepare( parameters, context, feedback );
559 if ( !res )
560 return QVariantMap();
561
562 QVariantMap runRes;
563 bool success = false;
564 try
565 {
566 runRes = alg->runPrepared( parameters, context, feedback );
567 success = true;
568 }
569 catch ( QgsProcessingException &e )
570 {
571 if ( !catchExceptions )
572 {
573 alg->postProcess( context, feedback, false );
574 throw e;
575 }
576
577 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
578 feedback->reportError( e.what() );
579 }
580
581 if ( ok )
582 *ok = success;
583
584 QVariantMap ppRes = alg->postProcess( context, feedback, success );
585 if ( !ppRes.isEmpty() )
586 return ppRes;
587 else
588 return runRes;
589}
590
591bool QgsProcessingAlgorithm::prepare( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
592{
593 // cppcheck-suppress assertWithSideEffect
594 Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::prepare", "prepare() must be called from the same thread as context was created in" );
595 Q_ASSERT_X( !mHasPrepared, "QgsProcessingAlgorithm::prepare", "prepare() has already been called for the algorithm instance" );
596 try
597 {
598 mHasPrepared = prepareAlgorithm( parameters, context, feedback );
599 return mHasPrepared;
600 }
601 catch ( QgsProcessingException &e )
602 {
603 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
604 feedback->reportError( e.what() );
605 return false;
606 }
607}
608
609QVariantMap QgsProcessingAlgorithm::runPrepared( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
610{
611 Q_ASSERT_X( mHasPrepared, "QgsProcessingAlgorithm::runPrepared", QStringLiteral( "prepare() was not called for the algorithm instance %1" ).arg( name() ).toLatin1() );
612 Q_ASSERT_X( !mHasExecuted, "QgsProcessingAlgorithm::runPrepared", "runPrepared() was already called for this algorithm instance" );
613
614 // Hey kids, let's all be thread safe! It's the fun thing to do!
615 //
616 // First, let's see if we're going to run into issues.
617 QgsProcessingContext *runContext = nullptr;
618 if ( context.thread() == QThread::currentThread() )
619 {
620 // OH. No issues. Seems you're running everything in the same thread, so go about your business. Sorry about
621 // the intrusion, we're just making sure everything's nice and safe here. We like to keep a clean and tidy neighbourhood,
622 // you know, for the kids and dogs and all.
623 runContext = &context;
624 }
625 else
626 {
627 // HA! I knew things looked a bit suspicious - seems you're running this algorithm in a different thread
628 // from that which the passed context has an affinity for. That's fine and all, but we need to make sure
629 // we proceed safely...
630
631 // So first we create a temporary local context with affinity for the current thread
632 mLocalContext = std::make_unique<QgsProcessingContext>( );
633 // copy across everything we can safely do from the passed context
634 mLocalContext->copyThreadSafeSettings( context );
635
636 // and we'll run the actual algorithm processing using the local thread safe context
637 runContext = mLocalContext.get();
638 }
639
640 std::unique_ptr< QgsProcessingModelInitialRunConfig > modelConfig = context.takeModelInitialRunConfig();
641 if ( modelConfig )
642 {
643 std::unique_ptr< QgsMapLayerStore > modelPreviousLayerStore = modelConfig->takePreviousLayerStore();
644 if ( modelPreviousLayerStore )
645 {
646 // move layers from previous layer store to context's temporary layer store, in a thread-safe way
647 Q_ASSERT_X( !modelPreviousLayerStore->thread(), "QgsProcessingAlgorithm::runPrepared", "QgsProcessingModelConfig::modelPreviousLayerStore must have been pushed to a nullptr thread" );
648 modelPreviousLayerStore->moveToThread( QThread::currentThread() );
649 runContext->temporaryLayerStore()->transferLayersFromStore( modelPreviousLayerStore.get() );
650 }
651 runContext->setModelInitialRunConfig( std::move( modelConfig ) );
652 }
653
654 mHasExecuted = true;
655 try
656 {
657 QVariantMap runResults = processAlgorithm( parameters, *runContext, feedback );
658
659 if ( mLocalContext )
660 {
661 // ok, time to clean things up. We need to push the temporary context back into
662 // the thread that the passed context is associated with (we can only push from the
663 // current thread, so we HAVE to do this here)
664 mLocalContext->pushToThread( context.thread() );
665 }
666 return runResults;
667 }
668 catch ( QgsProcessingException & )
669 {
670 if ( mLocalContext )
671 {
672 // see above!
673 mLocalContext->pushToThread( context.thread() );
674 }
675 //rethrow
676 throw;
677 }
678}
679
681{
682 // cppcheck-suppress assertWithSideEffect
683 Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::postProcess", "postProcess() must be called from the same thread the context was created in" );
684 Q_ASSERT_X( mHasExecuted, "QgsProcessingAlgorithm::postProcess", QStringLiteral( "algorithm instance %1 was not executed" ).arg( name() ).toLatin1() );
685 Q_ASSERT_X( !mHasPostProcessed, "QgsProcessingAlgorithm::postProcess", "postProcess() was already called for this algorithm instance" );
686
687 if ( mLocalContext )
688 {
689 // algorithm was processed using a temporary thread safe context. So now we need
690 // to take the results from that temporary context, and smash them into the passed
691 // context
692 context.takeResultsFrom( *mLocalContext );
693 // now get lost, we don't need you anymore
694 mLocalContext.reset();
695 }
696
697 mHasPostProcessed = true;
698 if ( runResult )
699 {
700 try
701 {
702 return postProcessAlgorithm( context, feedback );
703 }
704 catch ( QgsProcessingException &e )
705 {
706 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
707 feedback->reportError( e.what() );
708 return QVariantMap();
709 }
710 }
711 else
712 {
713 return QVariantMap();
714 }
715}
716
717QString QgsProcessingAlgorithm::parameterAsString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
718{
720}
721
722QString QgsProcessingAlgorithm::parameterAsExpression( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
723{
725}
726
727double QgsProcessingAlgorithm::parameterAsDouble( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
728{
730}
731
732int QgsProcessingAlgorithm::parameterAsInt( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
733{
734 return QgsProcessingParameters::parameterAsInt( parameterDefinition( name ), parameters, context );
735}
736
737QList<int> QgsProcessingAlgorithm::parameterAsInts( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
738{
739 return QgsProcessingParameters::parameterAsInts( parameterDefinition( name ), parameters, context );
740}
741
742int QgsProcessingAlgorithm::parameterAsEnum( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
743{
744 return QgsProcessingParameters::parameterAsEnum( parameterDefinition( name ), parameters, context );
745}
746
747QList<int> QgsProcessingAlgorithm::parameterAsEnums( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
748{
750}
751
752QString QgsProcessingAlgorithm::parameterAsEnumString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
753{
755}
756
757QStringList QgsProcessingAlgorithm::parameterAsEnumStrings( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
758{
760}
761
762bool QgsProcessingAlgorithm::parameterAsBool( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
763{
764 return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
765}
766
767bool QgsProcessingAlgorithm::parameterAsBoolean( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
768{
769 return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
770}
771
772QgsFeatureSink *QgsProcessingAlgorithm::parameterAsSink( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QString &destinationIdentifier, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, QgsFeatureSink::SinkFlags sinkFlags, const QVariantMap &createOptions, const QStringList &datasourceOptions, const QStringList &layerOptions ) const
773{
774 if ( !parameterDefinition( name ) )
775 throw QgsProcessingException( QObject::tr( "No parameter definition for the sink '%1'" ).arg( name ) );
776
777 return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
778}
779
780QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
781{
783}
784
785QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback ) const
786{
787 return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback );
788}
789
790QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPathAndLayerName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName ) const
791{
792 return QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback, layerName );
793}
794
795QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
796{
798}
799
800QgsRasterLayer *QgsProcessingAlgorithm::parameterAsRasterLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
801{
803}
804
805QgsMeshLayer *QgsProcessingAlgorithm::parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
806{
808}
809
810QString QgsProcessingAlgorithm::parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
811{
813}
814
815QString QgsProcessingAlgorithm::parameterAsOutputFormat( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
816{
818}
819
820QString QgsProcessingAlgorithm::parameterAsOutputRasterFormat( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
821{
822 QString outputFormat = parameterAsOutputFormat( parameters, name, context );
823 if ( outputFormat.isEmpty() )
824 {
825 QString outputFile = parameterAsOutputLayer( parameters, name, context );
826 if ( !outputFile.isEmpty() )
827 {
828 const QFileInfo fi( outputFile );
829 outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() );
830 }
831 }
832 return outputFormat;
833}
834
835QString QgsProcessingAlgorithm::parameterAsFileOutput( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
836{
838}
839
840QgsVectorLayer *QgsProcessingAlgorithm::parameterAsVectorLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
841{
843}
844
845QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
846{
847 return QgsProcessingParameters::parameterAsCrs( parameterDefinition( name ), parameters, context );
848}
849
850QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsExtentCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
851{
853}
854
855QgsRectangle QgsProcessingAlgorithm::parameterAsExtent( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
856{
857 return QgsProcessingParameters::parameterAsExtent( parameterDefinition( name ), parameters, context, crs );
858}
859
860QgsGeometry QgsProcessingAlgorithm::parameterAsExtentGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
861{
863}
864
865QgsPointXY QgsProcessingAlgorithm::parameterAsPoint( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
866{
867 return QgsProcessingParameters::parameterAsPoint( parameterDefinition( name ), parameters, context, crs );
868}
869
870QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsPointCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
871{
873}
874
875QgsGeometry QgsProcessingAlgorithm::parameterAsGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
876{
877 return QgsProcessingParameters::parameterAsGeometry( parameterDefinition( name ), parameters, context, crs );
878}
879
880QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsGeometryCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
881{
883}
884
885QString QgsProcessingAlgorithm::parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
886{
887 return QgsProcessingParameters::parameterAsFile( parameterDefinition( name ), parameters, context );
888}
889
890QVariantList QgsProcessingAlgorithm::parameterAsMatrix( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
891{
893}
894
895QList<QgsMapLayer *> QgsProcessingAlgorithm::parameterAsLayerList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags ) const
896{
898}
899
900QStringList QgsProcessingAlgorithm::parameterAsFileList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
901{
903}
904
905QList<double> QgsProcessingAlgorithm::parameterAsRange( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
906{
908}
909
910QStringList QgsProcessingAlgorithm::parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
911{
913}
914
915QStringList QgsProcessingAlgorithm::parameterAsStrings( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
916{
918}
919
920QgsPrintLayout *QgsProcessingAlgorithm::parameterAsLayout( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
921{
923}
924
925QgsLayoutItem *QgsProcessingAlgorithm::parameterAsLayoutItem( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsPrintLayout *layout )
926{
927 return QgsProcessingParameters::parameterAsLayoutItem( parameterDefinition( name ), parameters, context, layout );
928}
929
930QColor QgsProcessingAlgorithm::parameterAsColor( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
931{
933}
934
935QString QgsProcessingAlgorithm::parameterAsConnectionName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
936{
938}
939
940QDateTime QgsProcessingAlgorithm::parameterAsDateTime( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
941{
943}
944
945QString QgsProcessingAlgorithm::parameterAsSchema( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
946{
948}
949
950QString QgsProcessingAlgorithm::parameterAsDatabaseTableName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
951{
953}
954
959
960QgsAnnotationLayer *QgsProcessingAlgorithm::parameterAsAnnotationLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
961{
963}
964
965QString QgsProcessingAlgorithm::invalidSourceError( const QVariantMap &parameters, const QString &name )
966{
967 if ( !parameters.contains( name ) )
968 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
969 else
970 {
971 QVariant var = parameters.value( name );
972 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
973 {
974 QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
975 var = fromVar.source;
976 }
977 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
978 {
979 QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
980 var = fromVar.sink;
981 }
982 if ( var.userType() == qMetaTypeId<QgsProperty>() )
983 {
984 QgsProperty p = var.value< QgsProperty >();
986 {
987 var = p.staticValue();
988 }
989 }
990 if ( !var.toString().isEmpty() )
991 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
992 else
993 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
994 }
995}
996
997QString QgsProcessingAlgorithm::invalidRasterError( const QVariantMap &parameters, const QString &name )
998{
999 if ( !parameters.contains( name ) )
1000 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
1001 else
1002 {
1003 QVariant var = parameters.value( name );
1004 if ( var.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
1005 {
1006 QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( var );
1007 var = fromVar.source;
1008 }
1009 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1010 {
1011 QgsProperty p = var.value< QgsProperty >();
1013 {
1014 var = p.staticValue();
1015 }
1016 }
1017 if ( !var.toString().isEmpty() )
1018 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
1019 else
1020 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
1021 }
1022}
1023
1024QString QgsProcessingAlgorithm::invalidSinkError( const QVariantMap &parameters, const QString &name )
1025{
1026 if ( !parameters.contains( name ) )
1027 return QObject::tr( "Could not create destination layer for %1: no value specified for parameter" ).arg( name );
1028 else
1029 {
1030 QVariant var = parameters.value( name );
1031 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1032 {
1033 QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1034 var = fromVar.sink;
1035 }
1036 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1037 {
1038 QgsProperty p = var.value< QgsProperty >();
1040 {
1041 var = p.staticValue();
1042 }
1043 }
1044 if ( !var.toString().isEmpty() )
1045 return QObject::tr( "Could not create destination layer for %1: %2" ).arg( name, var.toString() );
1046 else
1047 return QObject::tr( "Could not create destination layer for %1: invalid value" ).arg( name );
1048 }
1049}
1050
1051QString QgsProcessingAlgorithm::invalidPointCloudError( const QVariantMap &parameters, const QString &name )
1052{
1053 if ( !parameters.contains( name ) )
1054 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
1055 else
1056 {
1057 QVariant var = parameters.value( name );
1058 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1059 {
1060 QgsProperty p = var.value< QgsProperty >();
1062 {
1063 var = p.staticValue();
1064 }
1065 }
1066 if ( !var.toString().isEmpty() )
1067 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
1068 else
1069 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
1070 }
1071}
1072
1073QString QgsProcessingAlgorithm::writeFeatureError( QgsFeatureSink *sink, const QVariantMap &parameters, const QString &name )
1074{
1075 Q_UNUSED( sink );
1076 Q_UNUSED( parameters );
1077 const QString lastError = sink->lastError();
1078 if ( !lastError.isEmpty() )
1079 {
1080 if ( !name.isEmpty() )
1081 return QObject::tr( "Could not write feature into %1: %2" ).arg( name, lastError );
1082 else
1083 return QObject::tr( "Could not write feature: %1" ).arg( lastError );
1084 }
1085 else
1086 {
1087 if ( !name.isEmpty() )
1088 return QObject::tr( "Could not write feature into %1" ).arg( name );
1089 else
1090 return QObject::tr( "Could not write feature" );
1091 }
1092}
1093
1095{
1096 Q_UNUSED( layer )
1097 return false;
1098}
1099
1100
1101bool QgsProcessingAlgorithm::createAutoOutputForParameter( const QgsProcessingParameterDefinition *parameter )
1102{
1103 if ( !parameter->isDestination() )
1104 return true; // nothing created, but nothing went wrong - so return true
1105
1106 const QgsProcessingDestinationParameter *dest = static_cast< const QgsProcessingDestinationParameter * >( parameter );
1108 if ( !output )
1109 return true; // nothing created - but nothing went wrong - so return true
1110 output->setAutoCreated( true );
1111
1112 if ( !addOutput( output ) )
1113 {
1114 // couldn't add output - probably a duplicate name
1115 return false;
1116 }
1117 else
1118 {
1119 return true;
1120 }
1121}
1122
1123
1124//
1125// QgsProcessingFeatureBasedAlgorithm
1126//
1127
1134
1136{
1138 initParameters( config );
1139 addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), outputName(), outputLayerType(), QVariant(), false, true, true ) );
1140}
1141
1143{
1144 return QStringLiteral( "INPUT" );
1145}
1146
1148{
1149 return QObject::tr( "Input layer" );
1150}
1151
1153{
1154 return QList<int>();
1155}
1156
1161
1166
1171
1173{
1174 return inputWkbType;
1175}
1176
1178{
1179 return inputFields;
1180}
1181
1186
1188{
1189}
1190
1192{
1193 if ( mSource )
1194 return mSource->sourceCrs();
1195 else
1197}
1198
1199QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
1200{
1201 prepareSource( parameters, context );
1202 QString dest;
1203 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest,
1204 outputFields( mSource->fields() ),
1205 outputWkbType( mSource->wkbType() ),
1206 outputCrs( mSource->sourceCrs() ),
1207 sinkFlags() ) );
1208 if ( !sink )
1209 throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );
1210
1211 // prepare expression context for feature iteration
1212 QgsExpressionContext prevContext = context.expressionContext();
1213 QgsExpressionContext algContext = prevContext;
1214
1215 algContext.appendScopes( createExpressionContext( parameters, context, mSource.get() ).takeScopes() );
1216 context.setExpressionContext( algContext );
1217
1218 long count = mSource->featureCount();
1219
1220 QgsFeature f;
1221 QgsFeatureIterator it = mSource->getFeatures( request(), sourceFlags() );
1222
1223 double step = count > 0 ? 100.0 / count : 1;
1224 int current = 0;
1225 while ( it.nextFeature( f ) )
1226 {
1227 if ( feedback->isCanceled() )
1228 {
1229 break;
1230 }
1231
1232 context.expressionContext().setFeature( f );
1233 const QgsFeatureList transformed = processFeature( f, context, feedback );
1234 for ( QgsFeature transformedFeature : transformed )
1235 {
1236 if ( !sink->addFeature( transformedFeature, QgsFeatureSink::FastInsert ) )
1237 {
1238 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QString() ) );
1239 }
1240 }
1241
1242 feedback->setProgress( current * step );
1243 current++;
1244 }
1245
1246 sink->finalize();
1247
1248 mSource.reset();
1249
1250 // probably not necessary - context's aren't usually recycled, but can't hurt
1251 context.setExpressionContext( prevContext );
1252
1253 QVariantMap outputs;
1254 outputs.insert( QStringLiteral( "OUTPUT" ), dest );
1255 return outputs;
1256}
1257
1262
1264{
1265 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
1266 if ( !layer )
1267 return false;
1268
1269 Qgis::GeometryType inPlaceGeometryType = layer->geometryType();
1270 if ( !inputLayerTypes().empty() &&
1271 !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::Vector ) ) &&
1272 !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry ) ) &&
1273 ( ( inPlaceGeometryType == Qgis::GeometryType::Polygon && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon ) ) ) ||
1274 ( inPlaceGeometryType == Qgis::GeometryType::Line && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorLine ) ) ) ||
1275 ( inPlaceGeometryType == Qgis::GeometryType::Point && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorPoint ) ) ) ) )
1276 return false;
1277
1279 if ( inPlaceGeometryType == Qgis::GeometryType::Point )
1280 type = Qgis::WkbType::Point;
1281 else if ( inPlaceGeometryType == Qgis::GeometryType::Line )
1283 else if ( inPlaceGeometryType == Qgis::GeometryType::Polygon )
1285
1286 if ( QgsWkbTypes::geometryType( outputWkbType( type ) ) != inPlaceGeometryType )
1287 return false;
1288
1289 return true;
1290}
1291
1293{
1294 if ( ! mSource )
1295 {
1296 mSource.reset( parameterAsSource( parameters, inputParameterName(), context ) );
1297 if ( !mSource )
1299 }
1300}
1301
1302
1303QgsProcessingAlgorithm::VectorProperties QgsProcessingFeatureBasedAlgorithm::sinkProperties( const QString &sink, const QVariantMap &parameters, QgsProcessingContext &context, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> &sourceProperties ) const
1304{
1306 if ( sink == QLatin1String( "OUTPUT" ) )
1307 {
1308 if ( sourceProperties.value( QStringLiteral( "INPUT" ) ).availability == Qgis::ProcessingPropertyAvailability::Available )
1309 {
1310 const VectorProperties inputProps = sourceProperties.value( QStringLiteral( "INPUT" ) );
1311 result.fields = outputFields( inputProps.fields );
1312 result.crs = outputCrs( inputProps.crs );
1313 result.wkbType = outputWkbType( inputProps.wkbType );
1315 return result;
1316 }
1317 else
1318 {
1319 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
1320 if ( source )
1321 {
1322 result.fields = outputFields( source->fields() );
1323 result.crs = outputCrs( source->sourceCrs() );
1324 result.wkbType = outputWkbType( source->wkbType() );
1326 return result;
1327 }
1328 }
1329 }
1330 return result;
1331}
1332
ProcessingSourceType
Processing data source types.
Definition qgis.h:3531
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition qgis.h:3539
@ VectorAnyGeometry
Any vector layer with geometry.
Definition qgis.h:3533
@ VectorPoint
Vector point layers.
Definition qgis.h:3534
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3536
@ VectorLine
Vector line layers.
Definition qgis.h:3535
ProcessingMode
Types of modes which Processing widgets can be created for.
Definition qgis.h:3671
@ Critical
Critical/error message.
Definition qgis.h:159
@ Static
Static property.
Definition qgis.h:684
@ Available
Properties are available.
Definition qgis.h:3644
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:358
@ Point
Points.
Definition qgis.h:359
@ Line
Lines.
Definition qgis.h:360
@ Polygon
Polygons.
Definition qgis.h:361
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3609
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
Definition qgis.h:3630
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
@ Point
Point.
Definition qgis.h:279
@ LineString
LineString.
Definition qgis.h:280
@ Polygon
Polygon.
Definition qgis.h:281
@ Unknown
Unknown.
Definition qgis.h:278
@ SupportsBatch
Algorithm supports batch mode.
Definition qgis.h:3585
@ SupportsInPlaceEdits
Algorithm supports in-place editing.
Definition qgis.h:3590
@ RequiresMatchingCrs
Algorithm requires that all input layers have matching coordinate reference systems.
Definition qgis.h:3587
@ CanCancel
Algorithm can be canceled.
Definition qgis.h:3586
@ RequiresProject
The algorithm requires that a valid QgsProject is available from the processing context in order to e...
Definition qgis.h:3596
@ Hidden
Parameter is hidden and should not be shown to users.
Definition qgis.h:3764
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Definition qgis.h:3722
Represents a map layer containing a set of georeferenced annotations, e.g.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString what() const
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsExpressionContextScope * processingAlgorithmScope(const QgsProcessingAlgorithm *algorithm, const QVariantMap &parameters, QgsProcessingContext &context)
Creates a new scope which contains variables and functions relating to a processing algorithm,...
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QList< QgsExpressionContextScope * > takeScopes()
Returns all scopes from this context and remove them, leaving this context without any context.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
An interface for objects which accept features via addFeature(s) methods.
QFlags< SinkFlag > SinkFlags
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
virtual QString lastError() const
Returns the most recent error encountered by the sink, e.g.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:53
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition qgsfeedback.h:61
Container of fields for a vector layer.
Definition qgsfields.h:46
A geometry is the spatial representation of a feature.
Base class for graphical items within a QgsLayout.
void transferLayersFromStore(QgsMapLayerStore *other)
Transfers all the map layers contained within another map layer store and adds them to this store.
Base class for all map layer types.
Definition qgsmaplayer.h:80
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:87
Represents a mesh layer supporting display of data on structured or unstructured meshes.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
Represents a map layer supporting display of point clouds.
Represents a 2D point.
Definition qgspointxy.h:60
Print layout, a QgsLayout subclass for static or atlas-based layouts.
QString parameterAsCompatibleSourceLayerPath(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr) const
Evaluates the parameter with matching name to a source vector layer file path of compatible format.
QString parameterAsConnectionName(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a connection name string.
const QgsProcessingOutputDefinition * outputDefinition(const QString &name) const
Returns a matching output by name.
QString parameterAsCompatibleSourceLayerPathAndLayerName(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr) const
Evaluates the parameter with matching name to a source vector layer file path and layer name of compa...
QStringList parameterAsStrings(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of strings (e.g.
QgsGeometry parameterAsExtentGeometry(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Evaluates the parameter with matching name to a rectangular extent, and returns a geometry covering t...
virtual QgsProcessingAlgorithm * createInstance() const =0
Creates a new instance of the algorithm class.
QgsMapLayer * parameterAsLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a map layer.
QgsRasterLayer * parameterAsRasterLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a raster layer.
virtual bool prepareAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm to run using the specified parameters.
int parameterAsInt(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static integer value.
virtual QString helpUrl() const
Returns a url pointing to the algorithm's help page.
virtual QVariantMap autogenerateParameterValues(const QVariantMap &existingParameters, const QString &changedParameter, Qgis::ProcessingMode mode) const
Returns a map of default auto-generated parameters to fill in, based on existing parameters.
int parameterAsEnum(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a enum value.
void setProvider(QgsProcessingProvider *provider)
Associates this algorithm with its provider.
virtual QIcon icon() const
Returns an icon for the algorithm.
virtual QString shortHelpString() const
Returns a localised short helper string for the algorithm.
QString parameterAsOutputRasterFormat(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a output format.
virtual bool validateInputCrs(const QVariantMap &parameters, QgsProcessingContext &context) const
Checks whether the coordinate reference systems for the specified set of parameters are valid for the...
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
virtual QString shortDescription() const
Returns an optional translated short description of the algorithm.
Q_DECL_DEPRECATED QStringList parameterAsFields(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of fields.
QgsProcessingFeatureSource * parameterAsSource(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a feature source.
int countVisibleParameters() const
Returns the number of visible (non-hidden) parameters defined by this algorithm.
QString parameterAsFile(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a file/folder name.
QString id() const
Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and th...
virtual QVariantMap preprocessParameters(const QVariantMap &parameters)
Pre-processes a set of parameters, allowing the algorithm to clean their values.
static QString invalidRasterError(const QVariantMap &parameters, const QString &name)
Returns a user-friendly string to use as an error when a raster layer input could not be loaded.
QgsVectorLayer * parameterAsVectorLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a vector layer.
static QString writeFeatureError(QgsFeatureSink *sink, const QVariantMap &parameters, const QString &name)
Returns a user-friendly string to use as an error when a feature cannot be written into a sink.
QStringList parameterAsFileList(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of files (for QgsProcessingParameterMultipleLaye...
QVariantMap postProcess(QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool runResult=true)
Should be called in the main thread following the completion of runPrepared().
bool prepare(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm for execution.
QString parameterAsDatabaseTableName(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a database table name string.
QString parameterAsExpression(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to an expression.
void removeParameter(const QString &name)
Removes the parameter with matching name from the algorithm, and deletes any existing definition.
QList< QgsMapLayer * > parameterAsLayerList(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags()) const
Evaluates the parameter with matching name to a list of map layers.
QgsAnnotationLayer * parameterAsAnnotationLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to an annotation layer.
bool addParameter(QgsProcessingParameterDefinition *parameterDefinition, bool createOutput=true)
Adds a parameter definition to the algorithm.
QgsGeometry parameterAsGeometry(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Evaluates the parameter with matching name to a geometry.
virtual QString asQgisProcessCommand(const QVariantMap &parameters, QgsProcessingContext &context, bool &ok) const
Returns a command string which will execute the algorithm using the specified parameters via the comm...
bool parameterAsBoolean(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static boolean value.
QList< double > parameterAsRange(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a range of values.
QVariantList parameterAsMatrix(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a matrix/table of values.
QString parameterAsOutputFormat(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a output format.
virtual QgsExpressionContext createExpressionContext(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeatureSource *source=nullptr) const
Creates an expression context relating to the algorithm.
QgsProcessingParameterDefinitions destinationParameterDefinitions() const
Returns a list of destination parameters definitions utilized by the algorithm.
static QString invalidSinkError(const QVariantMap &parameters, const QString &name)
Returns a user-friendly string to use as an error when a sink parameter could not be created.
bool hasHtmlOutputs() const
Returns true if this algorithm generates HTML outputs.
bool addOutput(QgsProcessingOutputDefinition *outputDefinition)
Adds an output definition to the algorithm.
double parameterAsDouble(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static double value.
QgsCoordinateReferenceSystem parameterAsPointCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Returns the coordinate reference system associated with an point parameter value.
QString parameterAsString(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static string value.
QgsRectangle parameterAsExtent(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Evaluates the parameter with matching name to a rectangular extent.
QgsPrintLayout * parameterAsLayout(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a print layout.
virtual QVariantMap processAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)=0
Runs the algorithm using the specified parameters.
QgsProcessingAlgorithm()=default
Constructor for QgsProcessingAlgorithm.
QgsPointCloudLayer * parameterAsPointCloudLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags()) const
Evaluates the parameter with matching name to a point cloud layer.
QgsCoordinateReferenceSystem parameterAsCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a coordinate reference system.
QString parameterAsFileOutput(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a file based output destination.
QgsLayoutItem * parameterAsLayoutItem(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching name to a print layout item, taken from the specified layout.
const QgsProcessingParameterDefinition * parameterDefinition(const QString &name) const
Returns a matching parameter by name.
virtual QString svgIconPath() const
Returns a path to an SVG version of the algorithm's icon.
QgsFeatureSink * parameterAsSink(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QString &destinationIdentifier, const QgsFields &fields, Qgis::WkbType geometryType=Qgis::WkbType::NoGeometry, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem(), QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList()) const
Evaluates the parameter with matching name to a feature sink.
QVariantMap run(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok=nullptr, const QVariantMap &configuration=QVariantMap(), bool catchExceptions=true) const
Executes the algorithm using the specified parameters.
QString parameterAsSchema(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a database schema name string.
virtual Q_DECL_DEPRECATED QString helpString() const
Returns a localised help string for the algorithm.
QStringList parameterAsEnumStrings(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to list of static enum strings.
QgsPointXY parameterAsPoint(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Evaluates the parameter with matching name to a point.
virtual QWidget * createCustomParametersWidget(QWidget *parent=nullptr) const
If an algorithm subclass implements a custom parameters widget, a copy of this widget should be const...
virtual QgsProcessingAlgorithm::VectorProperties sinkProperties(const QString &sink, const QVariantMap &parameters, QgsProcessingContext &context, const QMap< QString, QgsProcessingAlgorithm::VectorProperties > &sourceProperties) const
Returns the vector properties which will be used for the sink with matching name.
QgsCoordinateReferenceSystem parameterAsExtentCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Returns the coordinate reference system associated with an extent parameter value.
QgsMeshLayer * parameterAsMeshLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a mesh layer.
QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Returns the coordinate reference system associated with a geometry parameter value.
virtual QString asPythonCommand(const QVariantMap &parameters, QgsProcessingContext &context) const
Returns a Python command string which can be executed to run the algorithm using the specified parame...
QString parameterAsEnumString(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static enum string.
virtual QVariantMap postProcessAlgorithm(QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Allows the algorithm to perform any required cleanup tasks.
virtual bool canExecute(QString *errorMessage=nullptr) const
Returns true if the algorithm can execute.
QgsProcessingProvider * provider() const
Returns the provider to which this algorithm belongs.
QgsProcessingAlgorithm * create(const QVariantMap &configuration=QVariantMap()) const
Creates a copy of the algorithm, ready for execution.
virtual QVariantMap asMap(const QVariantMap &parameters, QgsProcessingContext &context) const
Returns a JSON serializable variant map containing the specified parameters and context settings.
QList< int > parameterAsInts(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of integer values.
virtual bool supportInPlaceEdit(const QgsMapLayer *layer) const
Checks whether this algorithm supports in-place editing on the given layer Default implementation ret...
bool parameterAsBool(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static boolean value.
virtual QString name() const =0
Returns the algorithm name, used for identifying the algorithm.
static QString invalidPointCloudError(const QVariantMap &parameters, const QString &name)
Returns a user-friendly string to use as an error when a point cloud layer input could not be loaded.
QList< int > parameterAsEnums(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to list of enum values.
virtual bool checkParameterValues(const QVariantMap &parameters, QgsProcessingContext &context, QString *message=nullptr) const
Checks the supplied parameter values to verify that they satisfy the requirements of this algorithm i...
virtual Qgis::ProcessingAlgorithmDocumentationFlags documentationFlags() const
Returns the flags describing algorithm behavior for documentation purposes.
static QString invalidSourceError(const QVariantMap &parameters, const QString &name)
Returns a user-friendly string to use as an error when a source parameter could not be loaded.
QVariantMap runPrepared(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Runs the algorithm, which has been prepared by an earlier call to prepare().
QDateTime parameterAsDateTime(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a DateTime, or returns an invalid date time if the para...
QString parameterAsOutputLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a output layer destination.
QColor parameterAsColor(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a color, or returns an invalid color if the parameter w...
Contains information about the context in which a processing algorithm is executed.
QThread * thread()
Returns the thread in which the context lives.
@ IncludeProjectPath
Include the associated project path argument.
QFlags< ProcessArgumentFlag > ProcessArgumentFlags
std::unique_ptr< QgsProcessingModelInitialRunConfig > takeModelInitialRunConfig()
Takes the model initial run configuration from the context.
QgsExpressionContext & expressionContext()
Returns the expression context.
void takeResultsFrom(QgsProcessingContext &context)
Takes the results from another context and merges them with the results currently stored in this cont...
QVariantMap exportToMap() const
Exports the context's settings to a variant map.
QStringList asQgisProcessArguments(QgsProcessingContext::ProcessArgumentFlags flags=QgsProcessingContext::ProcessArgumentFlags()) const
Returns list of the equivalent qgis_process arguments representing the settings from the context.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
void setModelInitialRunConfig(std::unique_ptr< QgsProcessingModelInitialRunConfig > config)
Sets the model initial run configuration, used to run a model algorithm.
QgsMapLayerStore * temporaryLayerStore()
Returns a reference to the layer store used for storing temporary layers during algorithm execution.
Base class for all parameter definitions which represent file or layer destinations,...
virtual QgsProcessingOutputDefinition * toOutputDefinition() const =0
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
void setSupportsNonFileBasedOutput(bool supportsNonFileBasedOutput)
Sets whether the destination parameter supports non filed-based outputs, such as memory layers or dir...
Custom exception class for processing related exceptions.
virtual QgsFeatureRequest request() const
Returns the feature request used for fetching features to process from the source layer.
virtual QgsFeatureList processFeature(const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback)=0
Processes an individual input feature from the source.
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation for...
virtual QString inputParameterName() const
Returns the name of the parameter corresponding to the input layer.
QgsProcessingAlgorithm::VectorProperties sinkProperties(const QString &sink, const QVariantMap &parameters, QgsProcessingContext &context, const QMap< QString, QgsProcessingAlgorithm::VectorProperties > &sourceProperties) const override
Returns the vector properties which will be used for the sink with matching name.
virtual void initParameters(const QVariantMap &configuration=QVariantMap())
Initializes any extra parameters added by the algorithm subclass.
Qgis::ProcessingAlgorithmFlags flags() const override
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
virtual Qgis::WkbType outputWkbType(Qgis::WkbType inputWkbType) const
Maps the input WKB geometry type (inputWkbType) to the corresponding output WKB type generated by the...
virtual Qgis::ProcessingSourceType outputLayerType() const
Returns the layer type for layers generated by this algorithm, if this is possible to determine in ad...
virtual QgsCoordinateReferenceSystem outputCrs(const QgsCoordinateReferenceSystem &inputCrs) const
Maps the input source coordinate reference system (inputCrs) to a corresponding output CRS generated ...
void prepareSource(const QVariantMap &parameters, QgsProcessingContext &context)
Read the source from parameters and context and set it.
QVariantMap processAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) override
Runs the algorithm using the specified parameters.
virtual QgsFields outputFields(const QgsFields &inputFields) const
Maps the input source fields (inputFields) to corresponding output fields generated by the algorithm.
virtual QString outputName() const =0
Returns the translated, user visible name for any layers created by this algorithm.
virtual QString inputParameterDescription() const
Returns the translated description of the parameter corresponding to the input layer.
virtual QgsFeatureSink::SinkFlags sinkFlags() const
Returns the feature sink flags to be used for the output.
void initAlgorithm(const QVariantMap &configuration=QVariantMap()) override
Initializes the algorithm using the specified configuration.
virtual QList< int > inputLayerTypes() const
Returns the valid input layer types for the source layer for this algorithm.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source's coordinate reference system.
virtual Qgis::ProcessingFeatureSourceFlags sourceFlags() const
Returns the processing feature source flags to be used in the algorithm.
Encapsulates settings relating to a feature source input to a processing algorithm.
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource,...
QgsExpressionContextScope * createExpressionContextScope() const
Returns an expression context scope suitable for this source.
Base class for providing feedback from a processing algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
Base class for the definition of processing outputs.
bool autoCreated() const
Returns true if the output was automatically created when adding a parameter.
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
QgsProperty sink
Sink/layer definition.
Base class for the definition of processing parameters.
virtual bool isDestination() const
Returns true if this parameter represents a file or layer destination, e.g.
QString name() const
Returns the name of the parameter.
static QString typeName()
Returns the type name for the parameter class.
A feature sink output for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
An input feature source (such as vector layers) parameter for processing algorithms.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static QString typeName()
Returns the type name for the parameter class.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
static QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
static QgsFeatureSink * parameterAsSink(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields, Qgis::WkbType geometryType, const QgsCoordinateReferenceSystem &crs, QgsProcessingContext &context, QString &destinationIdentifier, QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList())
Evaluates the parameter with matching definition to a feature sink.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a list of map layers.
static QgsRectangle parameterAsExtent(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent.
static QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter value.
static QgsAnnotationLayer * parameterAsAnnotationLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to an annotation layer.
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
static QStringList parameterAsStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of strings (e.g.
static QList< int > parameterAsInts(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of integer values.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
static QString parameterAsFileOutput(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file based output destination.
static QgsPointCloudLayer * parameterAsPointCloudLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a point cloud layer.
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
static QgsLayoutItem * parameterAsLayoutItem(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsPrintLayout *layout)
Evaluates the parameter with matching definition to a print layout item, taken from the specified lay...
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
static QString parameterAsCompatibleSourceLayerPathAndLayerName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path and layer name of...
static QgsMeshLayer * parameterAsMeshLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition and value to a mesh layer.
static QString parameterAsCompatibleSourceLayerPath(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr)
Evaluates the parameter with matching definition to a source vector layer file path of compatible for...
static QColor parameterAsColor(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the color associated with an point parameter value, or an invalid color if the parameter was ...
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
static QString parameterAsOutputFormat(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output format.
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
static QgsMapLayer * parameterAsLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint=QgsProcessingUtils::LayerHint::UnknownType, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags())
Evaluates the parameter with matching definition to a map layer.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
static QStringList parameterAsEnumStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of static enum strings.
static QgsGeometry parameterAsExtentGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a rectangular extent, and returns a geometry cove...
static QStringList parameterAsFileList(const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of files (for QgsProcessingParameterMultip...
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
static QString parameterAsFile(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file/folder name.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
Encapsulates settings relating to a raster layer input to a processing algorithm.
QFlags< LayerOptionsFlag > LayerOptionsFlags
A store for object properties.
Qgis::PropertyType propertyType() const
Returns the property type.
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
QVariant staticValue() const
Returns the current static value for the property.
static QString driverForExtension(const QString &extension)
Returns the GDAL driver name for a specified file extension.
Represents a raster layer.
A rectangle specified with double values.
Represents a vector layer which manages a vector based dataset.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QList< QgsFeature > QgsFeatureList
QList< const QgsProcessingParameterDefinition * > QgsProcessingParameterDefinitions
List of processing parameters.
Properties of a vector source or sink used in an algorithm.
Qgis::WkbType wkbType
Geometry (WKB) type.
QgsCoordinateReferenceSystem crs
Coordinate Reference System.
Qgis::ProcessingPropertyAvailability availability
Availability of the properties. By default properties are not available.