QGIS API Documentation 4.3.0-Master (0de80482b60)
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
45#define EXCLUDE_CPPCHECK
46#ifdef EXCLUDE_CPPCHECK
47std::unordered_map<std::type_index, QString> &algorithmSourceRegistry()
48{
49 static std::unordered_map<std::type_index, QString> registry;
50 return registry;
51}
52#endif
53
55{
56 qDeleteAll( mParameters );
57 qDeleteAll( mOutputs );
58}
59
60QgsProcessingAlgorithm *QgsProcessingAlgorithm::create( const QVariantMap &configuration ) const
61{
62 std::unique_ptr< QgsProcessingAlgorithm > creation( createInstance() );
63 if ( !creation )
64 throw QgsProcessingException( QObject::tr( "Error creating algorithm from createInstance()" ) );
65 creation->setProvider( provider() );
66 creation->initAlgorithm( configuration );
67 return creation.release();
68}
69
71{
72 if ( mProvider )
73 return u"%1:%2"_s.arg( mProvider->id(), name() );
74 else
75 return name();
76}
77
79{
80 return QString();
81}
82
84{
85 return QString();
86}
87
89{
90 return QString();
91}
92
94{
95 return QString();
96}
97
102
103QList<QgsAcademicReference> QgsProcessingAlgorithm::academicReferences() const
104{
105 return {};
106}
107
108QList<QgsProcessingAlgorithm::ExternalLink> QgsProcessingAlgorithm::externalLinks() const
109{
110 return {};
111}
112
114{
115#ifdef EXCLUDE_CPPCHECK
116 const std::unordered_map<std::type_index, QString> &registry = algorithmSourceRegistry();
117 auto it = registry.find( std::type_index( typeid( *this ) ) );
118 if ( it == registry.end() )
119 return QString();
120
121 const QString baseSourceLocation = it->second;
122
123 // split file from line number
124 const qsizetype colonPos = baseSourceLocation.lastIndexOf( ':' );
125 if ( colonPos == -1 )
126 return QString();
127
128 const QString filePath = baseSourceLocation.left( colonPos ).replace( '\\', '/' );
129 const QString lineNumber = baseSourceLocation.mid( colonPos + 1 );
130
131 // determine the git branch name corresponding to THIS qgis build
132 QString branch;
133 if ( QStringLiteral( RELEASE_NAME ).compare( u"Master"_s, Qt::CaseInsensitive ) == 0 )
134 {
135 branch = u"master"_s;
136 }
137 else
138 {
139 const int major = _QGIS_VERSION_INT / 10000;
140 const int minor = ( _QGIS_VERSION_INT % 10000 ) / 100;
141 branch = u"release-%1_%2"_s.arg( major ).arg( minor );
142 }
143
144 // construct GitHub blob URL pointing to the source
145 // TODO: not be GitHub ;)
146 return u"https://github.com/qgis/QGIS/blob/%1/%2#L%3"_s.arg( branch, filePath, lineNumber );
147#endif
148}
149
151{
152 return QgsApplication::getThemeIcon( "/processingAlgorithm.svg" );
153}
154
156{
157 return QgsApplication::iconPath( u"processingAlgorithm.svg"_s );
158}
159
164
166{
167 return true;
168}
169
170bool QgsProcessingAlgorithm::checkParameterValues( const QVariantMap &parameters, QgsProcessingContext &context, QString *message ) const
171{
172 for ( const QgsProcessingParameterDefinition *def : mParameters )
173 {
174 if ( !def->checkValueIsAcceptable( parameters.value( def->name() ), &context ) )
175 {
176 if ( message )
177 {
178 // TODO QGIS 5 - move the message handling to the parameter subclasses (but this
179 // requires a change in signature for the virtual checkValueIsAcceptable method)
181 *message = invalidSourceError( parameters, def->name() );
182 else if ( def->type() == QgsProcessingParameterFeatureSink::typeName() )
183 *message = invalidSinkError( parameters, def->name() );
184 else if ( def->type() == QgsProcessingParameterRasterLayer::typeName() )
185 *message = invalidRasterError( parameters, def->name() );
186 else if ( def->type() == QgsProcessingParameterPointCloudLayer::typeName() )
187 *message = invalidPointCloudError( parameters, def->name() );
188 else
189 *message = QObject::tr( "Incorrect parameter value for %1" ).arg( def->name() );
190 }
191 return false;
192 }
193 }
194 return true;
195}
196
197QVariantMap QgsProcessingAlgorithm::preprocessParameters( const QVariantMap &parameters )
198{
199 return parameters;
200}
201
202QVariantMap QgsProcessingAlgorithm::autogenerateParameterValues( const QVariantMap &, const QString &, Qgis::ProcessingMode ) const
203{
204 return {};
205}
206
208{
209 return mProvider;
210}
211
213{
214 mProvider = provider;
215
216 if ( mProvider && !mProvider->supportsNonFileBasedOutput() )
217 {
218 // need to update all destination parameters to turn off non file based outputs
219 for ( const QgsProcessingParameterDefinition *definition : std::as_const( mParameters ) )
220 {
221 if ( definition->isDestination() )
222 {
223 const QgsProcessingDestinationParameter *destParam = static_cast< const QgsProcessingDestinationParameter *>( definition );
224 const_cast< QgsProcessingDestinationParameter *>( destParam )->setSupportsNonFileBasedOutput( false );
225 }
226 }
227 }
228}
229
231{
232 return nullptr;
233}
234
236{
237 // start with context's expression context
239
240 // If there's a source capable of generating a context scope, use it
241 if ( source )
242 {
244 if ( scope )
245 c << scope;
246 }
247 else if ( c.scopeCount() == 0 )
248 {
249 //empty scope, populate with initial scopes
251 }
252
253 c << QgsExpressionContextUtils::processingAlgorithmScope( this, parameters, context );
254 return c;
255}
256
257bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, QgsProcessingContext &context ) const
258{
260 {
261 // I'm a well behaved algorithm - I take work AWAY from users!
262 return true;
263 }
264
265 bool foundCrs = false;
267 for ( const QgsProcessingParameterDefinition *def : mParameters )
268 {
270 {
271 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( def, parameters, context );
272 if ( layer )
273 {
274 if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
275 {
276 return false;
277 }
278 else if ( !foundCrs && layer->crs().isValid() )
279 {
280 foundCrs = true;
281 crs = layer->crs();
282 }
283 }
284 }
285 else if ( def->type() == QgsProcessingParameterFeatureSource::typeName() )
286 {
287 std::unique_ptr< QgsFeatureSource > source( QgsProcessingParameters::parameterAsSource( def, parameters, context ) );
288 if ( source )
289 {
290 if ( foundCrs && source->sourceCrs().isValid() && crs != source->sourceCrs() )
291 {
292 return false;
293 }
294 else if ( !foundCrs && source->sourceCrs().isValid() )
295 {
296 foundCrs = true;
297 crs = source->sourceCrs();
298 }
299 }
300 }
301 else if ( def->type() == QgsProcessingParameterMultipleLayers::typeName() )
302 {
303 QList< QgsMapLayer *> layers = QgsProcessingParameters::parameterAsLayerList( def, parameters, context );
304 const auto constLayers = layers;
305 for ( QgsMapLayer *layer : constLayers )
306 {
307 if ( !layer )
308 continue;
309
310 if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
311 {
312 return false;
313 }
314 else if ( !foundCrs && layer->crs().isValid() )
315 {
316 foundCrs = true;
317 crs = layer->crs();
318 }
319 }
320 }
321 else if ( def->type() == QgsProcessingParameterExtent::typeName() )
322 {
324 if ( foundCrs && extentCrs.isValid() && crs != extentCrs )
325 {
326 return false;
327 }
328 else if ( !foundCrs && extentCrs.isValid() )
329 {
330 foundCrs = true;
331 crs = extentCrs;
332 }
333 }
334 else if ( def->type() == QgsProcessingParameterPoint::typeName() )
335 {
337 if ( foundCrs && pointCrs.isValid() && crs != pointCrs )
338 {
339 return false;
340 }
341 else if ( !foundCrs && pointCrs.isValid() )
342 {
343 foundCrs = true;
344 crs = pointCrs;
345 }
346 }
347 else if ( def->type() == QgsProcessingParameterGeometry::typeName() )
348 {
350 if ( foundCrs && geomCrs.isValid() && crs != geomCrs )
351 {
352 return false;
353 }
354 else if ( !foundCrs && geomCrs.isValid() )
355 {
356 foundCrs = true;
357 crs = geomCrs;
358 }
359 }
360 }
361 return true;
362}
363
364QString QgsProcessingAlgorithm::asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const
365{
366 QString s = u"processing.run(\"%1\","_s.arg( id() );
367
368 QStringList parts;
369 for ( const QgsProcessingParameterDefinition *def : mParameters )
370 {
371 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
372 continue;
373
374 if ( !parameters.contains( def->name() ) )
375 continue;
376
377 parts << u"'%1':%2"_s.arg( def->name(), def->valueAsPythonString( parameters.value( def->name() ), context ) );
378 }
379
380 s += u" {%1})"_s.arg( parts.join( ',' ) );
381 return s;
382}
383
384QString QgsProcessingAlgorithm::asQgisProcessCommand( const QVariantMap &parameters, QgsProcessingContext &context, bool &ok ) const
385{
386 ok = true;
387 QStringList parts;
388 parts.append( u"qgis_process"_s );
389 parts.append( u"run"_s );
390 parts.append( id() );
391
393 // we only include the project path argument if a project is actually required by the algorithm
396
397 parts.append( context.asQgisProcessArguments( argumentFlags ) );
398
399 auto escapeIfNeeded = []( const QString &input ) -> QString {
400 // play it safe and escape everything UNLESS it's purely alphanumeric characters (and a very select scattering of other common characters!)
401 const thread_local QRegularExpression nonAlphaNumericRx( u"[^a-zA-Z0-9.\\-/_]"_s );
402 if ( nonAlphaNumericRx.match( input ).hasMatch() )
403 {
404 QString escaped = input;
405 escaped.replace( '\'', "'\\''"_L1 );
406 return u"'%1'"_s.arg( escaped );
407 }
408 else
409 {
410 return input;
411 }
412 };
413
414 for ( const QgsProcessingParameterDefinition *def : mParameters )
415 {
416 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
417 continue;
418
419 if ( !parameters.contains( def->name() ) )
420 continue;
421
422 const QStringList partValues = def->valueAsStringList( parameters.value( def->name() ), context, ok );
423 if ( !ok )
424 return QString();
425
426 for ( const QString &partValue : partValues )
427 {
428 parts << u"--%1=%2"_s.arg( def->name(), escapeIfNeeded( partValue ) );
429 }
430 }
431
432 return parts.join( ' ' );
433}
434
435QVariantMap QgsProcessingAlgorithm::asMap( const QVariantMap &parameters, QgsProcessingContext &context ) const
436{
437 QVariantMap properties = context.exportToMap();
438
439 // we only include the project path argument if a project is actually required by the algorithm
441 properties.remove( u"project_path"_s );
442
443 QVariantMap paramValues;
444 for ( const QgsProcessingParameterDefinition *def : mParameters )
445 {
446 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
447 continue;
448
449 if ( !parameters.contains( def->name() ) )
450 continue;
451
452 paramValues.insert( def->name(), def->valueAsJsonObject( parameters.value( def->name() ), context ) );
453 }
454
455 properties.insert( u"inputs"_s, paramValues );
456 return properties;
457}
458
460{
461 return addParameter( std::unique_ptr<QgsProcessingParameterDefinition>( definition ), createOutput );
462}
463
464bool QgsProcessingAlgorithm::addParameter( std::unique_ptr<QgsProcessingParameterDefinition> definition, bool createOutput )
465{
466 if ( !definition )
467 return false;
468
469 // check for duplicate named parameters
470 const QgsProcessingParameterDefinition *existingDef = QgsProcessingAlgorithm::parameterDefinition( definition->name() );
471 if ( existingDef && existingDef->name() == definition->name() ) // parameterDefinition is case-insensitive, but we DO allow case-different duplicate names
472 {
473 QgsMessageLog::logMessage( QObject::tr( "Duplicate parameter %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
474 return false;
475 }
476
477 if ( definition->isDestination() && mProvider )
478 {
479 QgsProcessingDestinationParameter *destParam = static_cast< QgsProcessingDestinationParameter *>( definition.get() );
480 if ( !mProvider->supportsNonFileBasedOutput() )
481 destParam->setSupportsNonFileBasedOutput( false );
482 }
483
484 definition->mAlgorithm = this;
485 mParameters << definition.release();
486 const QgsProcessingParameterDefinition *definitionRawPtr = mParameters.back();
487
488 if ( createOutput )
489 return createAutoOutputForParameter( definitionRawPtr );
490 else
491 return true;
492}
493
495{
497 if ( def )
498 {
499 delete def;
500 mParameters.removeAll( def );
501
502 // remove output automatically created when adding parameter
504 if ( outputDef && outputDef->autoCreated() )
505 {
506 delete outputDef;
507 mOutputs.removeAll( outputDef );
508 }
509 }
510}
511
513{
514 return addOutput( std::unique_ptr<QgsProcessingOutputDefinition>( definition ) );
515}
516
517bool QgsProcessingAlgorithm::addOutput( std::unique_ptr<QgsProcessingOutputDefinition> definition )
518{
519 if ( !definition )
520 return false;
521
522 // check for duplicate named outputs
523 if ( QgsProcessingAlgorithm::outputDefinition( definition->name() ) )
524 {
525 QgsMessageLog::logMessage( QObject::tr( "Duplicate output %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
526 return false;
527 }
528
529 mOutputs << definition.release();
530 return true;
531}
532
534{
535 return true;
536}
537
542
544{
545 // first pass - case sensitive match
546 for ( const QgsProcessingParameterDefinition *def : mParameters )
547 {
548 if ( def->name() == name )
549 return def;
550 }
551
552 // second pass - case insensitive
553 for ( const QgsProcessingParameterDefinition *def : mParameters )
554 {
555 if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
556 return def;
557 }
558 return nullptr;
559}
560
562{
563 int count = 0;
564 for ( const QgsProcessingParameterDefinition *def : mParameters )
565 {
566 if ( !( def->flags() & Qgis::ProcessingParameterFlag::Hidden ) )
567 count++;
568 }
569 return count;
570}
571
573{
575 for ( const QgsProcessingParameterDefinition *def : mParameters )
576 {
577 if ( def->isDestination() )
578 result << def;
579 }
580 return result;
581}
582
584{
585 for ( const QgsProcessingOutputDefinition *def : mOutputs )
586 {
587 if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
588 return def;
589 }
590 return nullptr;
591}
592
594{
595 for ( const QgsProcessingOutputDefinition *def : mOutputs )
596 {
597 if ( def->type() == "outputHtml"_L1 )
598 return true;
599 }
600 return false;
601}
602
604 const QString &, const QVariantMap &, QgsProcessingContext &, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> &
605) const
606{
607 return VectorProperties();
608}
609
610QVariantMap QgsProcessingAlgorithm::run( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok, const QVariantMap &configuration, bool catchExceptions ) const
611{
612 std::unique_ptr< QgsProcessingAlgorithm > alg( create( configuration ) );
613 if ( ok )
614 *ok = false;
615
616 bool res = alg->prepare( parameters, context, feedback );
617 if ( !res )
618 return QVariantMap();
619
620 QVariantMap runRes;
621 bool success = false;
622 try
623 {
624 runRes = alg->runPrepared( parameters, context, feedback );
625 success = true;
626 }
627 catch ( QgsProcessingException &e )
628 {
629 if ( !catchExceptions )
630 {
631 alg->postProcess( context, feedback, false );
632 throw e;
633 }
634
635 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
636 feedback->reportError( e.what() );
637 }
638
639 if ( ok )
640 *ok = success;
641
642 QVariantMap ppRes = alg->postProcess( context, feedback, success );
643 if ( !ppRes.isEmpty() )
644 return ppRes;
645 else
646 return runRes;
647}
648
649bool QgsProcessingAlgorithm::prepare( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
650{
651 // cppcheck-suppress assertWithSideEffect
652 Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::prepare", "prepare() must be called from the same thread as context was created in" );
653 Q_ASSERT_X( !mHasPrepared, "QgsProcessingAlgorithm::prepare", "prepare() has already been called for the algorithm instance" );
654 try
655 {
656 mHasPrepared = prepareAlgorithm( parameters, context, feedback );
657 return mHasPrepared;
658 }
659 catch ( QgsProcessingException &e )
660 {
661 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
662 feedback->reportError( e.what() );
663 return false;
664 }
665}
666
667QVariantMap QgsProcessingAlgorithm::runPrepared( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
668{
669 Q_ASSERT_X( mHasPrepared, "QgsProcessingAlgorithm::runPrepared", u"prepare() was not called for the algorithm instance %1"_s.arg( name() ).toLatin1() );
670 Q_ASSERT_X( !mHasExecuted, "QgsProcessingAlgorithm::runPrepared", "runPrepared() was already called for this algorithm instance" );
671
672 // Hey kids, let's all be thread safe! It's the fun thing to do!
673 //
674 // First, let's see if we're going to run into issues.
675 QgsProcessingContext *runContext = nullptr;
676 if ( context.thread() == QThread::currentThread() )
677 {
678 // OH. No issues. Seems you're running everything in the same thread, so go about your business. Sorry about
679 // the intrusion, we're just making sure everything's nice and safe here. We like to keep a clean and tidy neighbourhood,
680 // you know, for the kids and dogs and all.
681 runContext = &context;
682 }
683 else
684 {
685 // HA! I knew things looked a bit suspicious - seems you're running this algorithm in a different thread
686 // from that which the passed context has an affinity for. That's fine and all, but we need to make sure
687 // we proceed safely...
688
689 // So first we create a temporary local context with affinity for the current thread
690 mLocalContext = std::make_unique<QgsProcessingContext>();
691 // copy across everything we can safely do from the passed context
692 mLocalContext->copyThreadSafeSettings( context );
693
694 // and we'll run the actual algorithm processing using the local thread safe context
695 runContext = mLocalContext.get();
696 }
697
698 std::unique_ptr< QgsProcessingModelInitialRunConfig > modelConfig = context.takeModelInitialRunConfig();
699 if ( modelConfig )
700 {
701 std::unique_ptr< QgsMapLayerStore > modelPreviousLayerStore = modelConfig->takePreviousLayerStore();
702 if ( modelPreviousLayerStore )
703 {
704 // move layers from previous layer store to context's temporary layer store, in a thread-safe way
705 Q_ASSERT_X( !modelPreviousLayerStore->thread(), "QgsProcessingAlgorithm::runPrepared", "QgsProcessingModelConfig::modelPreviousLayerStore must have been pushed to a nullptr thread" );
706 modelPreviousLayerStore->moveToThread( QThread::currentThread() );
707 runContext->temporaryLayerStore()->transferLayersFromStore( modelPreviousLayerStore.get() );
708 }
709 runContext->setModelInitialRunConfig( std::move( modelConfig ) );
710 }
711
712 mHasExecuted = true;
713 try
714 {
715 QVariantMap runResults = processAlgorithm( parameters, *runContext, feedback );
716
717 if ( mLocalContext )
718 {
719 // ok, time to clean things up. We need to push the temporary context back into
720 // the thread that the passed context is associated with (we can only push from the
721 // current thread, so we HAVE to do this here)
722 mLocalContext->pushToThread( context.thread() );
723 }
724 return runResults;
725 }
726 catch ( QgsProcessingException & )
727 {
728 if ( mLocalContext )
729 {
730 // see above!
731 mLocalContext->pushToThread( context.thread() );
732 }
733 //rethrow
734 throw;
735 }
736}
737
739{
740 // cppcheck-suppress assertWithSideEffect
741 Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::postProcess", "postProcess() must be called from the same thread the context was created in" );
742 Q_ASSERT_X( mHasExecuted, "QgsProcessingAlgorithm::postProcess", u"algorithm instance %1 was not executed"_s.arg( name() ).toLatin1() );
743 Q_ASSERT_X( !mHasPostProcessed, "QgsProcessingAlgorithm::postProcess", "postProcess() was already called for this algorithm instance" );
744
745 if ( mLocalContext )
746 {
747 // algorithm was processed using a temporary thread safe context. So now we need
748 // to take the results from that temporary context, and smash them into the passed
749 // context
750 context.takeResultsFrom( *mLocalContext );
751 // now get lost, we don't need you anymore
752 mLocalContext.reset();
753 }
754
755 mHasPostProcessed = true;
756 if ( runResult )
757 {
758 try
759 {
760 return postProcessAlgorithm( context, feedback );
761 }
762 catch ( QgsProcessingException &e )
763 {
764 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
765 feedback->reportError( e.what() );
766 return QVariantMap();
767 }
768 }
769 else
770 {
771 return QVariantMap();
772 }
773}
774
775QString QgsProcessingAlgorithm::parameterAsString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
776{
778}
779
780QString QgsProcessingAlgorithm::parameterAsExpression( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
781{
783}
784
785double QgsProcessingAlgorithm::parameterAsDouble( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
786{
788}
789
790int QgsProcessingAlgorithm::parameterAsInt( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
791{
792 return QgsProcessingParameters::parameterAsInt( parameterDefinition( name ), parameters, context );
793}
794
795QList<int> QgsProcessingAlgorithm::parameterAsInts( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
796{
797 return QgsProcessingParameters::parameterAsInts( parameterDefinition( name ), parameters, context );
798}
799
800int QgsProcessingAlgorithm::parameterAsEnum( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
801{
802 return QgsProcessingParameters::parameterAsEnum( parameterDefinition( name ), parameters, context );
803}
804
805QList<int> QgsProcessingAlgorithm::parameterAsEnums( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
806{
808}
809
810QString QgsProcessingAlgorithm::parameterAsEnumString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
811{
813}
814
815QStringList QgsProcessingAlgorithm::parameterAsEnumStrings( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
816{
818}
819
820bool QgsProcessingAlgorithm::parameterAsBool( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
821{
822 return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
823}
824
825bool QgsProcessingAlgorithm::parameterAsBoolean( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
826{
827 return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
828}
829
831 const QVariantMap &parameters,
832 const QString &name,
833 QgsProcessingContext &context,
834 QString &destinationIdentifier,
835 const QgsFields &fields,
836 Qgis::WkbType geometryType,
839 const QVariantMap &createOptions,
840 const QStringList &datasourceOptions,
841 const QStringList &layerOptions
842) const
843{
844 if ( !parameterDefinition( name ) )
845 throw QgsProcessingException( QObject::tr( "No parameter definition for the sink '%1'" ).arg( name ) );
846
847 return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
848}
849
850QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
851{
853}
854
856 const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback
857) const
858{
859 return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback );
860}
861
863 const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName
864) const
865{
866 return QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback, layerName );
867}
868
869QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
870{
872}
873
874QgsRasterLayer *QgsProcessingAlgorithm::parameterAsRasterLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
875{
877}
878
879QgsMeshLayer *QgsProcessingAlgorithm::parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
880{
882}
883
884QString QgsProcessingAlgorithm::parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
885{
887}
888
889QString QgsProcessingAlgorithm::parameterAsOutputFormat( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
890{
892}
893
894QString QgsProcessingAlgorithm::parameterAsOutputRasterFormat( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
895{
896 QString outputFormat = parameterAsOutputFormat( parameters, name, context );
897 if ( outputFormat.isEmpty() )
898 {
900 QVariant val;
901 if ( definition )
902 {
903 val = parameters.value( definition->name() );
904 }
905 QString outputFile = QgsProcessingParameters::parameterAsOutputLayer( definition, val, context, /* testOnly = */ true );
906 if ( !outputFile.isEmpty() )
907 {
908 const QFileInfo fi( outputFile );
909 outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() );
910 }
911 }
912 return outputFormat;
913}
914
915QString QgsProcessingAlgorithm::parameterAsFileOutput( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
916{
918}
919
920QgsVectorLayer *QgsProcessingAlgorithm::parameterAsVectorLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
921{
923}
924
925QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
926{
927 return QgsProcessingParameters::parameterAsCrs( parameterDefinition( name ), parameters, context );
928}
929
930QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsExtentCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
931{
933}
934
935QgsRectangle QgsProcessingAlgorithm::parameterAsExtent( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
936{
937 return QgsProcessingParameters::parameterAsExtent( parameterDefinition( name ), parameters, context, crs );
938}
939
940QgsGeometry QgsProcessingAlgorithm::parameterAsExtentGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
941{
943}
944
945QgsPointXY QgsProcessingAlgorithm::parameterAsPoint( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
946{
947 return QgsProcessingParameters::parameterAsPoint( parameterDefinition( name ), parameters, context, crs );
948}
949
950QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsPointCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
951{
953}
954
955QgsGeometry QgsProcessingAlgorithm::parameterAsGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
956{
957 return QgsProcessingParameters::parameterAsGeometry( parameterDefinition( name ), parameters, context, crs );
958}
959
960QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsGeometryCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
961{
963}
964
965QString QgsProcessingAlgorithm::parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
966{
967 return QgsProcessingParameters::parameterAsFile( parameterDefinition( name ), parameters, context );
968}
969
970QVariantList QgsProcessingAlgorithm::parameterAsMatrix( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
971{
973}
974
975QList<QgsMapLayer *> QgsProcessingAlgorithm::parameterAsLayerList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags ) const
976{
978}
979
980QStringList QgsProcessingAlgorithm::parameterAsFileList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
981{
983}
984
985QList<double> QgsProcessingAlgorithm::parameterAsRange( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
986{
988}
989
990QStringList QgsProcessingAlgorithm::parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
991{
993}
994
995QStringList QgsProcessingAlgorithm::parameterAsStrings( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
996{
998}
999
1000QgsPrintLayout *QgsProcessingAlgorithm::parameterAsLayout( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
1001{
1003}
1004
1005QgsLayoutItem *QgsProcessingAlgorithm::parameterAsLayoutItem( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsPrintLayout *layout )
1006{
1007 return QgsProcessingParameters::parameterAsLayoutItem( parameterDefinition( name ), parameters, context, layout );
1008}
1009
1010QColor QgsProcessingAlgorithm::parameterAsColor( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
1011{
1012 return QgsProcessingParameters::parameterAsColor( parameterDefinition( name ), parameters, context );
1013}
1014
1015QString QgsProcessingAlgorithm::parameterAsConnectionName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
1016{
1018}
1019
1020QDateTime QgsProcessingAlgorithm::parameterAsDateTime( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
1021{
1023}
1024
1025QString QgsProcessingAlgorithm::parameterAsSchema( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
1026{
1028}
1029
1030QString QgsProcessingAlgorithm::parameterAsDatabaseTableName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
1031{
1033}
1034
1039
1040QgsAnnotationLayer *QgsProcessingAlgorithm::parameterAsAnnotationLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
1041{
1043}
1044
1045QString QgsProcessingAlgorithm::invalidSourceError( const QVariantMap &parameters, const QString &name )
1046{
1047 if ( !parameters.contains( name ) )
1048 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
1049 else
1050 {
1051 QVariant var = parameters.value( name );
1052 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
1053 {
1054 QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
1055 var = fromVar.source;
1056 }
1057 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1058 {
1059 QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1060 var = fromVar.sink;
1061 }
1062 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1063 {
1064 QgsProperty p = var.value< QgsProperty >();
1066 {
1067 var = p.staticValue();
1068 }
1069 }
1070 if ( !var.toString().isEmpty() )
1071 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
1072 else
1073 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
1074 }
1075}
1076
1077QString QgsProcessingAlgorithm::invalidRasterError( const QVariantMap &parameters, const QString &name )
1078{
1079 if ( !parameters.contains( name ) )
1080 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
1081 else
1082 {
1083 QVariant var = parameters.value( name );
1084 if ( var.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
1085 {
1086 QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( var );
1087 var = fromVar.source;
1088 }
1089 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1090 {
1091 QgsProperty p = var.value< QgsProperty >();
1093 {
1094 var = p.staticValue();
1095 }
1096 }
1097 if ( !var.toString().isEmpty() )
1098 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
1099 else
1100 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
1101 }
1102}
1103
1104QString QgsProcessingAlgorithm::invalidSinkError( const QVariantMap &parameters, const QString &name )
1105{
1106 if ( !parameters.contains( name ) )
1107 return QObject::tr( "Could not create destination layer for %1: no value specified for parameter" ).arg( name );
1108 else
1109 {
1110 QVariant var = parameters.value( name );
1111 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1112 {
1113 QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1114 var = fromVar.sink;
1115 }
1116 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1117 {
1118 QgsProperty p = var.value< QgsProperty >();
1120 {
1121 var = p.staticValue();
1122 }
1123 }
1124 if ( !var.toString().isEmpty() )
1125 return QObject::tr( "Could not create destination layer for %1: %2" ).arg( name, var.toString() );
1126 else
1127 return QObject::tr( "Could not create destination layer for %1: invalid value" ).arg( name );
1128 }
1129}
1130
1131QString QgsProcessingAlgorithm::invalidPointCloudError( const QVariantMap &parameters, const QString &name )
1132{
1133 if ( !parameters.contains( name ) )
1134 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
1135 else
1136 {
1137 QVariant var = parameters.value( name );
1138 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1139 {
1140 QgsProperty p = var.value< QgsProperty >();
1142 {
1143 var = p.staticValue();
1144 }
1145 }
1146 if ( !var.toString().isEmpty() )
1147 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
1148 else
1149 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
1150 }
1151}
1152
1153QString QgsProcessingAlgorithm::writeFeatureError( QgsFeatureSink *sink, const QVariantMap &parameters, const QString &name )
1154{
1155 Q_UNUSED( sink );
1156 Q_UNUSED( parameters );
1157 const QString lastError = sink->lastError();
1158 if ( !lastError.isEmpty() )
1159 {
1160 if ( !name.isEmpty() )
1161 return QObject::tr( "Could not write feature into %1: %2" ).arg( name, lastError );
1162 else
1163 return QObject::tr( "Could not write feature: %1" ).arg( lastError );
1164 }
1165 else
1166 {
1167 if ( !name.isEmpty() )
1168 return QObject::tr( "Could not write feature into %1" ).arg( name );
1169 else
1170 return QObject::tr( "Could not write feature" );
1171 }
1172}
1173
1175{
1176 Q_UNUSED( layer )
1177 return false;
1178}
1179
1180
1181bool QgsProcessingAlgorithm::createAutoOutputForParameter( const QgsProcessingParameterDefinition *parameter )
1182{
1183 if ( !parameter->isDestination() )
1184 return true; // nothing created, but nothing went wrong - so return true
1185
1186 const QgsProcessingDestinationParameter *dest = static_cast< const QgsProcessingDestinationParameter * >( parameter );
1188 if ( !output )
1189 return true; // nothing created - but nothing went wrong - so return true
1190 output->setAutoCreated( true );
1191
1192 if ( !addOutput( output ) )
1193 {
1194 // couldn't add output - probably a duplicate name
1195 return false;
1196 }
1197 else
1198 {
1199 return true;
1200 }
1201}
1202
1203
1204//
1205// QgsProcessingFeatureBasedAlgorithm
1206//
1207
1214
1216{
1218 initParameters( config );
1219 addParameter( new QgsProcessingParameterFeatureSink( u"OUTPUT"_s, outputName(), outputLayerType(), QVariant(), false, true, true ) );
1220}
1221
1223{
1224 return u"INPUT"_s;
1225}
1226
1228{
1229 return QObject::tr( "Input layer" );
1230}
1231
1233{
1234 return QList<int>();
1235}
1236
1241
1246
1251
1253{
1254 return inputWkbType;
1255}
1256
1258{
1259 return inputFields;
1260}
1261
1266
1269
1271{
1272 if ( mSource )
1273 return mSource->sourceCrs();
1274 else
1276}
1277
1278QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
1279{
1280 prepareSource( parameters, context );
1281 QString dest;
1282 std::unique_ptr< QgsFeatureSink > sink(
1283 parameterAsSink( parameters, u"OUTPUT"_s, context, dest, outputFields( mSource->fields() ), outputWkbType( mSource->wkbType() ), outputCrs( mSource->sourceCrs() ), sinkFlags() )
1284 );
1285 if ( !sink )
1286 throw QgsProcessingException( invalidSinkError( parameters, u"OUTPUT"_s ) );
1287
1288 // prepare expression context for feature iteration
1289 QgsExpressionContext prevContext = context.expressionContext();
1290 QgsExpressionContext algContext = prevContext;
1291
1292 algContext.appendScopes( createExpressionContext( parameters, context, mSource.get() ).takeScopes() );
1293 context.setExpressionContext( algContext );
1294
1295 long count = mSource->featureCount();
1296
1297 QgsFeature f;
1298 QgsFeatureIterator it = mSource->getFeatures( request(), sourceFlags() );
1299
1300 double step = count > 0 ? 100.0 / count : 1;
1301 int current = 0;
1302 while ( it.nextFeature( f ) )
1303 {
1304 if ( feedback->isCanceled() )
1305 {
1306 break;
1307 }
1308
1309 context.expressionContext().setFeature( f );
1310 const QgsFeatureList transformed = processFeature( f, context, feedback );
1311 for ( QgsFeature transformedFeature : transformed )
1312 {
1313 if ( !sink->addFeature( transformedFeature, QgsFeatureSink::FastInsert ) )
1314 {
1315 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QString() ) );
1316 }
1317 else
1318 {
1319 feedback->featureAddedToSink( u"OUTPUT"_s );
1320 }
1321 }
1322
1323 feedback->setProgress( current * step );
1324 current++;
1325 }
1326
1327 sink->finalize();
1328 feedback->featureSinkFinalized( u"OUTPUT"_s );
1329
1330 mSource.reset();
1331
1332 // probably not necessary - context's aren't usually recycled, but can't hurt
1333 context.setExpressionContext( prevContext );
1334
1335 QVariantMap outputs;
1336 outputs.insert( u"OUTPUT"_s, dest );
1337 return outputs;
1338}
1339
1344
1346{
1347 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
1348 if ( !layer )
1349 return false;
1350
1351 Qgis::GeometryType inPlaceGeometryType = layer->geometryType();
1352 if ( !inputLayerTypes().empty() &&
1353 !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::Vector ) ) &&
1354 !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry ) ) &&
1355 ( ( inPlaceGeometryType == Qgis::GeometryType::Polygon && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon ) ) ) ||
1356 ( inPlaceGeometryType == Qgis::GeometryType::Line && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorLine ) ) ) ||
1357 ( inPlaceGeometryType == Qgis::GeometryType::Point && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorPoint ) ) ) ) )
1358 return false;
1359
1361 if ( inPlaceGeometryType == Qgis::GeometryType::Point )
1362 type = Qgis::WkbType::Point;
1363 else if ( inPlaceGeometryType == Qgis::GeometryType::Line )
1365 else if ( inPlaceGeometryType == Qgis::GeometryType::Polygon )
1367
1368 if ( QgsWkbTypes::geometryType( outputWkbType( type ) ) != inPlaceGeometryType )
1369 return false;
1370
1371 return true;
1372}
1373
1375{
1376 if ( !mSource )
1377 {
1378 mSource.reset( parameterAsSource( parameters, inputParameterName(), context ) );
1379 if ( !mSource )
1381 }
1382}
1383
1384
1386 const QString &sink, const QVariantMap &parameters, QgsProcessingContext &context, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> &sourceProperties
1387) const
1388{
1390 if ( sink == "OUTPUT"_L1 )
1391 {
1392 if ( sourceProperties.value( u"INPUT"_s ).availability == Qgis::ProcessingPropertyAvailability::Available )
1393 {
1394 const VectorProperties inputProps = sourceProperties.value( u"INPUT"_s );
1395 result.fields = outputFields( inputProps.fields );
1396 result.crs = outputCrs( inputProps.crs );
1397 result.wkbType = outputWkbType( inputProps.wkbType );
1399 return result;
1400 }
1401 else
1402 {
1403 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, u"INPUT"_s, context ) );
1404 if ( source )
1405 {
1406 result.fields = outputFields( source->fields() );
1407 result.crs = outputCrs( source->sourceCrs() );
1408 result.wkbType = outputWkbType( source->wkbType() );
1410 return result;
1411 }
1412 }
1413 }
1414 return result;
1415}
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 QString implementationSourceUri() const
Returns a URL for the source code location best reflecting the internal algorithm logic.
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 QList< QgsProcessingAlgorithm::ExternalLink > externalLinks() const
Returns a list of external links describing the algorithm's behavior or source.
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
std::unordered_map< std::type_index, QString > & algorithmSourceRegistry()
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.