QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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#include "qgsapplication.h"
23#include "qgsrectangle.h"
25#include "qgsprocessingutils.h"
26#include "qgsexception.h"
27#include "qgsmessagelog.h"
28#include "qgsvectorlayer.h"
30#include "qgsmeshlayer.h"
31#include "qgspointcloudlayer.h"
33#include <QRegularExpression>
34#include <QRegularExpressionMatch>
35
37{
38 qDeleteAll( mParameters );
39 qDeleteAll( mOutputs );
40}
41
42QgsProcessingAlgorithm *QgsProcessingAlgorithm::create( const QVariantMap &configuration ) const
43{
44 std::unique_ptr< QgsProcessingAlgorithm > creation( createInstance() );
45 if ( ! creation )
46 throw QgsProcessingException( QObject::tr( "Error creating algorithm from createInstance()" ) );
47 creation->setProvider( provider() );
48 creation->initAlgorithm( configuration );
49 return creation.release();
50}
51
53{
54 if ( mProvider )
55 return QStringLiteral( "%1:%2" ).arg( mProvider->id(), name() );
56 else
57 return name();
58}
59
61{
62 return QString();
63}
64
66{
67 return QString();
68}
69
71{
72 return QString();
73}
74
76{
77 return QString();
78}
79
84
86{
87 return QgsApplication::getThemeIcon( "/processingAlgorithm.svg" );
88}
89
91{
92 return QgsApplication::iconPath( QStringLiteral( "processingAlgorithm.svg" ) );
93}
94
99
101{
102 return true;
103}
104
105bool QgsProcessingAlgorithm::checkParameterValues( const QVariantMap &parameters, QgsProcessingContext &context, QString *message ) const
106{
107 for ( const QgsProcessingParameterDefinition *def : mParameters )
108 {
109 if ( !def->checkValueIsAcceptable( parameters.value( def->name() ), &context ) )
110 {
111 if ( message )
112 {
113 // TODO QGIS 4 - move the message handling to the parameter subclasses (but this
114 // requires a change in signature for the virtual checkValueIsAcceptable method)
116 *message = invalidSourceError( parameters, def->name() );
117 else if ( def->type() == QgsProcessingParameterFeatureSink::typeName() )
118 *message = invalidSinkError( parameters, def->name() );
119 else if ( def->type() == QgsProcessingParameterRasterLayer::typeName() )
120 *message = invalidRasterError( parameters, def->name() );
121 else if ( def->type() == QgsProcessingParameterPointCloudLayer::typeName() )
122 *message = invalidPointCloudError( parameters, def->name() );
123 else
124 *message = QObject::tr( "Incorrect parameter value for %1" ).arg( def->name() );
125 }
126 return false;
127 }
128 }
129 return true;
130}
131
132QVariantMap QgsProcessingAlgorithm::preprocessParameters( const QVariantMap &parameters )
133{
134 return parameters;
135}
136
138{
139 return mProvider;
140}
141
143{
144 mProvider = provider;
145
146 if ( mProvider && !mProvider->supportsNonFileBasedOutput() )
147 {
148 // need to update all destination parameters to turn off non file based outputs
149 for ( const QgsProcessingParameterDefinition *definition : std::as_const( mParameters ) )
150 {
151 if ( definition->isDestination() )
152 {
153 const QgsProcessingDestinationParameter *destParam = static_cast< const QgsProcessingDestinationParameter *>( definition );
154 const_cast< QgsProcessingDestinationParameter *>( destParam )->setSupportsNonFileBasedOutput( false );
155 }
156 }
157 }
158}
159
161{
162 return nullptr;
163}
164
166 QgsProcessingContext &context, QgsProcessingFeatureSource *source ) const
167{
168 // start with context's expression context
170
171 // If there's a source capable of generating a context scope, use it
172 if ( source )
173 {
175 if ( scope )
176 c << scope;
177 }
178 else if ( c.scopeCount() == 0 )
179 {
180 //empty scope, populate with initial scopes
183 }
184
185 c << QgsExpressionContextUtils::processingAlgorithmScope( this, parameters, context );
186 return c;
187}
188
189bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, QgsProcessingContext &context ) const
190{
192 {
193 // I'm a well behaved algorithm - I take work AWAY from users!
194 return true;
195 }
196
197 bool foundCrs = false;
199 for ( const QgsProcessingParameterDefinition *def : mParameters )
200 {
202 {
203 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( def, parameters, context );
204 if ( layer )
205 {
206 if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
207 {
208 return false;
209 }
210 else if ( !foundCrs && layer->crs().isValid() )
211 {
212 foundCrs = true;
213 crs = layer->crs();
214 }
215 }
216 }
217 else if ( def->type() == QgsProcessingParameterFeatureSource::typeName() )
218 {
219 std::unique_ptr< QgsFeatureSource > source( QgsProcessingParameters::parameterAsSource( def, parameters, context ) );
220 if ( source )
221 {
222 if ( foundCrs && source->sourceCrs().isValid() && crs != source->sourceCrs() )
223 {
224 return false;
225 }
226 else if ( !foundCrs && source->sourceCrs().isValid() )
227 {
228 foundCrs = true;
229 crs = source->sourceCrs();
230 }
231 }
232 }
233 else if ( def->type() == QgsProcessingParameterMultipleLayers::typeName() )
234 {
235 QList< QgsMapLayer *> layers = QgsProcessingParameters::parameterAsLayerList( def, parameters, context );
236 const auto constLayers = layers;
237 for ( QgsMapLayer *layer : constLayers )
238 {
239 if ( !layer )
240 continue;
241
242 if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
243 {
244 return false;
245 }
246 else if ( !foundCrs && layer->crs().isValid() )
247 {
248 foundCrs = true;
249 crs = layer->crs();
250 }
251 }
252 }
253 else if ( def->type() == QgsProcessingParameterExtent::typeName() )
254 {
256 if ( foundCrs && extentCrs.isValid() && crs != extentCrs )
257 {
258 return false;
259 }
260 else if ( !foundCrs && extentCrs.isValid() )
261 {
262 foundCrs = true;
263 crs = extentCrs;
264 }
265 }
266 else if ( def->type() == QgsProcessingParameterPoint::typeName() )
267 {
269 if ( foundCrs && pointCrs.isValid() && crs != pointCrs )
270 {
271 return false;
272 }
273 else if ( !foundCrs && pointCrs.isValid() )
274 {
275 foundCrs = true;
276 crs = pointCrs;
277 }
278 }
279 else if ( def->type() == QgsProcessingParameterGeometry::typeName() )
280 {
282 if ( foundCrs && geomCrs.isValid() && crs != geomCrs )
283 {
284 return false;
285 }
286 else if ( !foundCrs && geomCrs.isValid() )
287 {
288 foundCrs = true;
289 crs = geomCrs;
290 }
291 }
292
293 }
294 return true;
295}
296
297QString QgsProcessingAlgorithm::asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const
298{
299 QString s = QStringLiteral( "processing.run(\"%1\"," ).arg( id() );
300
301 QStringList parts;
302 for ( const QgsProcessingParameterDefinition *def : mParameters )
303 {
304 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
305 continue;
306
307 if ( !parameters.contains( def->name() ) )
308 continue;
309
310 parts << QStringLiteral( "'%1':%2" ).arg( def->name(), def->valueAsPythonString( parameters.value( def->name() ), context ) );
311 }
312
313 s += QStringLiteral( " {%1})" ).arg( parts.join( ',' ) );
314 return s;
315}
316
317QString QgsProcessingAlgorithm::asQgisProcessCommand( const QVariantMap &parameters, QgsProcessingContext &context, bool &ok ) const
318{
319 ok = true;
320 QStringList parts;
321 parts.append( QStringLiteral( "qgis_process" ) );
322 parts.append( QStringLiteral( "run" ) );
323 parts.append( id() );
324
326 // we only include the project path argument if a project is actually required by the algorithm
329
330 parts.append( context.asQgisProcessArguments( argumentFlags ) );
331
332 auto escapeIfNeeded = []( const QString & input ) -> QString
333 {
334 // play it safe and escape everything UNLESS it's purely alphanumeric characters (and a very select scattering of other common characters!)
335 const thread_local QRegularExpression nonAlphaNumericRx( QStringLiteral( "[^a-zA-Z0-9.\\-/_]" ) );
336 if ( nonAlphaNumericRx.match( input ).hasMatch() )
337 {
338 QString escaped = input;
339 escaped.replace( '\'', QLatin1String( "'\\''" ) );
340 return QStringLiteral( "'%1'" ).arg( escaped );
341 }
342 else
343 {
344 return input;
345 }
346 };
347
348 for ( const QgsProcessingParameterDefinition *def : mParameters )
349 {
350 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
351 continue;
352
353 if ( !parameters.contains( def->name() ) )
354 continue;
355
356 const QStringList partValues = def->valueAsStringList( parameters.value( def->name() ), context, ok );
357 if ( !ok )
358 return QString();
359
360 for ( const QString &partValue : partValues )
361 {
362 parts << QStringLiteral( "--%1=%2" ).arg( def->name(), escapeIfNeeded( partValue ) );
363 }
364 }
365
366 return parts.join( ' ' );
367}
368
369QVariantMap QgsProcessingAlgorithm::asMap( const QVariantMap &parameters, QgsProcessingContext &context ) const
370{
371 QVariantMap properties = context.exportToMap();
372
373 // we only include the project path argument if a project is actually required by the algorithm
375 properties.remove( QStringLiteral( "project_path" ) );
376
377 QVariantMap paramValues;
378 for ( const QgsProcessingParameterDefinition *def : mParameters )
379 {
380 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
381 continue;
382
383 if ( !parameters.contains( def->name() ) )
384 continue;
385
386 paramValues.insert( def->name(), def->valueAsJsonObject( parameters.value( def->name() ), context ) );
387 }
388
389 properties.insert( QStringLiteral( "inputs" ), paramValues );
390 return properties;
391}
392
394{
395 if ( !definition )
396 return false;
397
398 // check for duplicate named parameters
400 if ( existingDef && existingDef->name() == definition->name() ) // parameterDefinition is case-insensitive, but we DO allow case-different duplicate names
401 {
402 QgsMessageLog::logMessage( QObject::tr( "Duplicate parameter %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
403 delete definition;
404 return false;
405 }
406
407 if ( definition->isDestination() && mProvider )
408 {
409 QgsProcessingDestinationParameter *destParam = static_cast< QgsProcessingDestinationParameter *>( definition );
410 if ( !mProvider->supportsNonFileBasedOutput() )
411 destParam->setSupportsNonFileBasedOutput( false );
412 }
413
414 mParameters << definition;
415 definition->mAlgorithm = this;
416
417 if ( createOutput )
418 return createAutoOutputForParameter( definition );
419 else
420 return true;
421}
422
424{
426 if ( def )
427 {
428 delete def;
429 mParameters.removeAll( def );
430
431 // remove output automatically created when adding parameter
433 if ( outputDef && outputDef->autoCreated() )
434 {
435 delete outputDef;
436 mOutputs.removeAll( outputDef );
437 }
438 }
439}
440
442{
443 if ( !definition )
444 return false;
445
446 // check for duplicate named outputs
447 if ( QgsProcessingAlgorithm::outputDefinition( definition->name() ) )
448 {
449 QgsMessageLog::logMessage( QObject::tr( "Duplicate output %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
450 delete definition;
451 return false;
452 }
453
454 mOutputs << definition;
455 return true;
456}
457
459{
460 return true;
461}
462
467
469{
470 // first pass - case sensitive match
471 for ( const QgsProcessingParameterDefinition *def : mParameters )
472 {
473 if ( def->name() == name )
474 return def;
475 }
476
477 // second pass - case insensitive
478 for ( const QgsProcessingParameterDefinition *def : mParameters )
479 {
480 if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
481 return def;
482 }
483 return nullptr;
484}
485
487{
488 int count = 0;
489 for ( const QgsProcessingParameterDefinition *def : mParameters )
490 {
491 if ( !( def->flags() & Qgis::ProcessingParameterFlag::Hidden ) )
492 count++;
493 }
494 return count;
495}
496
498{
500 for ( const QgsProcessingParameterDefinition *def : mParameters )
501 {
502 if ( def->isDestination() )
503 result << def;
504 }
505 return result;
506}
507
509{
510 for ( const QgsProcessingOutputDefinition *def : mOutputs )
511 {
512 if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
513 return def;
514 }
515 return nullptr;
516}
517
519{
520 for ( const QgsProcessingOutputDefinition *def : mOutputs )
521 {
522 if ( def->type() == QLatin1String( "outputHtml" ) )
523 return true;
524 }
525 return false;
526}
527
528QgsProcessingAlgorithm::VectorProperties QgsProcessingAlgorithm::sinkProperties( const QString &, const QVariantMap &, QgsProcessingContext &, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> & ) const
529{
530 return VectorProperties();
531}
532
533QVariantMap QgsProcessingAlgorithm::run( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok, const QVariantMap &configuration, bool catchExceptions ) const
534{
535 std::unique_ptr< QgsProcessingAlgorithm > alg( create( configuration ) );
536 if ( ok )
537 *ok = false;
538
539 bool res = alg->prepare( parameters, context, feedback );
540 if ( !res )
541 return QVariantMap();
542
543 QVariantMap runRes;
544 bool success = false;
545 try
546 {
547 runRes = alg->runPrepared( parameters, context, feedback );
548 success = true;
549 }
550 catch ( QgsProcessingException &e )
551 {
552 if ( !catchExceptions )
553 {
554 alg->postProcess( context, feedback, false );
555 throw e;
556 }
557
558 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
559 feedback->reportError( e.what() );
560 }
561
562 if ( ok )
563 *ok = success;
564
565 QVariantMap ppRes = alg->postProcess( context, feedback, success );
566 if ( !ppRes.isEmpty() )
567 return ppRes;
568 else
569 return runRes;
570}
571
572bool QgsProcessingAlgorithm::prepare( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
573{
574 // cppcheck-suppress assertWithSideEffect
575 Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::prepare", "prepare() must be called from the same thread as context was created in" );
576 Q_ASSERT_X( !mHasPrepared, "QgsProcessingAlgorithm::prepare", "prepare() has already been called for the algorithm instance" );
577 try
578 {
579 mHasPrepared = prepareAlgorithm( parameters, context, feedback );
580 return mHasPrepared;
581 }
582 catch ( QgsProcessingException &e )
583 {
584 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
585 feedback->reportError( e.what() );
586 return false;
587 }
588}
589
590QVariantMap QgsProcessingAlgorithm::runPrepared( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
591{
592 Q_ASSERT_X( mHasPrepared, "QgsProcessingAlgorithm::runPrepared", QStringLiteral( "prepare() was not called for the algorithm instance %1" ).arg( name() ).toLatin1() );
593 Q_ASSERT_X( !mHasExecuted, "QgsProcessingAlgorithm::runPrepared", "runPrepared() was already called for this algorithm instance" );
594
595 // Hey kids, let's all be thread safe! It's the fun thing to do!
596 //
597 // First, let's see if we're going to run into issues.
598 QgsProcessingContext *runContext = nullptr;
599 if ( context.thread() == QThread::currentThread() )
600 {
601 // OH. No issues. Seems you're running everything in the same thread, so go about your business. Sorry about
602 // the intrusion, we're just making sure everything's nice and safe here. We like to keep a clean and tidy neighbourhood,
603 // you know, for the kids and dogs and all.
604 runContext = &context;
605 }
606 else
607 {
608 // HA! I knew things looked a bit suspicious - seems you're running this algorithm in a different thread
609 // from that which the passed context has an affinity for. That's fine and all, but we need to make sure
610 // we proceed safely...
611
612 // So first we create a temporary local context with affinity for the current thread
613 mLocalContext.reset( new QgsProcessingContext() );
614 // copy across everything we can safely do from the passed context
615 mLocalContext->copyThreadSafeSettings( context );
616
617 // and we'll run the actual algorithm processing using the local thread safe context
618 runContext = mLocalContext.get();
619 }
620
621 std::unique_ptr< QgsProcessingModelInitialRunConfig > modelConfig = context.takeModelInitialRunConfig();
622 if ( modelConfig )
623 {
624 std::unique_ptr< QgsMapLayerStore > modelPreviousLayerStore = modelConfig->takePreviousLayerStore();
625 if ( modelPreviousLayerStore )
626 {
627 // move layers from previous layer store to context's temporary layer store, in a thread-safe way
628 Q_ASSERT_X( !modelPreviousLayerStore->thread(), "QgsProcessingAlgorithm::runPrepared", "QgsProcessingModelConfig::modelPreviousLayerStore must have been pushed to a nullptr thread" );
629 modelPreviousLayerStore->moveToThread( QThread::currentThread() );
630 runContext->temporaryLayerStore()->transferLayersFromStore( modelPreviousLayerStore.get() );
631 }
632 runContext->setModelInitialRunConfig( std::move( modelConfig ) );
633 }
634
635 mHasExecuted = true;
636 try
637 {
638 QVariantMap runResults = processAlgorithm( parameters, *runContext, feedback );
639
640 if ( mLocalContext )
641 {
642 // ok, time to clean things up. We need to push the temporary context back into
643 // the thread that the passed context is associated with (we can only push from the
644 // current thread, so we HAVE to do this here)
645 mLocalContext->pushToThread( context.thread() );
646 }
647 return runResults;
648 }
649 catch ( QgsProcessingException & )
650 {
651 if ( mLocalContext )
652 {
653 // see above!
654 mLocalContext->pushToThread( context.thread() );
655 }
656 //rethrow
657 throw;
658 }
659}
660
662{
663 // cppcheck-suppress assertWithSideEffect
664 Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::postProcess", "postProcess() must be called from the same thread the context was created in" );
665 Q_ASSERT_X( mHasExecuted, "QgsProcessingAlgorithm::postProcess", QStringLiteral( "algorithm instance %1 was not executed" ).arg( name() ).toLatin1() );
666 Q_ASSERT_X( !mHasPostProcessed, "QgsProcessingAlgorithm::postProcess", "postProcess() was already called for this algorithm instance" );
667
668 if ( mLocalContext )
669 {
670 // algorithm was processed using a temporary thread safe context. So now we need
671 // to take the results from that temporary context, and smash them into the passed
672 // context
673 context.takeResultsFrom( *mLocalContext );
674 // now get lost, we don't need you anymore
675 mLocalContext.reset();
676 }
677
678 mHasPostProcessed = true;
679 if ( runResult )
680 {
681 try
682 {
683 return postProcessAlgorithm( context, feedback );
684 }
685 catch ( QgsProcessingException &e )
686 {
687 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
688 feedback->reportError( e.what() );
689 return QVariantMap();
690 }
691 }
692 else
693 {
694 return QVariantMap();
695 }
696}
697
698QString QgsProcessingAlgorithm::parameterAsString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
699{
701}
702
703QString QgsProcessingAlgorithm::parameterAsExpression( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
704{
706}
707
708double QgsProcessingAlgorithm::parameterAsDouble( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
709{
711}
712
713int QgsProcessingAlgorithm::parameterAsInt( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
714{
715 return QgsProcessingParameters::parameterAsInt( parameterDefinition( name ), parameters, context );
716}
717
718QList<int> QgsProcessingAlgorithm::parameterAsInts( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
719{
720 return QgsProcessingParameters::parameterAsInts( parameterDefinition( name ), parameters, context );
721}
722
723int QgsProcessingAlgorithm::parameterAsEnum( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
724{
725 return QgsProcessingParameters::parameterAsEnum( parameterDefinition( name ), parameters, context );
726}
727
728QList<int> QgsProcessingAlgorithm::parameterAsEnums( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
729{
731}
732
733QString QgsProcessingAlgorithm::parameterAsEnumString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
734{
736}
737
738QStringList QgsProcessingAlgorithm::parameterAsEnumStrings( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
739{
741}
742
743bool QgsProcessingAlgorithm::parameterAsBool( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
744{
745 return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
746}
747
748bool QgsProcessingAlgorithm::parameterAsBoolean( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
749{
750 return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
751}
752
753QgsFeatureSink *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
754{
755 if ( !parameterDefinition( name ) )
756 throw QgsProcessingException( QObject::tr( "No parameter definition for the sink '%1'" ).arg( name ) );
757
758 return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
759}
760
761QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
762{
764}
765
766QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback ) const
767{
768 return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback );
769}
770
771QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPathAndLayerName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName ) const
772{
773 return QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback, layerName );
774}
775
776QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
777{
779}
780
781QgsRasterLayer *QgsProcessingAlgorithm::parameterAsRasterLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
782{
784}
785
786QgsMeshLayer *QgsProcessingAlgorithm::parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
787{
789}
790
791QString QgsProcessingAlgorithm::parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
792{
794}
795
796QString QgsProcessingAlgorithm::parameterAsFileOutput( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
797{
799}
800
801QgsVectorLayer *QgsProcessingAlgorithm::parameterAsVectorLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
802{
804}
805
806QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
807{
808 return QgsProcessingParameters::parameterAsCrs( parameterDefinition( name ), parameters, context );
809}
810
811QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsExtentCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
812{
814}
815
816QgsRectangle QgsProcessingAlgorithm::parameterAsExtent( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
817{
819}
820
821QgsGeometry QgsProcessingAlgorithm::parameterAsExtentGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
822{
824}
825
826QgsPointXY QgsProcessingAlgorithm::parameterAsPoint( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
827{
829}
830
831QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsPointCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
832{
834}
835
836QgsGeometry QgsProcessingAlgorithm::parameterAsGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
837{
839}
840
841QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsGeometryCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
842{
844}
845
846QString QgsProcessingAlgorithm::parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
847{
848 return QgsProcessingParameters::parameterAsFile( parameterDefinition( name ), parameters, context );
849}
850
851QVariantList QgsProcessingAlgorithm::parameterAsMatrix( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
852{
854}
855
856QList<QgsMapLayer *> QgsProcessingAlgorithm::parameterAsLayerList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags ) const
857{
859}
860
861QStringList QgsProcessingAlgorithm::parameterAsFileList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
862{
864}
865
866QList<double> QgsProcessingAlgorithm::parameterAsRange( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
867{
869}
870
871QStringList QgsProcessingAlgorithm::parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
872{
874}
875
876QStringList QgsProcessingAlgorithm::parameterAsStrings( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
877{
879}
880
881QgsPrintLayout *QgsProcessingAlgorithm::parameterAsLayout( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
882{
884}
885
886QgsLayoutItem *QgsProcessingAlgorithm::parameterAsLayoutItem( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsPrintLayout *layout )
887{
888 return QgsProcessingParameters::parameterAsLayoutItem( parameterDefinition( name ), parameters, context, layout );
889}
890
891QColor QgsProcessingAlgorithm::parameterAsColor( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
892{
894}
895
896QString QgsProcessingAlgorithm::parameterAsConnectionName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
897{
899}
900
901QDateTime QgsProcessingAlgorithm::parameterAsDateTime( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
902{
904}
905
906QString QgsProcessingAlgorithm::parameterAsSchema( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
907{
909}
910
911QString QgsProcessingAlgorithm::parameterAsDatabaseTableName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
912{
914}
915
917{
919}
920
921QgsAnnotationLayer *QgsProcessingAlgorithm::parameterAsAnnotationLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
922{
924}
925
926QString QgsProcessingAlgorithm::invalidSourceError( const QVariantMap &parameters, const QString &name )
927{
928 if ( !parameters.contains( name ) )
929 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
930 else
931 {
932 QVariant var = parameters.value( name );
933 if ( var.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
934 {
935 QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
936 var = fromVar.source;
937 }
938 else if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
939 {
940 QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
941 var = fromVar.sink;
942 }
943 if ( var.userType() == qMetaTypeId<QgsProperty>() )
944 {
945 QgsProperty p = var.value< QgsProperty >();
947 {
948 var = p.staticValue();
949 }
950 }
951 if ( !var.toString().isEmpty() )
952 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
953 else
954 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
955 }
956}
957
958QString QgsProcessingAlgorithm::invalidRasterError( const QVariantMap &parameters, const QString &name )
959{
960 if ( !parameters.contains( name ) )
961 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
962 else
963 {
964 QVariant var = parameters.value( name );
965 if ( var.userType() == qMetaTypeId<QgsProperty>() )
966 {
967 QgsProperty p = var.value< QgsProperty >();
969 {
970 var = p.staticValue();
971 }
972 }
973 if ( !var.toString().isEmpty() )
974 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
975 else
976 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
977 }
978}
979
980QString QgsProcessingAlgorithm::invalidSinkError( const QVariantMap &parameters, const QString &name )
981{
982 if ( !parameters.contains( name ) )
983 return QObject::tr( "Could not create destination layer for %1: no value specified for parameter" ).arg( name );
984 else
985 {
986 QVariant var = parameters.value( name );
987 if ( var.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
988 {
989 QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
990 var = fromVar.sink;
991 }
992 if ( var.userType() == qMetaTypeId<QgsProperty>() )
993 {
994 QgsProperty p = var.value< QgsProperty >();
996 {
997 var = p.staticValue();
998 }
999 }
1000 if ( !var.toString().isEmpty() )
1001 return QObject::tr( "Could not create destination layer for %1: %2" ).arg( name, var.toString() );
1002 else
1003 return QObject::tr( "Could not create destination layer for %1: invalid value" ).arg( name );
1004 }
1005}
1006
1007QString QgsProcessingAlgorithm::invalidPointCloudError( const QVariantMap &parameters, const QString &name )
1008{
1009 if ( !parameters.contains( name ) )
1010 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
1011 else
1012 {
1013 QVariant var = parameters.value( name );
1014 if ( var.userType() == qMetaTypeId<QgsProperty>() )
1015 {
1016 QgsProperty p = var.value< QgsProperty >();
1018 {
1019 var = p.staticValue();
1020 }
1021 }
1022 if ( !var.toString().isEmpty() )
1023 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
1024 else
1025 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
1026 }
1027}
1028
1029QString QgsProcessingAlgorithm::writeFeatureError( QgsFeatureSink *sink, const QVariantMap &parameters, const QString &name )
1030{
1031 Q_UNUSED( sink );
1032 Q_UNUSED( parameters );
1033 if ( !name.isEmpty() )
1034 return QObject::tr( "Could not write feature into %1" ).arg( name );
1035 else
1036 return QObject::tr( "Could not write feature" );
1037}
1038
1040{
1041 Q_UNUSED( layer )
1042 return false;
1043}
1044
1045
1046bool QgsProcessingAlgorithm::createAutoOutputForParameter( QgsProcessingParameterDefinition *parameter )
1047{
1048 if ( !parameter->isDestination() )
1049 return true; // nothing created, but nothing went wrong - so return true
1050
1051 QgsProcessingDestinationParameter *dest = static_cast< QgsProcessingDestinationParameter * >( parameter );
1053 if ( !output )
1054 return true; // nothing created - but nothing went wrong - so return true
1055 output->setAutoCreated( true );
1056
1057 if ( !addOutput( output ) )
1058 {
1059 // couldn't add output - probably a duplicate name
1060 return false;
1061 }
1062 else
1063 {
1064 return true;
1065 }
1066}
1067
1068
1069//
1070// QgsProcessingFeatureBasedAlgorithm
1071//
1072
1079
1081{
1083 initParameters( config );
1084 addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), outputName(), outputLayerType(), QVariant(), false, true, true ) );
1085}
1086
1088{
1089 return QStringLiteral( "INPUT" );
1090}
1091
1093{
1094 return QObject::tr( "Input layer" );
1095}
1096
1098{
1099 return QList<int>();
1100}
1101
1106
1111
1116
1118{
1119 return inputWkbType;
1120}
1121
1123{
1124 return inputFields;
1125}
1126
1131
1133{
1134}
1135
1137{
1138 if ( mSource )
1139 return mSource->sourceCrs();
1140 else
1142}
1143
1144QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
1145{
1146 prepareSource( parameters, context );
1147 QString dest;
1148 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest,
1149 outputFields( mSource->fields() ),
1150 outputWkbType( mSource->wkbType() ),
1151 outputCrs( mSource->sourceCrs() ),
1152 sinkFlags() ) );
1153 if ( !sink )
1154 throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );
1155
1156 // prepare expression context for feature iteration
1157 QgsExpressionContext prevContext = context.expressionContext();
1158 QgsExpressionContext algContext = prevContext;
1159
1160 algContext.appendScopes( createExpressionContext( parameters, context, mSource.get() ).takeScopes() );
1161 context.setExpressionContext( algContext );
1162
1163 long count = mSource->featureCount();
1164
1165 QgsFeature f;
1166 QgsFeatureIterator it = mSource->getFeatures( request(), sourceFlags() );
1167
1168 double step = count > 0 ? 100.0 / count : 1;
1169 int current = 0;
1170 while ( it.nextFeature( f ) )
1171 {
1172 if ( feedback->isCanceled() )
1173 {
1174 break;
1175 }
1176
1177 context.expressionContext().setFeature( f );
1178 const QgsFeatureList transformed = processFeature( f, context, feedback );
1179 for ( QgsFeature transformedFeature : transformed )
1180 sink->addFeature( transformedFeature, QgsFeatureSink::FastInsert );
1181
1182 feedback->setProgress( current * step );
1183 current++;
1184 }
1185
1186 mSource.reset();
1187
1188 // probably not necessary - context's aren't usually recycled, but can't hurt
1189 context.setExpressionContext( prevContext );
1190
1191 QVariantMap outputs;
1192 outputs.insert( QStringLiteral( "OUTPUT" ), dest );
1193 return outputs;
1194}
1195
1200
1202{
1203 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
1204 if ( !layer )
1205 return false;
1206
1207 Qgis::GeometryType inPlaceGeometryType = layer->geometryType();
1208 if ( !inputLayerTypes().empty() &&
1209 !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::Vector ) ) &&
1210 !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry ) ) &&
1211 ( ( inPlaceGeometryType == Qgis::GeometryType::Polygon && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon ) ) ) ||
1212 ( inPlaceGeometryType == Qgis::GeometryType::Line && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorLine ) ) ) ||
1213 ( inPlaceGeometryType == Qgis::GeometryType::Point && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorPoint ) ) ) ) )
1214 return false;
1215
1217 if ( inPlaceGeometryType == Qgis::GeometryType::Point )
1218 type = Qgis::WkbType::Point;
1219 else if ( inPlaceGeometryType == Qgis::GeometryType::Line )
1221 else if ( inPlaceGeometryType == Qgis::GeometryType::Polygon )
1223
1224 if ( QgsWkbTypes::geometryType( outputWkbType( type ) ) != inPlaceGeometryType )
1225 return false;
1226
1227 return true;
1228}
1229
1231{
1232 if ( ! mSource )
1233 {
1234 mSource.reset( parameterAsSource( parameters, inputParameterName(), context ) );
1235 if ( !mSource )
1237 }
1238}
1239
1240
1241QgsProcessingAlgorithm::VectorProperties QgsProcessingFeatureBasedAlgorithm::sinkProperties( const QString &sink, const QVariantMap &parameters, QgsProcessingContext &context, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> &sourceProperties ) const
1242{
1244 if ( sink == QLatin1String( "OUTPUT" ) )
1245 {
1246 if ( sourceProperties.value( QStringLiteral( "INPUT" ) ).availability == Qgis::ProcessingPropertyAvailability::Available )
1247 {
1248 const VectorProperties inputProps = sourceProperties.value( QStringLiteral( "INPUT" ) );
1249 result.fields = outputFields( inputProps.fields );
1250 result.crs = outputCrs( inputProps.crs );
1251 result.wkbType = outputWkbType( inputProps.wkbType );
1253 return result;
1254 }
1255 else
1256 {
1257 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
1258 if ( source )
1259 {
1260 result.fields = outputFields( source->fields() );
1261 result.crs = outputCrs( source->sourceCrs() );
1262 result.wkbType = outputWkbType( source->wkbType() );
1264 return result;
1265 }
1266 }
1267 }
1268 return result;
1269}
1270
ProcessingSourceType
Processing data source types.
Definition qgis.h:3262
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ VectorAnyGeometry
Any vector layer with geometry.
@ VectorPoint
Vector point layers.
@ VectorPolygon
Vector polygon layers.
@ VectorLine
Vector line layers.
@ Critical
Critical/error message.
Definition qgis.h:157
@ Static
Static property.
@ Available
Properties are available.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:337
@ Polygon
Polygons.
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3339
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
Definition qgis.h:3359
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
@ LineString
LineString.
@ Polygon
Polygon.
@ Unknown
Unknown.
@ SupportsBatch
Algorithm supports batch mode.
@ SupportsInPlaceEdits
Algorithm supports in-place editing.
@ RequiresMatchingCrs
Algorithm requires that all input layers have matching coordinate reference systems.
@ CanCancel
Algorithm can be canceled.
@ RequiresProject
The algorithm requires that a valid QgsProject is available from the processing context in order to e...
@ Hidden
Parameter is hidden and should not be shown to users.
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Definition qgis.h:3436
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.
This class 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.
This class 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...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:53
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition qgsfeedback.h:61
Container of fields for a vector layer.
Definition qgsfields.h:46
A geometry is the spatial representation of a feature.
Base class for graphical items within a QgsLayout.
void transferLayersFromStore(QgsMapLayerStore *other)
Transfers all the map layers contained within another map layer store and adds them to this store.
Base class for all map layer types.
Definition qgsmaplayer.h:76
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:83
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)
Adds a message to the log instance (and creates it if necessary).
Represents a map layer supporting display of point clouds.
A class to represent a 2D point.
Definition qgspointxy.h:60
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Abstract base class for processing algorithms.
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.
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.
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.
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.
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.
QString name() const
Returns the name of the output.
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.
QgsProcessingAlgorithm * mAlgorithm
Pointer to algorithm which owns this parameter.
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 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.
Abstract base class for processing providers.
virtual QString id() const =0
Returns the unique provider id, used for identifying the provider.
virtual bool supportsNonFileBasedOutput() const
Returns true if the provider supports non-file based outputs (such as memory layers or direct databas...
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.
Represents a raster layer.
A rectangle specified with double values.
Represents a vector layer which manages a vector based data sets.
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.
const QgsCoordinateReferenceSystem & outputCrs
const QgsCoordinateReferenceSystem & crs
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.