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