QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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{
180 // start with context's expression context
182
183 // If there's a source capable of generating a context scope, use it
184 if ( source )
185 {
187 if ( scope )
188 c << scope;
189 }
190 else if ( c.scopeCount() == 0 )
191 {
192 //empty scope, populate with initial scopes
194 }
195
196 c << QgsExpressionContextUtils::processingAlgorithmScope( this, parameters, context );
197 return c;
198}
199
200bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, QgsProcessingContext &context ) const
201{
203 {
204 // I'm a well behaved algorithm - I take work AWAY from users!
205 return true;
206 }
207
208 bool foundCrs = false;
210 for ( const QgsProcessingParameterDefinition *def : mParameters )
211 {
213 {
214 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( def, parameters, context );
215 if ( layer )
216 {
217 if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
218 {
219 return false;
220 }
221 else if ( !foundCrs && layer->crs().isValid() )
222 {
223 foundCrs = true;
224 crs = layer->crs();
225 }
226 }
227 }
228 else if ( def->type() == QgsProcessingParameterFeatureSource::typeName() )
229 {
230 std::unique_ptr< QgsFeatureSource > source( QgsProcessingParameters::parameterAsSource( def, parameters, context ) );
231 if ( source )
232 {
233 if ( foundCrs && source->sourceCrs().isValid() && crs != source->sourceCrs() )
234 {
235 return false;
236 }
237 else if ( !foundCrs && source->sourceCrs().isValid() )
238 {
239 foundCrs = true;
240 crs = source->sourceCrs();
241 }
242 }
243 }
244 else if ( def->type() == QgsProcessingParameterMultipleLayers::typeName() )
245 {
246 QList< QgsMapLayer *> layers = QgsProcessingParameters::parameterAsLayerList( def, parameters, context );
247 const auto constLayers = layers;
248 for ( QgsMapLayer *layer : constLayers )
249 {
250 if ( !layer )
251 continue;
252
253 if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
254 {
255 return false;
256 }
257 else if ( !foundCrs && layer->crs().isValid() )
258 {
259 foundCrs = true;
260 crs = layer->crs();
261 }
262 }
263 }
264 else if ( def->type() == QgsProcessingParameterExtent::typeName() )
265 {
267 if ( foundCrs && extentCrs.isValid() && crs != extentCrs )
268 {
269 return false;
270 }
271 else if ( !foundCrs && extentCrs.isValid() )
272 {
273 foundCrs = true;
274 crs = extentCrs;
275 }
276 }
277 else if ( def->type() == QgsProcessingParameterPoint::typeName() )
278 {
280 if ( foundCrs && pointCrs.isValid() && crs != pointCrs )
281 {
282 return false;
283 }
284 else if ( !foundCrs && pointCrs.isValid() )
285 {
286 foundCrs = true;
287 crs = pointCrs;
288 }
289 }
290 else if ( def->type() == QgsProcessingParameterGeometry::typeName() )
291 {
293 if ( foundCrs && geomCrs.isValid() && crs != geomCrs )
294 {
295 return false;
296 }
297 else if ( !foundCrs && geomCrs.isValid() )
298 {
299 foundCrs = true;
300 crs = geomCrs;
301 }
302 }
303 }
304 return true;
305}
306
307QString QgsProcessingAlgorithm::asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const
308{
309 QString s = u"processing.run(\"%1\","_s.arg( id() );
310
311 QStringList parts;
312 for ( const QgsProcessingParameterDefinition *def : mParameters )
313 {
314 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
315 continue;
316
317 if ( !parameters.contains( def->name() ) )
318 continue;
319
320 parts << u"'%1':%2"_s.arg( def->name(), def->valueAsPythonString( parameters.value( def->name() ), context ) );
321 }
322
323 s += u" {%1})"_s.arg( parts.join( ',' ) );
324 return s;
325}
326
327QString QgsProcessingAlgorithm::asQgisProcessCommand( const QVariantMap &parameters, QgsProcessingContext &context, bool &ok ) const
328{
329 ok = true;
330 QStringList parts;
331 parts.append( u"qgis_process"_s );
332 parts.append( u"run"_s );
333 parts.append( id() );
334
336 // we only include the project path argument if a project is actually required by the algorithm
339
340 parts.append( context.asQgisProcessArguments( argumentFlags ) );
341
342 auto escapeIfNeeded = []( const QString &input ) -> QString {
343 // play it safe and escape everything UNLESS it's purely alphanumeric characters (and a very select scattering of other common characters!)
344 const thread_local QRegularExpression nonAlphaNumericRx( u"[^a-zA-Z0-9.\\-/_]"_s );
345 if ( nonAlphaNumericRx.match( input ).hasMatch() )
346 {
347 QString escaped = input;
348 escaped.replace( '\'', "'\\''"_L1 );
349 return u"'%1'"_s.arg( escaped );
350 }
351 else
352 {
353 return input;
354 }
355 };
356
357 for ( const QgsProcessingParameterDefinition *def : mParameters )
358 {
359 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
360 continue;
361
362 if ( !parameters.contains( def->name() ) )
363 continue;
364
365 const QStringList partValues = def->valueAsStringList( parameters.value( def->name() ), context, ok );
366 if ( !ok )
367 return QString();
368
369 for ( const QString &partValue : partValues )
370 {
371 parts << u"--%1=%2"_s.arg( def->name(), escapeIfNeeded( partValue ) );
372 }
373 }
374
375 return parts.join( ' ' );
376}
377
378QVariantMap QgsProcessingAlgorithm::asMap( const QVariantMap &parameters, QgsProcessingContext &context ) const
379{
380 QVariantMap properties = context.exportToMap();
381
382 // we only include the project path argument if a project is actually required by the algorithm
384 properties.remove( u"project_path"_s );
385
386 QVariantMap paramValues;
387 for ( const QgsProcessingParameterDefinition *def : mParameters )
388 {
389 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
390 continue;
391
392 if ( !parameters.contains( def->name() ) )
393 continue;
394
395 paramValues.insert( def->name(), def->valueAsJsonObject( parameters.value( def->name() ), context ) );
396 }
397
398 properties.insert( u"inputs"_s, paramValues );
399 return properties;
400}
401
403{
404 return addParameter( std::unique_ptr<QgsProcessingParameterDefinition>( definition ), createOutput );
405}
406
407bool QgsProcessingAlgorithm::addParameter( std::unique_ptr<QgsProcessingParameterDefinition> definition, bool createOutput )
408{
409 if ( !definition )
410 return false;
411
412 // check for duplicate named parameters
413 const QgsProcessingParameterDefinition *existingDef = QgsProcessingAlgorithm::parameterDefinition( definition->name() );
414 if ( existingDef && existingDef->name() == definition->name() ) // parameterDefinition is case-insensitive, but we DO allow case-different duplicate names
415 {
416 QgsMessageLog::logMessage( QObject::tr( "Duplicate parameter %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
417 return false;
418 }
419
420 if ( definition->isDestination() && mProvider )
421 {
422 QgsProcessingDestinationParameter *destParam = static_cast< QgsProcessingDestinationParameter *>( definition.get() );
423 if ( !mProvider->supportsNonFileBasedOutput() )
424 destParam->setSupportsNonFileBasedOutput( false );
425 }
426
427 definition->mAlgorithm = this;
428 mParameters << definition.release();
429 const QgsProcessingParameterDefinition *definitionRawPtr = mParameters.back();
430
431 if ( createOutput )
432 return createAutoOutputForParameter( definitionRawPtr );
433 else
434 return true;
435}
436
438{
440 if ( def )
441 {
442 delete def;
443 mParameters.removeAll( def );
444
445 // remove output automatically created when adding parameter
447 if ( outputDef && outputDef->autoCreated() )
448 {
449 delete outputDef;
450 mOutputs.removeAll( outputDef );
451 }
452 }
453}
454
456{
457 return addOutput( std::unique_ptr<QgsProcessingOutputDefinition>( definition ) );
458}
459
460bool QgsProcessingAlgorithm::addOutput( std::unique_ptr<QgsProcessingOutputDefinition> definition )
461{
462 if ( !definition )
463 return false;
464
465 // check for duplicate named outputs
466 if ( QgsProcessingAlgorithm::outputDefinition( definition->name() ) )
467 {
468 QgsMessageLog::logMessage( QObject::tr( "Duplicate output %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
469 return false;
470 }
471
472 mOutputs << definition.release();
473 return true;
474}
475
477{
478 return true;
479}
480
485
487{
488 // first pass - case sensitive match
489 for ( const QgsProcessingParameterDefinition *def : mParameters )
490 {
491 if ( def->name() == name )
492 return def;
493 }
494
495 // second pass - case insensitive
496 for ( const QgsProcessingParameterDefinition *def : mParameters )
497 {
498 if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
499 return def;
500 }
501 return nullptr;
502}
503
505{
506 int count = 0;
507 for ( const QgsProcessingParameterDefinition *def : mParameters )
508 {
509 if ( !( def->flags() & Qgis::ProcessingParameterFlag::Hidden ) )
510 count++;
511 }
512 return count;
513}
514
516{
518 for ( const QgsProcessingParameterDefinition *def : mParameters )
519 {
520 if ( def->isDestination() )
521 result << def;
522 }
523 return result;
524}
525
527{
528 for ( const QgsProcessingOutputDefinition *def : mOutputs )
529 {
530 if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
531 return def;
532 }
533 return nullptr;
534}
535
537{
538 for ( const QgsProcessingOutputDefinition *def : mOutputs )
539 {
540 if ( def->type() == "outputHtml"_L1 )
541 return true;
542 }
543 return false;
544}
545
547 const QString &, const QVariantMap &, QgsProcessingContext &, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> &
548) const
549{
550 return VectorProperties();
551}
552
553QVariantMap QgsProcessingAlgorithm::run( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok, const QVariantMap &configuration, bool catchExceptions ) const
554{
555 std::unique_ptr< QgsProcessingAlgorithm > alg( create( configuration ) );
556 if ( ok )
557 *ok = false;
558
559 bool res = alg->prepare( parameters, context, feedback );
560 if ( !res )
561 return QVariantMap();
562
563 QVariantMap runRes;
564 bool success = false;
565 try
566 {
567 runRes = alg->runPrepared( parameters, context, feedback );
568 success = true;
569 }
570 catch ( QgsProcessingException &e )
571 {
572 if ( !catchExceptions )
573 {
574 alg->postProcess( context, feedback, false );
575 throw e;
576 }
577
578 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
579 feedback->reportError( e.what() );
580 }
581
582 if ( ok )
583 *ok = success;
584
585 QVariantMap ppRes = alg->postProcess( context, feedback, success );
586 if ( !ppRes.isEmpty() )
587 return ppRes;
588 else
589 return runRes;
590}
591
592bool QgsProcessingAlgorithm::prepare( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
593{
594 // cppcheck-suppress assertWithSideEffect
595 Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::prepare", "prepare() must be called from the same thread as context was created in" );
596 Q_ASSERT_X( !mHasPrepared, "QgsProcessingAlgorithm::prepare", "prepare() has already been called for the algorithm instance" );
597 try
598 {
599 mHasPrepared = prepareAlgorithm( parameters, context, feedback );
600 return mHasPrepared;
601 }
602 catch ( QgsProcessingException &e )
603 {
604 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
605 feedback->reportError( e.what() );
606 return false;
607 }
608}
609
610QVariantMap QgsProcessingAlgorithm::runPrepared( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
611{
612 Q_ASSERT_X( mHasPrepared, "QgsProcessingAlgorithm::runPrepared", u"prepare() was not called for the algorithm instance %1"_s.arg( name() ).toLatin1() );
613 Q_ASSERT_X( !mHasExecuted, "QgsProcessingAlgorithm::runPrepared", "runPrepared() was already called for this algorithm instance" );
614
615 // Hey kids, let's all be thread safe! It's the fun thing to do!
616 //
617 // First, let's see if we're going to run into issues.
618 QgsProcessingContext *runContext = nullptr;
619 if ( context.thread() == QThread::currentThread() )
620 {
621 // OH. No issues. Seems you're running everything in the same thread, so go about your business. Sorry about
622 // the intrusion, we're just making sure everything's nice and safe here. We like to keep a clean and tidy neighbourhood,
623 // you know, for the kids and dogs and all.
624 runContext = &context;
625 }
626 else
627 {
628 // HA! I knew things looked a bit suspicious - seems you're running this algorithm in a different thread
629 // from that which the passed context has an affinity for. That's fine and all, but we need to make sure
630 // we proceed safely...
631
632 // So first we create a temporary local context with affinity for the current thread
633 mLocalContext = std::make_unique<QgsProcessingContext>();
634 // copy across everything we can safely do from the passed context
635 mLocalContext->copyThreadSafeSettings( context );
636
637 // and we'll run the actual algorithm processing using the local thread safe context
638 runContext = mLocalContext.get();
639 }
640
641 std::unique_ptr< QgsProcessingModelInitialRunConfig > modelConfig = context.takeModelInitialRunConfig();
642 if ( modelConfig )
643 {
644 std::unique_ptr< QgsMapLayerStore > modelPreviousLayerStore = modelConfig->takePreviousLayerStore();
645 if ( modelPreviousLayerStore )
646 {
647 // move layers from previous layer store to context's temporary layer store, in a thread-safe way
648 Q_ASSERT_X( !modelPreviousLayerStore->thread(), "QgsProcessingAlgorithm::runPrepared", "QgsProcessingModelConfig::modelPreviousLayerStore must have been pushed to a nullptr thread" );
649 modelPreviousLayerStore->moveToThread( QThread::currentThread() );
650 runContext->temporaryLayerStore()->transferLayersFromStore( modelPreviousLayerStore.get() );
651 }
652 runContext->setModelInitialRunConfig( std::move( modelConfig ) );
653 }
654
655 mHasExecuted = true;
656 try
657 {
658 QVariantMap runResults = processAlgorithm( parameters, *runContext, feedback );
659
660 if ( mLocalContext )
661 {
662 // ok, time to clean things up. We need to push the temporary context back into
663 // the thread that the passed context is associated with (we can only push from the
664 // current thread, so we HAVE to do this here)
665 mLocalContext->pushToThread( context.thread() );
666 }
667 return runResults;
668 }
669 catch ( QgsProcessingException & )
670 {
671 if ( mLocalContext )
672 {
673 // see above!
674 mLocalContext->pushToThread( context.thread() );
675 }
676 //rethrow
677 throw;
678 }
679}
680
682{
683 // cppcheck-suppress assertWithSideEffect
684 Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::postProcess", "postProcess() must be called from the same thread the context was created in" );
685 Q_ASSERT_X( mHasExecuted, "QgsProcessingAlgorithm::postProcess", u"algorithm instance %1 was not executed"_s.arg( name() ).toLatin1() );
686 Q_ASSERT_X( !mHasPostProcessed, "QgsProcessingAlgorithm::postProcess", "postProcess() was already called for this algorithm instance" );
687
688 if ( mLocalContext )
689 {
690 // algorithm was processed using a temporary thread safe context. So now we need
691 // to take the results from that temporary context, and smash them into the passed
692 // context
693 context.takeResultsFrom( *mLocalContext );
694 // now get lost, we don't need you anymore
695 mLocalContext.reset();
696 }
697
698 mHasPostProcessed = true;
699 if ( runResult )
700 {
701 try
702 {
703 return postProcessAlgorithm( context, feedback );
704 }
705 catch ( QgsProcessingException &e )
706 {
707 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
708 feedback->reportError( e.what() );
709 return QVariantMap();
710 }
711 }
712 else
713 {
714 return QVariantMap();
715 }
716}
717
718QString QgsProcessingAlgorithm::parameterAsString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
719{
721}
722
723QString QgsProcessingAlgorithm::parameterAsExpression( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
724{
726}
727
728double QgsProcessingAlgorithm::parameterAsDouble( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
729{
731}
732
733int QgsProcessingAlgorithm::parameterAsInt( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
734{
735 return QgsProcessingParameters::parameterAsInt( parameterDefinition( name ), parameters, context );
736}
737
738QList<int> QgsProcessingAlgorithm::parameterAsInts( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
739{
740 return QgsProcessingParameters::parameterAsInts( parameterDefinition( name ), parameters, context );
741}
742
743int QgsProcessingAlgorithm::parameterAsEnum( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
744{
745 return QgsProcessingParameters::parameterAsEnum( parameterDefinition( name ), parameters, context );
746}
747
748QList<int> QgsProcessingAlgorithm::parameterAsEnums( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
749{
751}
752
753QString QgsProcessingAlgorithm::parameterAsEnumString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
754{
756}
757
758QStringList QgsProcessingAlgorithm::parameterAsEnumStrings( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
759{
761}
762
763bool QgsProcessingAlgorithm::parameterAsBool( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
764{
765 return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
766}
767
768bool QgsProcessingAlgorithm::parameterAsBoolean( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
769{
770 return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
771}
772
774 const QVariantMap &parameters,
775 const QString &name,
776 QgsProcessingContext &context,
777 QString &destinationIdentifier,
778 const QgsFields &fields,
779 Qgis::WkbType geometryType,
782 const QVariantMap &createOptions,
783 const QStringList &datasourceOptions,
784 const QStringList &layerOptions
785) const
786{
787 if ( !parameterDefinition( name ) )
788 throw QgsProcessingException( QObject::tr( "No parameter definition for the sink '%1'" ).arg( name ) );
789
790 return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
791}
792
793QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
794{
796}
797
799 const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback
800) const
801{
802 return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback );
803}
804
806 const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName
807) const
808{
809 return QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback, layerName );
810}
811
812QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
813{
815}
816
817QgsRasterLayer *QgsProcessingAlgorithm::parameterAsRasterLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
818{
820}
821
822QgsMeshLayer *QgsProcessingAlgorithm::parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
823{
825}
826
827QString QgsProcessingAlgorithm::parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
828{
830}
831
832QString QgsProcessingAlgorithm::parameterAsOutputFormat( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
833{
835}
836
837QString QgsProcessingAlgorithm::parameterAsOutputRasterFormat( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
838{
839 QString outputFormat = parameterAsOutputFormat( parameters, name, context );
840 if ( outputFormat.isEmpty() )
841 {
843 QVariant val;
844 if ( definition )
845 {
846 val = parameters.value( definition->name() );
847 }
848 QString outputFile = QgsProcessingParameters::parameterAsOutputLayer( definition, val, context, /* testOnly = */ true );
849 if ( !outputFile.isEmpty() )
850 {
851 const QFileInfo fi( outputFile );
852 outputFormat = QgsRasterFileWriter::driverForExtension( fi.suffix() );
853 }
854 }
855 return outputFormat;
856}
857
858QString QgsProcessingAlgorithm::parameterAsFileOutput( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
859{
861}
862
863QgsVectorLayer *QgsProcessingAlgorithm::parameterAsVectorLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
864{
866}
867
868QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
869{
870 return QgsProcessingParameters::parameterAsCrs( parameterDefinition( name ), parameters, context );
871}
872
873QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsExtentCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
874{
876}
877
878QgsRectangle QgsProcessingAlgorithm::parameterAsExtent( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
879{
880 return QgsProcessingParameters::parameterAsExtent( parameterDefinition( name ), parameters, context, crs );
881}
882
883QgsGeometry QgsProcessingAlgorithm::parameterAsExtentGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
884{
886}
887
888QgsPointXY QgsProcessingAlgorithm::parameterAsPoint( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
889{
890 return QgsProcessingParameters::parameterAsPoint( parameterDefinition( name ), parameters, context, crs );
891}
892
893QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsPointCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
894{
896}
897
898QgsGeometry QgsProcessingAlgorithm::parameterAsGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
899{
900 return QgsProcessingParameters::parameterAsGeometry( parameterDefinition( name ), parameters, context, crs );
901}
902
903QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsGeometryCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
904{
906}
907
908QString QgsProcessingAlgorithm::parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
909{
910 return QgsProcessingParameters::parameterAsFile( parameterDefinition( name ), parameters, context );
911}
912
913QVariantList QgsProcessingAlgorithm::parameterAsMatrix( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
914{
916}
917
918QList<QgsMapLayer *> QgsProcessingAlgorithm::parameterAsLayerList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags ) const
919{
921}
922
923QStringList QgsProcessingAlgorithm::parameterAsFileList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
924{
926}
927
928QList<double> QgsProcessingAlgorithm::parameterAsRange( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
929{
931}
932
933QStringList QgsProcessingAlgorithm::parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
934{
936}
937
938QStringList QgsProcessingAlgorithm::parameterAsStrings( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
939{
941}
942
943QgsPrintLayout *QgsProcessingAlgorithm::parameterAsLayout( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
944{
946}
947
948QgsLayoutItem *QgsProcessingAlgorithm::parameterAsLayoutItem( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsPrintLayout *layout )
949{
950 return QgsProcessingParameters::parameterAsLayoutItem( parameterDefinition( name ), parameters, context, layout );
951}
952
953QColor QgsProcessingAlgorithm::parameterAsColor( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
954{
956}
957
958QString QgsProcessingAlgorithm::parameterAsConnectionName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
959{
961}
962
963QDateTime QgsProcessingAlgorithm::parameterAsDateTime( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
964{
966}
967
968QString QgsProcessingAlgorithm::parameterAsSchema( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
969{
971}
972
973QString QgsProcessingAlgorithm::parameterAsDatabaseTableName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
974{
976}
977
982
983QgsAnnotationLayer *QgsProcessingAlgorithm::parameterAsAnnotationLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
984{
986}
987
988QString QgsProcessingAlgorithm::invalidSourceError( const QVariantMap &parameters, const QString &name )
989{
990 if ( !parameters.contains( name ) )
991 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
992 else
993 {
994 QVariant var = parameters.value( name );
995 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
996 {
997 QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
998 var = fromVar.source;
999 }
1000 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1001 {
1002 QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1003 var = fromVar.sink;
1004 }
1005 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1006 {
1007 QgsProperty p = var.value< QgsProperty >();
1009 {
1010 var = p.staticValue();
1011 }
1012 }
1013 if ( !var.toString().isEmpty() )
1014 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
1015 else
1016 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
1017 }
1018}
1019
1020QString QgsProcessingAlgorithm::invalidRasterError( const QVariantMap &parameters, const QString &name )
1021{
1022 if ( !parameters.contains( name ) )
1023 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
1024 else
1025 {
1026 QVariant var = parameters.value( name );
1027 if ( var.userType() == qMetaTypeId<QgsProcessingRasterLayerDefinition>() )
1028 {
1029 QgsProcessingRasterLayerDefinition fromVar = qvariant_cast<QgsProcessingRasterLayerDefinition>( var );
1030 var = fromVar.source;
1031 }
1032 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1033 {
1034 QgsProperty p = var.value< QgsProperty >();
1036 {
1037 var = p.staticValue();
1038 }
1039 }
1040 if ( !var.toString().isEmpty() )
1041 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
1042 else
1043 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
1044 }
1045}
1046
1047QString QgsProcessingAlgorithm::invalidSinkError( const QVariantMap &parameters, const QString &name )
1048{
1049 if ( !parameters.contains( name ) )
1050 return QObject::tr( "Could not create destination layer for %1: no value specified for parameter" ).arg( name );
1051 else
1052 {
1053 QVariant var = parameters.value( name );
1054 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
1055 {
1056 QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
1057 var = fromVar.sink;
1058 }
1059 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1060 {
1061 QgsProperty p = var.value< QgsProperty >();
1063 {
1064 var = p.staticValue();
1065 }
1066 }
1067 if ( !var.toString().isEmpty() )
1068 return QObject::tr( "Could not create destination layer for %1: %2" ).arg( name, var.toString() );
1069 else
1070 return QObject::tr( "Could not create destination layer for %1: invalid value" ).arg( name );
1071 }
1072}
1073
1074QString QgsProcessingAlgorithm::invalidPointCloudError( const QVariantMap &parameters, const QString &name )
1075{
1076 if ( !parameters.contains( name ) )
1077 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
1078 else
1079 {
1080 QVariant var = parameters.value( name );
1081 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1082 {
1083 QgsProperty p = var.value< QgsProperty >();
1085 {
1086 var = p.staticValue();
1087 }
1088 }
1089 if ( !var.toString().isEmpty() )
1090 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
1091 else
1092 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
1093 }
1094}
1095
1096QString QgsProcessingAlgorithm::writeFeatureError( QgsFeatureSink *sink, const QVariantMap &parameters, const QString &name )
1097{
1098 Q_UNUSED( sink );
1099 Q_UNUSED( parameters );
1100 const QString lastError = sink->lastError();
1101 if ( !lastError.isEmpty() )
1102 {
1103 if ( !name.isEmpty() )
1104 return QObject::tr( "Could not write feature into %1: %2" ).arg( name, lastError );
1105 else
1106 return QObject::tr( "Could not write feature: %1" ).arg( lastError );
1107 }
1108 else
1109 {
1110 if ( !name.isEmpty() )
1111 return QObject::tr( "Could not write feature into %1" ).arg( name );
1112 else
1113 return QObject::tr( "Could not write feature" );
1114 }
1115}
1116
1118{
1119 Q_UNUSED( layer )
1120 return false;
1121}
1122
1123
1124bool QgsProcessingAlgorithm::createAutoOutputForParameter( const QgsProcessingParameterDefinition *parameter )
1125{
1126 if ( !parameter->isDestination() )
1127 return true; // nothing created, but nothing went wrong - so return true
1128
1129 const QgsProcessingDestinationParameter *dest = static_cast< const QgsProcessingDestinationParameter * >( parameter );
1131 if ( !output )
1132 return true; // nothing created - but nothing went wrong - so return true
1133 output->setAutoCreated( true );
1134
1135 if ( !addOutput( output ) )
1136 {
1137 // couldn't add output - probably a duplicate name
1138 return false;
1139 }
1140 else
1141 {
1142 return true;
1143 }
1144}
1145
1146
1147//
1148// QgsProcessingFeatureBasedAlgorithm
1149//
1150
1157
1159{
1161 initParameters( config );
1162 addParameter( new QgsProcessingParameterFeatureSink( u"OUTPUT"_s, outputName(), outputLayerType(), QVariant(), false, true, true ) );
1163}
1164
1166{
1167 return u"INPUT"_s;
1168}
1169
1171{
1172 return QObject::tr( "Input layer" );
1173}
1174
1176{
1177 return QList<int>();
1178}
1179
1184
1189
1194
1196{
1197 return inputWkbType;
1198}
1199
1201{
1202 return inputFields;
1203}
1204
1209
1212
1214{
1215 if ( mSource )
1216 return mSource->sourceCrs();
1217 else
1219}
1220
1221QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
1222{
1223 prepareSource( parameters, context );
1224 QString dest;
1225 std::unique_ptr< QgsFeatureSink > sink(
1226 parameterAsSink( parameters, u"OUTPUT"_s, context, dest, outputFields( mSource->fields() ), outputWkbType( mSource->wkbType() ), outputCrs( mSource->sourceCrs() ), sinkFlags() )
1227 );
1228 if ( !sink )
1229 throw QgsProcessingException( invalidSinkError( parameters, u"OUTPUT"_s ) );
1230
1231 // prepare expression context for feature iteration
1232 QgsExpressionContext prevContext = context.expressionContext();
1233 QgsExpressionContext algContext = prevContext;
1234
1235 algContext.appendScopes( createExpressionContext( parameters, context, mSource.get() ).takeScopes() );
1236 context.setExpressionContext( algContext );
1237
1238 long count = mSource->featureCount();
1239
1240 QgsFeature f;
1241 QgsFeatureIterator it = mSource->getFeatures( request(), sourceFlags() );
1242
1243 double step = count > 0 ? 100.0 / count : 1;
1244 int current = 0;
1245 while ( it.nextFeature( f ) )
1246 {
1247 if ( feedback->isCanceled() )
1248 {
1249 break;
1250 }
1251
1252 context.expressionContext().setFeature( f );
1253 const QgsFeatureList transformed = processFeature( f, context, feedback );
1254 for ( QgsFeature transformedFeature : transformed )
1255 {
1256 if ( !sink->addFeature( transformedFeature, QgsFeatureSink::FastInsert ) )
1257 {
1258 throw QgsProcessingException( writeFeatureError( sink.get(), parameters, QString() ) );
1259 }
1260 }
1261
1262 feedback->setProgress( current * step );
1263 current++;
1264 }
1265
1266 sink->finalize();
1267
1268 mSource.reset();
1269
1270 // probably not necessary - context's aren't usually recycled, but can't hurt
1271 context.setExpressionContext( prevContext );
1272
1273 QVariantMap outputs;
1274 outputs.insert( u"OUTPUT"_s, dest );
1275 return outputs;
1276}
1277
1282
1284{
1285 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
1286 if ( !layer )
1287 return false;
1288
1289 Qgis::GeometryType inPlaceGeometryType = layer->geometryType();
1290 if ( !inputLayerTypes().empty() &&
1291 !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::Vector ) ) &&
1292 !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry ) ) &&
1293 ( ( inPlaceGeometryType == Qgis::GeometryType::Polygon && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon ) ) ) ||
1294 ( inPlaceGeometryType == Qgis::GeometryType::Line && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorLine ) ) ) ||
1295 ( inPlaceGeometryType == Qgis::GeometryType::Point && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorPoint ) ) ) ) )
1296 return false;
1297
1299 if ( inPlaceGeometryType == Qgis::GeometryType::Point )
1300 type = Qgis::WkbType::Point;
1301 else if ( inPlaceGeometryType == Qgis::GeometryType::Line )
1303 else if ( inPlaceGeometryType == Qgis::GeometryType::Polygon )
1305
1306 if ( QgsWkbTypes::geometryType( outputWkbType( type ) ) != inPlaceGeometryType )
1307 return false;
1308
1309 return true;
1310}
1311
1313{
1314 if ( !mSource )
1315 {
1316 mSource.reset( parameterAsSource( parameters, inputParameterName(), context ) );
1317 if ( !mSource )
1319 }
1320}
1321
1322
1324 const QString &sink, const QVariantMap &parameters, QgsProcessingContext &context, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> &sourceProperties
1325) const
1326{
1328 if ( sink == "OUTPUT"_L1 )
1329 {
1330 if ( sourceProperties.value( u"INPUT"_s ).availability == Qgis::ProcessingPropertyAvailability::Available )
1331 {
1332 const VectorProperties inputProps = sourceProperties.value( u"INPUT"_s );
1333 result.fields = outputFields( inputProps.fields );
1334 result.crs = outputCrs( inputProps.crs );
1335 result.wkbType = outputWkbType( inputProps.wkbType );
1337 return result;
1338 }
1339 else
1340 {
1341 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, u"INPUT"_s, context ) );
1342 if ( source )
1343 {
1344 result.fields = outputFields( source->fields() );
1345 result.crs = outputCrs( source->sourceCrs() );
1346 result.wkbType = outputWkbType( source->wkbType() );
1348 return result;
1349 }
1350 }
1351 }
1352 return result;
1353}
ProcessingSourceType
Processing data source types.
Definition qgis.h:3645
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition qgis.h:3653
@ VectorAnyGeometry
Any vector layer with geometry.
Definition qgis.h:3647
@ VectorPoint
Vector point layers.
Definition qgis.h:3648
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3650
@ VectorLine
Vector line layers.
Definition qgis.h:3649
ProcessingMode
Types of modes which Processing widgets can be created for.
Definition qgis.h:3786
@ Critical
Critical/error message.
Definition qgis.h:163
@ Static
Static property.
Definition qgis.h:710
@ Available
Properties are available.
Definition qgis.h:3759
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:3724
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
Definition qgis.h:3745
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:3700
@ SupportsInPlaceEdits
Algorithm supports in-place editing.
Definition qgis.h:3705
@ RequiresMatchingCrs
Algorithm requires that all input layers have matching coordinate reference systems.
Definition qgis.h:3702
@ CanCancel
Algorithm can be canceled.
Definition qgis.h:3701
@ RequiresProject
The algorithm requires that a valid QgsProject is available from the processing context in order to e...
Definition qgis.h:3711
@ Hidden
Parameter is hidden and should not be shown to users.
Definition qgis.h:3881
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Definition qgis.h:3839
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: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(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
Represents a map layer supporting display of point clouds.
Represents a 2D point.
Definition qgspointxy.h:62
Print layout, a QgsLayout subclass for static or atlas-based layouts.
QString parameterAsCompatibleSourceLayerPath(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr) const
Evaluates the parameter with matching name to a source vector layer file path of compatible format.
QString parameterAsConnectionName(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a connection name string.
const QgsProcessingOutputDefinition * outputDefinition(const QString &name) const
Returns a matching output by name.
QString parameterAsCompatibleSourceLayerPathAndLayerName(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr) const
Evaluates the parameter with matching name to a source vector layer file path and layer name of compa...
QStringList parameterAsStrings(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of strings (e.g.
QgsGeometry parameterAsExtentGeometry(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Evaluates the parameter with matching name to a rectangular extent, and returns a geometry covering t...
virtual QgsProcessingAlgorithm * createInstance() const =0
Creates a new instance of the algorithm class.
QgsMapLayer * parameterAsLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a map layer.
QgsRasterLayer * parameterAsRasterLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a raster layer.
virtual bool prepareAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm to run using the specified parameters.
int parameterAsInt(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static integer value.
virtual QString helpUrl() const
Returns a url pointing to the algorithm's help page.
virtual QVariantMap autogenerateParameterValues(const QVariantMap &existingParameters, const QString &changedParameter, Qgis::ProcessingMode mode) const
Returns a map of default auto-generated parameters to fill in, based on existing parameters.
int parameterAsEnum(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a enum value.
void setProvider(QgsProcessingProvider *provider)
Associates this algorithm with its provider.
virtual QIcon icon() const
Returns an icon for the algorithm.
virtual QString shortHelpString() const
Returns a localised short helper string for the algorithm.
QString parameterAsOutputRasterFormat(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a output format.
virtual bool validateInputCrs(const QVariantMap &parameters, QgsProcessingContext &context) const
Checks whether the coordinate reference systems for the specified set of parameters are valid for the...
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
virtual QString shortDescription() const
Returns an optional translated short description of the algorithm.
Q_DECL_DEPRECATED QStringList parameterAsFields(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of fields.
QgsProcessingFeatureSource * parameterAsSource(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a feature source.
int countVisibleParameters() const
Returns the number of visible (non-hidden) parameters defined by this algorithm.
QString parameterAsFile(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a file/folder name.
QString id() const
Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and th...
virtual QVariantMap preprocessParameters(const QVariantMap &parameters)
Pre-processes a set of parameters, allowing the algorithm to clean their values.
static QString invalidRasterError(const QVariantMap &parameters, const QString &name)
Returns a user-friendly string to use as an error when a raster layer input could not be loaded.
QgsVectorLayer * parameterAsVectorLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a vector layer.
static QString writeFeatureError(QgsFeatureSink *sink, const QVariantMap &parameters, const QString &name)
Returns a user-friendly string to use as an error when a feature cannot be written into a sink.
QStringList parameterAsFileList(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of files (for QgsProcessingParameterMultipleLaye...
QVariantMap postProcess(QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool runResult=true)
Should be called in the main thread following the completion of runPrepared().
bool prepare(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm for execution.
QString parameterAsDatabaseTableName(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a database table name string.
QString parameterAsExpression(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to an expression.
void removeParameter(const QString &name)
Removes the parameter with matching name from the algorithm, and deletes any existing definition.
QList< QgsMapLayer * > parameterAsLayerList(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags=QgsProcessing::LayerOptionsFlags()) const
Evaluates the parameter with matching name to a list of map layers.
QgsAnnotationLayer * parameterAsAnnotationLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to an annotation layer.
bool addParameter(QgsProcessingParameterDefinition *parameterDefinition, bool createOutput=true)
Adds a parameter definition to the algorithm.
QgsGeometry parameterAsGeometry(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Evaluates the parameter with matching name to a geometry.
virtual QString asQgisProcessCommand(const QVariantMap &parameters, QgsProcessingContext &context, bool &ok) const
Returns a command string which will execute the algorithm using the specified parameters via the comm...
bool parameterAsBoolean(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static boolean value.
QList< double > parameterAsRange(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a range of values.
QVariantList parameterAsMatrix(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a matrix/table of values.
QString parameterAsOutputFormat(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a output format.
virtual 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.