QGIS API Documentation 4.3.0-Master (d57cc4a041c)
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
23#include "qgsapplication.h"
24#include "qgsexception.h"
26#include "qgsmeshlayer.h"
27#include "qgsmessagelog.h"
28#include "qgspointcloudlayer.h"
34#include "qgsprocessingutils.h"
35#include "qgsrasterfilewriter.h"
36#include "qgsrectangle.h"
37#include "qgsvectorlayer.h"
38
39#include <QRegularExpression>
40#include <QRegularExpressionMatch>
41#include <QString>
42
43using namespace Qt::StringLiterals;
44
46{
47 qDeleteAll( mParameters );
48 qDeleteAll( mOutputs );
49}
50
51QgsProcessingAlgorithm *QgsProcessingAlgorithm::create( const QVariantMap &configuration ) const
52{
53 std::unique_ptr< QgsProcessingAlgorithm > creation( createInstance() );
54 if ( !creation )
55 throw QgsProcessingException( QObject::tr( "Error creating algorithm from createInstance()" ) );
56 creation->setProvider( provider() );
57 creation->initAlgorithm( configuration );
58 return creation.release();
59}
60
62{
63 if ( mProvider )
64 return u"%1:%2"_s.arg( mProvider->id(), name() );
65 else
66 return name();
67}
68
70{
71 return QString();
72}
73
75{
76 return QString();
77}
78
80{
81 return QString();
82}
83
85{
86 return QString();
87}
88
93
94QList<QgsAcademicReference> QgsProcessingAlgorithm::academicReferences() const
95{
96 return {};
97}
98
100{
101 return QgsApplication::getThemeIcon( "/processingAlgorithm.svg" );
102}
103
105{
106 return QgsApplication::iconPath( u"processingAlgorithm.svg"_s );
107}
108
113
115{
116 return true;
117}
118
119bool QgsProcessingAlgorithm::checkParameterValues( const QVariantMap &parameters, QgsProcessingContext &context, QString *message ) const
120{
121 for ( const QgsProcessingParameterDefinition *def : mParameters )
122 {
123 if ( !def->checkValueIsAcceptable( parameters.value( def->name() ), &context ) )
124 {
125 if ( message )
126 {
127 // TODO QGIS 5 - move the message handling to the parameter subclasses (but this
128 // requires a change in signature for the virtual checkValueIsAcceptable method)
130 *message = invalidSourceError( parameters, def->name() );
131 else if ( def->type() == QgsProcessingParameterFeatureSink::typeName() )
132 *message = invalidSinkError( parameters, def->name() );
133 else if ( def->type() == QgsProcessingParameterRasterLayer::typeName() )
134 *message = invalidRasterError( parameters, def->name() );
135 else if ( def->type() == QgsProcessingParameterPointCloudLayer::typeName() )
136 *message = invalidPointCloudError( parameters, def->name() );
137 else
138 *message = QObject::tr( "Incorrect parameter value for %1" ).arg( def->name() );
139 }
140 return false;
141 }
142 }
143 return true;
144}
145
146QVariantMap QgsProcessingAlgorithm::preprocessParameters( const QVariantMap &parameters )
147{
148 return parameters;
149}
150
151QVariantMap QgsProcessingAlgorithm::autogenerateParameterValues( const QVariantMap &, const QString &, Qgis::ProcessingMode ) const
152{
153 return {};
154}
155
157{
158 return mProvider;
159}
160
162{
163 mProvider = provider;
164
165 if ( mProvider && !mProvider->supportsNonFileBasedOutput() )
166 {
167 // need to update all destination parameters to turn off non file based outputs
168 for ( const QgsProcessingParameterDefinition *definition : std::as_const( mParameters ) )
169 {
170 if ( definition->isDestination() )
171 {
172 const QgsProcessingDestinationParameter *destParam = static_cast< const QgsProcessingDestinationParameter *>( definition );
173 const_cast< QgsProcessingDestinationParameter *>( destParam )->setSupportsNonFileBasedOutput( false );
174 }
175 }
176 }
177}
178
180{
181 return nullptr;
182}
183
185{
186 // start with context's expression context
188
189 // If there's a source capable of generating a context scope, use it
190 if ( source )
191 {
193 if ( scope )
194 c << scope;
195 }
196 else if ( c.scopeCount() == 0 )
197 {
198 //empty scope, populate with initial scopes
200 }
201
202 c << QgsExpressionContextUtils::processingAlgorithmScope( this, parameters, context );
203 return c;
204}
205
206bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, QgsProcessingContext &context ) const
207{
209 {
210 // I'm a well behaved algorithm - I take work AWAY from users!
211 return true;
212 }
213
214 bool foundCrs = false;
216 for ( const QgsProcessingParameterDefinition *def : mParameters )
217 {
219 {
220 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( def, parameters, context );
221 if ( layer )
222 {
223 if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
224 {
225 return false;
226 }
227 else if ( !foundCrs && layer->crs().isValid() )
228 {
229 foundCrs = true;
230 crs = layer->crs();
231 }
232 }
233 }
234 else if ( def->type() == QgsProcessingParameterFeatureSource::typeName() )
235 {
236 std::unique_ptr< QgsFeatureSource > source( QgsProcessingParameters::parameterAsSource( def, parameters, context ) );
237 if ( source )
238 {
239 if ( foundCrs && source->sourceCrs().isValid() && crs != source->sourceCrs() )
240 {
241 return false;
242 }
243 else if ( !foundCrs && source->sourceCrs().isValid() )
244 {
245 foundCrs = true;
246 crs = source->sourceCrs();
247 }
248 }
249 }
250 else if ( def->type() == QgsProcessingParameterMultipleLayers::typeName() )
251 {
252 QList< QgsMapLayer *> layers = QgsProcessingParameters::parameterAsLayerList( def, parameters, context );
253 const auto constLayers = layers;
254 for ( QgsMapLayer *layer : constLayers )
255 {
256 if ( !layer )
257 continue;
258
259 if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
260 {
261 return false;
262 }
263 else if ( !foundCrs && layer->crs().isValid() )
264 {
265 foundCrs = true;
266 crs = layer->crs();
267 }
268 }
269 }
270 else if ( def->type() == QgsProcessingParameterExtent::typeName() )
271 {
273 if ( foundCrs && extentCrs.isValid() && crs != extentCrs )
274 {
275 return false;
276 }
277 else if ( !foundCrs && extentCrs.isValid() )
278 {
279 foundCrs = true;
280 crs = extentCrs;
281 }
282 }
283 else if ( def->type() == QgsProcessingParameterPoint::typeName() )
284 {
286 if ( foundCrs && pointCrs.isValid() && crs != pointCrs )
287 {
288 return false;
289 }
290 else if ( !foundCrs && pointCrs.isValid() )
291 {
292 foundCrs = true;
293 crs = pointCrs;
294 }
295 }
296 else if ( def->type() == QgsProcessingParameterGeometry::typeName() )
297 {
299 if ( foundCrs && geomCrs.isValid() && crs != geomCrs )
300 {
301 return false;
302 }
303 else if ( !foundCrs && geomCrs.isValid() )
304 {
305 foundCrs = true;
306 crs = geomCrs;
307 }
308 }
309 }
310 return true;
311}
312
313QString QgsProcessingAlgorithm::asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const
314{
315 QString s = u"processing.run(\"%1\","_s.arg( id() );
316
317 QStringList parts;
318 for ( const QgsProcessingParameterDefinition *def : mParameters )
319 {
320 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
321 continue;
322
323 if ( !parameters.contains( def->name() ) )
324 continue;
325
326 parts << u"'%1':%2"_s.arg( def->name(), def->valueAsPythonString( parameters.value( def->name() ), context ) );
327 }
328
329 s += u" {%1})"_s.arg( parts.join( ',' ) );
330 return s;
331}
332
333QString QgsProcessingAlgorithm::asQgisProcessCommand( const QVariantMap &parameters, QgsProcessingContext &context, bool &ok ) const
334{
335 ok = true;
336 QStringList parts;
337 parts.append( u"qgis_process"_s );
338 parts.append( u"run"_s );
339 parts.append( id() );
340
342 // we only include the project path argument if a project is actually required by the algorithm
345
346 parts.append( context.asQgisProcessArguments( argumentFlags ) );
347
348 auto escapeIfNeeded = []( const QString &input ) -> QString {
349 // play it safe and escape everything UNLESS it's purely alphanumeric characters (and a very select scattering of other common characters!)
350 const thread_local QRegularExpression nonAlphaNumericRx( u"[^a-zA-Z0-9.\\-/_]"_s );
351 if ( nonAlphaNumericRx.match( input ).hasMatch() )
352 {
353 QString escaped = input;
354 escaped.replace( '\'', "'\\''"_L1 );
355 return u"'%1'"_s.arg( escaped );
356 }
357 else
358 {
359 return input;
360 }
361 };
362
363 for ( const QgsProcessingParameterDefinition *def : mParameters )
364 {
365 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
366 continue;
367
368 if ( !parameters.contains( def->name() ) )
369 continue;
370
371 const QStringList partValues = def->valueAsStringList( parameters.value( def->name() ), context, ok );
372 if ( !ok )
373 return QString();
374
375 for ( const QString &partValue : partValues )
376 {
377 parts << u"--%1=%2"_s.arg( def->name(), escapeIfNeeded( partValue ) );
378 }
379 }
380
381 return parts.join( ' ' );
382}
383
384QVariantMap QgsProcessingAlgorithm::asMap( const QVariantMap &parameters, QgsProcessingContext &context ) const
385{
386 QVariantMap properties = context.exportToMap();
387
388 // we only include the project path argument if a project is actually required by the algorithm
390 properties.remove( u"project_path"_s );
391
392 QVariantMap paramValues;
393 for ( const QgsProcessingParameterDefinition *def : mParameters )
394 {
395 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
396 continue;
397
398 if ( !parameters.contains( def->name() ) )
399 continue;
400
401 paramValues.insert( def->name(), def->valueAsJsonObject( parameters.value( def->name() ), context ) );
402 }
403
404 properties.insert( u"inputs"_s, paramValues );
405 return properties;
406}
407
409{
410 return addParameter( std::unique_ptr<QgsProcessingParameterDefinition>( definition ), createOutput );
411}
412
413bool QgsProcessingAlgorithm::addParameter( std::unique_ptr<QgsProcessingParameterDefinition> definition, bool createOutput )
414{
415 if ( !definition )
416 return false;
417
418 // check for duplicate named parameters
419 const QgsProcessingParameterDefinition *existingDef = QgsProcessingAlgorithm::parameterDefinition( definition->name() );
420 if ( existingDef && existingDef->name() == definition->name() ) // parameterDefinition is case-insensitive, but we DO allow case-different duplicate names
421 {
422 QgsMessageLog::logMessage( QObject::tr( "Duplicate parameter %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
423 return false;
424 }
425
426 if ( definition->isDestination() && mProvider )
427 {
428 QgsProcessingDestinationParameter *destParam = static_cast< QgsProcessingDestinationParameter *>( definition.get() );
429 if ( !mProvider->supportsNonFileBasedOutput() )
430 destParam->setSupportsNonFileBasedOutput( false );
431 }
432
433 definition->mAlgorithm = this;
434 mParameters << definition.release();
435 const QgsProcessingParameterDefinition *definitionRawPtr = mParameters.back();
436
437 if ( createOutput )
438 return createAutoOutputForParameter( definitionRawPtr );
439 else
440 return true;
441}
442
444{
446 if ( def )
447 {
448 delete def;
449 mParameters.removeAll( def );
450
451 // remove output automatically created when adding parameter
453 if ( outputDef && outputDef->autoCreated() )
454 {
455 delete outputDef;
456 mOutputs.removeAll( outputDef );
457 }
458 }
459}
460
462{
463 return addOutput( std::unique_ptr<QgsProcessingOutputDefinition>( definition ) );
464}
465
466bool QgsProcessingAlgorithm::addOutput( std::unique_ptr<QgsProcessingOutputDefinition> definition )
467{
468 if ( !definition )
469 return false;
470
471 // check for duplicate named outputs
472 if ( QgsProcessingAlgorithm::outputDefinition( definition->name() ) )
473 {
474 QgsMessageLog::logMessage( QObject::tr( "Duplicate output %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
475 return false;
476 }
477
478 mOutputs << definition.release();
479 return true;
480}
481
483{
484 return true;
485}
486
491
493{
494 // first pass - case sensitive match
495 for ( const QgsProcessingParameterDefinition *def : mParameters )
496 {
497 if ( def->name() == name )
498 return def;
499 }
500
501 // second pass - case insensitive
502 for ( const QgsProcessingParameterDefinition *def : mParameters )
503 {
504 if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
505 return def;
506 }
507 return nullptr;
508}
509
511{
512 int count = 0;
513 for ( const QgsProcessingParameterDefinition *def : mParameters )
514 {
515 if ( !( def->flags() & Qgis::ProcessingParameterFlag::Hidden ) )
516 count++;
517 }
518 return count;
519}
520
522{
524 for ( const QgsProcessingParameterDefinition *def : mParameters )
525 {
526 if ( def->isDestination() )
527 result << def;
528 }
529 return result;
530}
531
533{
534 for ( const QgsProcessingOutputDefinition *def : mOutputs )
535 {
536 if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
537 return def;
538 }
539 return nullptr;
540}
541
543{
544 for ( const QgsProcessingOutputDefinition *def : mOutputs )
545 {
546 if ( def->type() == "outputHtml"_L1 )
547 return true;
548 }
549 return false;
550}
551
553 const QString &, const QVariantMap &, QgsProcessingContext &, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> &
554) const
555{
556 return VectorProperties();
557}
558
559QVariantMap QgsProcessingAlgorithm::run( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok, const QVariantMap &configuration, bool catchExceptions ) const
560{
561 std::unique_ptr< QgsProcessingAlgorithm > alg( create( configuration ) );
562 if ( ok )
563 *ok = false;
564
565 bool res = alg->prepare( parameters, context, feedback );
566 if ( !res )
567 return QVariantMap();
568
569 QVariantMap runRes;
570 bool success = false;
571 try
572 {
573 runRes = alg->runPrepared( parameters, context, feedback );
574 success = true;
575 }
576 catch ( QgsProcessingException &e )
577 {
578 if ( !catchExceptions )
579 {
580 alg->postProcess( context, feedback, false );
581 throw e;
582 }
583
584 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
585 feedback->reportError( e.what() );
586 }
587
588 if ( ok )
589 *ok = success;
590
591 QVariantMap ppRes = alg->postProcess( context, feedback, success );
592 if ( !ppRes.isEmpty() )
593 return ppRes;
594 else
595 return runRes;
596}
597
598bool QgsProcessingAlgorithm::prepare( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
599{
600 // cppcheck-suppress assertWithSideEffect
601 Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::prepare", "prepare() must be called from the same thread as context was created in" );
602 Q_ASSERT_X( !mHasPrepared, "QgsProcessingAlgorithm::prepare", "prepare() has already been called for the algorithm instance" );
603 try
604 {
605 mHasPrepared = prepareAlgorithm( parameters, context, feedback );
606 return mHasPrepared;
607 }
608 catch ( QgsProcessingException &e )
609 {
610 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
611 feedback->reportError( e.what() );
612 return false;
613 }
614}
615
616QVariantMap QgsProcessingAlgorithm::runPrepared( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
617{
618 Q_ASSERT_X( mHasPrepared, "QgsProcessingAlgorithm::runPrepared", u"prepare() was not called for the algorithm instance %1"_s.arg( name() ).toLatin1() );
619 Q_ASSERT_X( !mHasExecuted, "QgsProcessingAlgorithm::runPrepared", "runPrepared() was already called for this algorithm instance" );
620
621 // Hey kids, let's all be thread safe! It's the fun thing to do!
622 //
623 // First, let's see if we're going to run into issues.
624 QgsProcessingContext *runContext = nullptr;
625 if ( context.thread() == QThread::currentThread() )
626 {
627 // OH. No issues. Seems you're running everything in the same thread, so go about your business. Sorry about
628 // the intrusion, we're just making sure everything's nice and safe here. We like to keep a clean and tidy neighbourhood,
629 // you know, for the kids and dogs and all.
630 runContext = &context;
631 }
632 else
633 {
634 // HA! I knew things looked a bit suspicious - seems you're running this algorithm in a different thread
635 // from that which the passed context has an affinity for. That's fine and all, but we need to make sure
636 // we proceed safely...
637
638 // So first we create a temporary local context with affinity for the current thread
639 mLocalContext = std::make_unique<QgsProcessingContext>();
640 // copy across everything we can safely do from the passed context
641 mLocalContext->copyThreadSafeSettings( context );
642
643 // and we'll run the actual algorithm processing using the local thread safe context
644 runContext = mLocalContext.get();
645 }
646
647 std::unique_ptr< QgsProcessingModelInitialRunConfig > modelConfig = context.takeModelInitialRunConfig();
648 if ( modelConfig )
649 {
650 std::unique_ptr< QgsMapLayerStore > modelPreviousLayerStore = modelConfig->takePreviousLayerStore();
651 if ( modelPreviousLayerStore )
652 {
653 // move layers from previous layer store to context's temporary layer store, in a thread-safe way
654 Q_ASSERT_X( !modelPreviousLayerStore->thread(), "QgsProcessingAlgorithm::runPrepared", "QgsProcessingModelConfig::modelPreviousLayerStore must have been pushed to a nullptr thread" );
655 modelPreviousLayerStore->moveToThread( QThread::currentThread() );
656 runContext->temporaryLayerStore()->transferLayersFromStore( modelPreviousLayerStore.get() );
657 }
658 runContext->setModelInitialRunConfig( std::move( modelConfig ) );
659 }
660
661 mHasExecuted = true;
662 try
663 {
664 QVariantMap runResults = processAlgorithm( parameters, *runContext, feedback );
665
666 if ( mLocalContext )
667 {
668 // ok, time to clean things up. We need to push the temporary context back into
669 // the thread that the passed context is associated with (we can only push from the
670 // current thread, so we HAVE to do this here)
671 mLocalContext->pushToThread( context.thread() );
672 }
673 return runResults;
674 }
675 catch ( QgsProcessingException & )
676 {
677 if ( mLocalContext )
678 {
679 // see above!
680 mLocalContext->pushToThread( context.thread() );
681 }
682 //rethrow
683 throw;
684 }
685}
686
688{
689 // cppcheck-suppress assertWithSideEffect
690 Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::postProcess", "postProcess() must be called from the same thread the context was created in" );
691 Q_ASSERT_X( mHasExecuted, "QgsProcessingAlgorithm::postProcess", u"algorithm instance %1 was not executed"_s.arg( name() ).toLatin1() );
692 Q_ASSERT_X( !mHasPostProcessed, "QgsProcessingAlgorithm::postProcess", "postProcess() was already called for this algorithm instance" );
693
694 if ( mLocalContext )
695 {
696 // algorithm was processed using a temporary thread safe context. So now we need
697 // to take the results from that temporary context, and smash them into the passed
698 // context
699 context.takeResultsFrom( *mLocalContext );
700 // now get lost, we don't need you anymore
701 mLocalContext.reset();
702 }
703
704 mHasPostProcessed = true;
705 if ( runResult )
706 {
707 try
708 {
709 return postProcessAlgorithm( context, feedback );
710 }
711 catch ( QgsProcessingException &e )
712 {
713 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
714 feedback->reportError( e.what() );
715 return QVariantMap();
716 }
717 }
718 else
719 {
720 return QVariantMap();
721 }
722}
723
724QString QgsProcessingAlgorithm::parameterAsString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
725{
727}
728
729QString QgsProcessingAlgorithm::parameterAsExpression( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
730{
732}
733
734double QgsProcessingAlgorithm::parameterAsDouble( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
735{
737}
738
739int QgsProcessingAlgorithm::parameterAsInt( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
740{
741 return QgsProcessingParameters::parameterAsInt( parameterDefinition( name ), parameters, context );
742}
743
744QList<int> QgsProcessingAlgorithm::parameterAsInts( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
745{
746 return QgsProcessingParameters::parameterAsInts( parameterDefinition( name ), parameters, context );
747}
748
749int QgsProcessingAlgorithm::parameterAsEnum( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
750{
751 return QgsProcessingParameters::parameterAsEnum( parameterDefinition( name ), parameters, context );
752}
753
754QList<int> QgsProcessingAlgorithm::parameterAsEnums( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
755{
757}
758
759QString QgsProcessingAlgorithm::parameterAsEnumString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
760{
762}
763
764QStringList QgsProcessingAlgorithm::parameterAsEnumStrings( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
765{
767}
768
769bool QgsProcessingAlgorithm::parameterAsBool( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
770{
771 return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
772}
773
774bool QgsProcessingAlgorithm::parameterAsBoolean( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
775{
776 return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
777}
778
780 const QVariantMap &parameters,
781 const QString &name,
782 QgsProcessingContext &context,
783 QString &destinationIdentifier,
784 const QgsFields &fields,
785 Qgis::WkbType geometryType,
788 const QVariantMap &createOptions,
789 const QStringList &datasourceOptions,
790 const QStringList &layerOptions
791) const
792{
793 if ( !parameterDefinition( name ) )
794 throw QgsProcessingException( QObject::tr( "No parameter definition for the sink '%1'" ).arg( name ) );
795
796 return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
797}
798
799QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
800{
802}
803
805 const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback
806) const
807{
808 return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback );
809}
810
812 const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName
813) const
814{
815 return QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback, layerName );
816}
817
818QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
819{
821}
822
823QgsRasterLayer *QgsProcessingAlgorithm::parameterAsRasterLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
824{
826}
827
828QgsMeshLayer *QgsProcessingAlgorithm::parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
829{
831}
832
833QString QgsProcessingAlgorithm::parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
834{
836}
837
838QString QgsProcessingAlgorithm::parameterAsOutputFormat( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
839{
841}
842
843QString QgsProcessingAlgorithm::parameterAsOutputRasterFormat( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
844{
845 QString outputFormat = parameterAsOutputFormat( parameters, name, context );
846 if ( outputFormat.isEmpty() )
847 {
849 QVariant val;
850 if ( definition )
851 {
852 val = parameters.value( definition->name() );
853 }
854 QString outputFile = QgsProcessingParameters::parameterAsOutputLayer( definition, val, context, /* testOnly = */ true );
855 if ( !outputFile.isEmpty() )
856 {
857 const QFileInfo fi( outputFile );
858 outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() );
859 }
860 }
861 return outputFormat;
862}
863
864QString QgsProcessingAlgorithm::parameterAsFileOutput( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
865{
867}
868
869QgsVectorLayer *QgsProcessingAlgorithm::parameterAsVectorLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
870{
872}
873
874QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
875{
876 return QgsProcessingParameters::parameterAsCrs( parameterDefinition( name ), parameters, context );
877}
878
879QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsExtentCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
880{
882}
883
884QgsRectangle QgsProcessingAlgorithm::parameterAsExtent( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
885{
886 return QgsProcessingParameters::parameterAsExtent( parameterDefinition( name ), parameters, context, crs );
887}
888
889QgsGeometry QgsProcessingAlgorithm::parameterAsExtentGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
890{
892}
893
894QgsPointXY QgsProcessingAlgorithm::parameterAsPoint( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
895{
896 return QgsProcessingParameters::parameterAsPoint( parameterDefinition( name ), parameters, context, crs );
897}
898
899QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsPointCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
900{
902}
903
904QgsGeometry QgsProcessingAlgorithm::parameterAsGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
905{
906 return QgsProcessingParameters::parameterAsGeometry( parameterDefinition( name ), parameters, context, crs );
907}
908
909QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsGeometryCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
910{
912}
913
914QString QgsProcessingAlgorithm::parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
915{
916 return QgsProcessingParameters::parameterAsFile( parameterDefinition( name ), parameters, context );
917}
918
919QVariantList QgsProcessingAlgorithm::parameterAsMatrix( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
920{
922}
923
924QList<QgsMapLayer *> QgsProcessingAlgorithm::parameterAsLayerList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags ) const
925{
927}
928
929QStringList QgsProcessingAlgorithm::parameterAsFileList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
930{
932}
933
934QList<double> QgsProcessingAlgorithm::parameterAsRange( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
935{
937}
938
939QStringList QgsProcessingAlgorithm::parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
940{
942}
943
944QStringList QgsProcessingAlgorithm::parameterAsStrings( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
945{
947}
948
949QgsPrintLayout *QgsProcessingAlgorithm::parameterAsLayout( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
950{
952}
953
954QgsLayoutItem *QgsProcessingAlgorithm::parameterAsLayoutItem( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsPrintLayout *layout )
955{
956 return QgsProcessingParameters::parameterAsLayoutItem( parameterDefinition( name ), parameters, context, layout );
957}
958
959QColor QgsProcessingAlgorithm::parameterAsColor( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
960{
962}
963
964QString QgsProcessingAlgorithm::parameterAsConnectionName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
965{
967}
968
969QDateTime QgsProcessingAlgorithm::parameterAsDateTime( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
970{
972}
973
974QString QgsProcessingAlgorithm::parameterAsSchema( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
975{
977}
978
979QString QgsProcessingAlgorithm::parameterAsDatabaseTableName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
980{
982}
983
988
989QgsAnnotationLayer *QgsProcessingAlgorithm::parameterAsAnnotationLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
990{
992}
993
994QString QgsProcessingAlgorithm::invalidSourceError( const QVariantMap &parameters, const QString &name )
995{
996 if ( !parameters.contains( name ) )
997 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
998 else
999 {
1000 QVariant var = parameters.value( name );
1001 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1002 {
1003 QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
1004 var = fromVar.source;
1005 }
1006 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1007 {
1008 QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1009 var = fromVar.sink;
1010 }
1011 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1012 {
1013 QgsProperty p = var.value< QgsProperty >();
1015 {
1016 var = p.staticValue();
1017 }
1018 }
1019 if ( !var.toString().isEmpty() )
1020 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
1021 else
1022 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
1023 }
1024}
1025
1026QString QgsProcessingAlgorithm::invalidRasterError( const QVariantMap &parameters, const QString &name )
1027{
1028 if ( !parameters.contains( name ) )
1029 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
1030 else
1031 {
1032 QVariant var = parameters.value( name );
1033 if ( var.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
1034 {
1035 QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( var );
1036 var = fromVar.source;
1037 }
1038 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1039 {
1040 QgsProperty p = var.value< QgsProperty >();
1042 {
1043 var = p.staticValue();
1044 }
1045 }
1046 if ( !var.toString().isEmpty() )
1047 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
1048 else
1049 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
1050 }
1051}
1052
1053QString QgsProcessingAlgorithm::invalidSinkError( const QVariantMap &parameters, const QString &name )
1054{
1055 if ( !parameters.contains( name ) )
1056 return QObject::tr( "Could not create destination layer for %1: no value specified for parameter" ).arg( name );
1057 else
1058 {
1059 QVariant var = parameters.value( name );
1060 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1061 {
1062 QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1063 var = fromVar.sink;
1064 }
1065 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1066 {
1067 QgsProperty p = var.value< QgsProperty >();
1069 {
1070 var = p.staticValue();
1071 }
1072 }
1073 if ( !var.toString().isEmpty() )
1074 return QObject::tr( "Could not create destination layer for %1: %2" ).arg( name, var.toString() );
1075 else
1076 return QObject::tr( "Could not create destination layer for %1: invalid value" ).arg( name );
1077 }
1078}
1079
1080QString QgsProcessingAlgorithm::invalidPointCloudError( const QVariantMap &parameters, const QString &name )
1081{
1082 if ( !parameters.contains( name ) )
1083 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
1084 else
1085 {
1086 QVariant var = parameters.value( name );
1087 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1088 {
1089 QgsProperty p = var.value< QgsProperty >();
1091 {
1092 var = p.staticValue();
1093 }
1094 }
1095 if ( !var.toString().isEmpty() )
1096 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
1097 else
1098 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
1099 }
1100}
1101
1102QString QgsProcessingAlgorithm::writeFeatureError( QgsFeatureSink *sink, const QVariantMap &parameters, const QString &name )
1103{
1104 Q_UNUSED( sink );
1105 Q_UNUSED( parameters );
1106 const QString lastError = sink->lastError();
1107 if ( !lastError.isEmpty() )
1108 {
1109 if ( !name.isEmpty() )
1110 return QObject::tr( "Could not write feature into %1: %2" ).arg( name, lastError );
1111 else
1112 return QObject::tr( "Could not write feature: %1" ).arg( lastError );
1113 }
1114 else
1115 {
1116 if ( !name.isEmpty() )
1117 return QObject::tr( "Could not write feature into %1" ).arg( name );
1118 else
1119 return QObject::tr( "Could not write feature" );
1120 }
1121}
1122
1124{
1125 Q_UNUSED( layer )
1126 return false;
1127}
1128
1129
1130bool QgsProcessingAlgorithm::createAutoOutputForParameter( const QgsProcessingParameterDefinition *parameter )
1131{
1132 if ( !parameter->isDestination() )
1133 return true; // nothing created, but nothing went wrong - so return true
1134
1135 const QgsProcessingDestinationParameter *dest = static_cast< const QgsProcessingDestinationParameter * >( parameter );
1137 if ( !output )
1138 return true; // nothing created - but nothing went wrong - so return true
1139 output->setAutoCreated( true );
1140
1141 if ( !addOutput( output ) )
1142 {
1143 // couldn't add output - probably a duplicate name
1144 return false;
1145 }
1146 else
1147 {
1148 return true;
1149 }
1150}
1151
1152
1153//
1154// QgsProcessingFeatureBasedAlgorithm
1155//
1156
1163
1165{
1167 initParameters( config );
1168 addParameter( new QgsProcessingParameterFeatureSink( u"OUTPUT"_s, outputName(), outputLayerType(), QVariant(), false, true, true ) );
1169}
1170
1172{
1173 return u"INPUT"_s;
1174}
1175
1177{
1178 return QObject::tr( "Input layer" );
1179}
1180
1182{
1183 return QList<int>();
1184}
1185
1190
1195
1200
1202{
1203 return inputWkbType;
1204}
1205
1207{
1208 return inputFields;
1209}
1210
1215
1218
1220{
1221 if ( mSource )
1222 return mSource->sourceCrs();
1223 else
1225}
1226
1227QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
1228{
1229 prepareSource( parameters, context );
1230 QString dest;
1231 std::unique_ptr< QgsFeatureSink > sink(
1232 parameterAsSink( parameters, u"OUTPUT"_s, context, dest, outputFields( mSource->fields() ), outputWkbType( mSource->wkbType() ), outputCrs( mSource->sourceCrs() ), sinkFlags() )
1233 );
1234 if ( !sink )
1235 throw QgsProcessingException( invalidSinkError( parameters, u"OUTPUT"_s ) );
1236
1237 // prepare expression context for feature iteration
1238 QgsExpressionContext prevContext = context.expressionContext();
1239 QgsExpressionContext algContext = prevContext;
1240
1241 algContext.appendScopes( createExpressionContext( parameters, context, mSource.get() ).takeScopes() );
1242 context.setExpressionContext( algContext );
1243
1244 long count = mSource->featureCount();
1245
1246 QgsFeature f;
1247 QgsFeatureIterator it = mSource->getFeatures( request(), sourceFlags() );
1248
1249 double step = count > 0 ? 100.0 / count : 1;
1250 int current = 0;
1251 while ( it.nextFeature( f ) )
1252 {
1253 if ( feedback->isCanceled() )
1254 {
1255 break;
1256 }
1257
1258 context.expressionContext().setFeature( f );
1259 const QgsFeatureList transformed = processFeature( f, context, feedback );
1260 for ( QgsFeature transformedFeature : transformed )
1261 {
1262 if ( !sink->addFeature( transformedFeature, QgsFeatureSink::FastInsert ) )
1263 {
1264 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QString() ) );
1265 }
1266 else
1267 {
1268 feedback->featureAddedToSink( u"OUTPUT"_s );
1269 }
1270 }
1271
1272 feedback->setProgress( current * step );
1273 current++;
1274 }
1275
1276 sink->finalize();
1277 feedback->featureSinkFinalized( u"OUTPUT"_s );
1278
1279 mSource.reset();
1280
1281 // probably not necessary - context's aren't usually recycled, but can't hurt
1282 context.setExpressionContext( prevContext );
1283
1284 QVariantMap outputs;
1285 outputs.insert( u"OUTPUT"_s, dest );
1286 return outputs;
1287}
1288
1293
1295{
1296 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
1297 if ( !layer )
1298 return false;
1299
1300 Qgis::GeometryType inPlaceGeometryType = layer->geometryType();
1301 if ( !inputLayerTypes().empty() &&
1302 !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::Vector ) ) &&
1303 !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry ) ) &&
1304 ( ( inPlaceGeometryType == Qgis::GeometryType::Polygon && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon ) ) ) ||
1305 ( inPlaceGeometryType == Qgis::GeometryType::Line && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorLine ) ) ) ||
1306 ( inPlaceGeometryType == Qgis::GeometryType::Point && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorPoint ) ) ) ) )
1307 return false;
1308
1310 if ( inPlaceGeometryType == Qgis::GeometryType::Point )
1311 type = Qgis::WkbType::Point;
1312 else if ( inPlaceGeometryType == Qgis::GeometryType::Line )
1314 else if ( inPlaceGeometryType == Qgis::GeometryType::Polygon )
1316
1317 if ( QgsWkbTypes::geometryType( outputWkbType( type ) ) != inPlaceGeometryType )
1318 return false;
1319
1320 return true;
1321}
1322
1324{
1325 if ( !mSource )
1326 {
1327 mSource.reset( parameterAsSource( parameters, inputParameterName(), context ) );
1328 if ( !mSource )
1330 }
1331}
1332
1333
1335 const QString &sink, const QVariantMap &parameters, QgsProcessingContext &context, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> &sourceProperties
1336) const
1337{
1339 if ( sink == "OUTPUT"_L1 )
1340 {
1341 if ( sourceProperties.value( u"INPUT"_s ).availability == Qgis::ProcessingPropertyAvailability::Available )
1342 {
1343 const VectorProperties inputProps = sourceProperties.value( u"INPUT"_s );
1344 result.fields = outputFields( inputProps.fields );
1345 result.crs = outputCrs( inputProps.crs );
1346 result.wkbType = outputWkbType( inputProps.wkbType );
1348 return result;
1349 }
1350 else
1351 {
1352 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, u"INPUT"_s, context ) );
1353 if ( source )
1354 {
1355 result.fields = outputFields( source->fields() );
1356 result.crs = outputCrs( source->sourceCrs() );
1357 result.wkbType = outputWkbType( source->wkbType() );
1359 return result;
1360 }
1361 }
1362 }
1363 return result;
1364}
ProcessingSourceType
Processing data source types.
Definition qgis.h:3747
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition qgis.h:3755
@ VectorAnyGeometry
Any vector layer with geometry.
Definition qgis.h:3749
@ VectorPoint
Vector point layers.
Definition qgis.h:3750
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3752
@ VectorLine
Vector line layers.
Definition qgis.h:3751
ProcessingMode
Types of modes which Processing widgets can be created for.
Definition qgis.h:3888
@ Critical
Critical/error message.
Definition qgis.h:163
@ Static
Static property.
Definition qgis.h:725
@ Available
Properties are available.
Definition qgis.h:3861
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:379
@ Point
Points.
Definition qgis.h:380
@ Line
Lines.
Definition qgis.h:381
@ Polygon
Polygons.
Definition qgis.h:382
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3826
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
Definition qgis.h:3847
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:294
@ Point
Point.
Definition qgis.h:296
@ LineString
LineString.
Definition qgis.h:297
@ Polygon
Polygon.
Definition qgis.h:298
@ Unknown
Unknown.
Definition qgis.h:295
@ SupportsBatch
Algorithm supports batch mode.
Definition qgis.h:3802
@ SupportsInPlaceEdits
Algorithm supports in-place editing.
Definition qgis.h:3807
@ RequiresMatchingCrs
Algorithm requires that all input layers have matching coordinate reference systems.
Definition qgis.h:3804
@ CanCancel
Algorithm can be canceled.
Definition qgis.h:3803
@ RequiresProject
The algorithm requires that a valid QgsProject is available from the processing context in order to e...
Definition qgis.h:3813
@ Hidden
Parameter is hidden and should not be shown to users.
Definition qgis.h:3983
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Definition qgis.h:3941
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:60
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:56
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition qgsfeedback.h:65
Container of fields for a vector layer.
Definition qgsfields.h:45
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:83
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:90
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(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
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:62
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 QWidget * createCustomParametersWidget(QMainWindow *parent=nullptr) const
If an algorithm subclass implements a custom parameters widget, a copy of this widget should be const...
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 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...
virtual QList< QgsAcademicReference > academicReferences() const
Returns the list of academic references describing the logic and processes used by the algorithm.
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.
void featureAddedToSink(const QString &output)
Reports that a feature was added to the the sink associated with the specified algorithm output.
void featureSinkFinalized(const QString &output)
Reports that a feature sink has been finalized.
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.