QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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
81{
82 return QgsApplication::getThemeIcon( "/processingAlgorithm.svg" );
83}
84
86{
87 return QgsApplication::iconPath( QStringLiteral( "processingAlgorithm.svg" ) );
88}
89
94
96{
97 return true;
98}
99
100bool QgsProcessingAlgorithm::checkParameterValues( const QVariantMap &parameters, QgsProcessingContext &context, QString *message ) const
101{
102 for ( const QgsProcessingParameterDefinition *def : mParameters )
103 {
104 if ( !def->checkValueIsAcceptable( parameters.value( def->name() ), &context ) )
105 {
106 if ( message )
107 {
108 // TODO QGIS 4 - move the message handling to the parameter subclasses (but this
109 // requires a change in signature for the virtual checkValueIsAcceptable method)
111 *message = invalidSourceError( parameters, def->name() );
112 else if ( def->type() == QgsProcessingParameterFeatureSink::typeName() )
113 *message = invalidSinkError( parameters, def->name() );
114 else if ( def->type() == QgsProcessingParameterRasterLayer::typeName() )
115 *message = invalidRasterError( parameters, def->name() );
116 else if ( def->type() == QgsProcessingParameterPointCloudLayer::typeName() )
117 *message = invalidPointCloudError( parameters, def->name() );
118 else
119 *message = QObject::tr( "Incorrect parameter value for %1" ).arg( def->name() );
120 }
121 return false;
122 }
123 }
124 return true;
125}
126
127QVariantMap QgsProcessingAlgorithm::preprocessParameters( const QVariantMap &parameters )
128{
129 return parameters;
130}
131
133{
134 return mProvider;
135}
136
138{
139 mProvider = provider;
140
141 if ( mProvider && !mProvider->supportsNonFileBasedOutput() )
142 {
143 // need to update all destination parameters to turn off non file based outputs
144 for ( const QgsProcessingParameterDefinition *definition : std::as_const( mParameters ) )
145 {
146 if ( definition->isDestination() )
147 {
148 const QgsProcessingDestinationParameter *destParam = static_cast< const QgsProcessingDestinationParameter *>( definition );
149 const_cast< QgsProcessingDestinationParameter *>( destParam )->setSupportsNonFileBasedOutput( false );
150 }
151 }
152 }
153}
154
156{
157 return nullptr;
158}
159
161 QgsProcessingContext &context, QgsProcessingFeatureSource *source ) const
162{
163 // start with context's expression context
165
166 // If there's a source capable of generating a context scope, use it
167 if ( source )
168 {
170 if ( scope )
171 c << scope;
172 }
173 else if ( c.scopeCount() == 0 )
174 {
175 //empty scope, populate with initial scopes
178 }
179
180 c << QgsExpressionContextUtils::processingAlgorithmScope( this, parameters, context );
181 return c;
182}
183
184bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, QgsProcessingContext &context ) const
185{
187 {
188 // I'm a well behaved algorithm - I take work AWAY from users!
189 return true;
190 }
191
192 bool foundCrs = false;
194 for ( const QgsProcessingParameterDefinition *def : mParameters )
195 {
197 {
198 QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( def, parameters, context );
199 if ( layer )
200 {
201 if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
202 {
203 return false;
204 }
205 else if ( !foundCrs && layer->crs().isValid() )
206 {
207 foundCrs = true;
208 crs = layer->crs();
209 }
210 }
211 }
212 else if ( def->type() == QgsProcessingParameterFeatureSource::typeName() )
213 {
214 std::unique_ptr< QgsFeatureSource > source( QgsProcessingParameters::parameterAsSource( def, parameters, context ) );
215 if ( source )
216 {
217 if ( foundCrs && source->sourceCrs().isValid() && crs != source->sourceCrs() )
218 {
219 return false;
220 }
221 else if ( !foundCrs && source->sourceCrs().isValid() )
222 {
223 foundCrs = true;
224 crs = source->sourceCrs();
225 }
226 }
227 }
228 else if ( def->type() == QgsProcessingParameterMultipleLayers::typeName() )
229 {
230 QList< QgsMapLayer *> layers = QgsProcessingParameters::parameterAsLayerList( def, parameters, context );
231 const auto constLayers = layers;
232 for ( QgsMapLayer *layer : constLayers )
233 {
234 if ( !layer )
235 continue;
236
237 if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
238 {
239 return false;
240 }
241 else if ( !foundCrs && layer->crs().isValid() )
242 {
243 foundCrs = true;
244 crs = layer->crs();
245 }
246 }
247 }
248 else if ( def->type() == QgsProcessingParameterExtent::typeName() )
249 {
251 if ( foundCrs && extentCrs.isValid() && crs != extentCrs )
252 {
253 return false;
254 }
255 else if ( !foundCrs && extentCrs.isValid() )
256 {
257 foundCrs = true;
258 crs = extentCrs;
259 }
260 }
261 else if ( def->type() == QgsProcessingParameterPoint::typeName() )
262 {
264 if ( foundCrs && pointCrs.isValid() && crs != pointCrs )
265 {
266 return false;
267 }
268 else if ( !foundCrs && pointCrs.isValid() )
269 {
270 foundCrs = true;
271 crs = pointCrs;
272 }
273 }
274 else if ( def->type() == QgsProcessingParameterGeometry::typeName() )
275 {
277 if ( foundCrs && geomCrs.isValid() && crs != geomCrs )
278 {
279 return false;
280 }
281 else if ( !foundCrs && geomCrs.isValid() )
282 {
283 foundCrs = true;
284 crs = geomCrs;
285 }
286 }
287
288 }
289 return true;
290}
291
292QString QgsProcessingAlgorithm::asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const
293{
294 QString s = QStringLiteral( "processing.run(\"%1\"," ).arg( id() );
295
296 QStringList parts;
297 for ( const QgsProcessingParameterDefinition *def : mParameters )
298 {
299 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
300 continue;
301
302 if ( !parameters.contains( def->name() ) )
303 continue;
304
305 parts << QStringLiteral( "'%1':%2" ).arg( def->name(), def->valueAsPythonString( parameters.value( def->name() ), context ) );
306 }
307
308 s += QStringLiteral( " {%1})" ).arg( parts.join( ',' ) );
309 return s;
310}
311
312QString QgsProcessingAlgorithm::asQgisProcessCommand( const QVariantMap &parameters, QgsProcessingContext &context, bool &ok ) const
313{
314 ok = true;
315 QStringList parts;
316 parts.append( QStringLiteral( "qgis_process" ) );
317 parts.append( QStringLiteral( "run" ) );
318 parts.append( id() );
319
320 QgsProcessingContext::ProcessArgumentFlags argumentFlags;
321 // we only include the project path argument if a project is actually required by the algorithm
324
325 parts.append( context.asQgisProcessArguments( argumentFlags ) );
326
327 auto escapeIfNeeded = []( const QString & input ) -> QString
328 {
329 // play it safe and escape everything UNLESS it's purely alphanumeric characters (and a very select scattering of other common characters!)
330 const thread_local QRegularExpression nonAlphaNumericRx( QStringLiteral( "[^a-zA-Z0-9.\\-/_]" ) );
331 if ( nonAlphaNumericRx.match( input ).hasMatch() )
332 {
333 QString escaped = input;
334 escaped.replace( '\'', QLatin1String( "'\\''" ) );
335 return QStringLiteral( "'%1'" ).arg( escaped );
336 }
337 else
338 {
339 return input;
340 }
341 };
342
343 for ( const QgsProcessingParameterDefinition *def : mParameters )
344 {
345 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
346 continue;
347
348 if ( !parameters.contains( def->name() ) )
349 continue;
350
351 const QStringList partValues = def->valueAsStringList( parameters.value( def->name() ), context, ok );
352 if ( !ok )
353 return QString();
354
355 for ( const QString &partValue : partValues )
356 {
357 parts << QStringLiteral( "--%1=%2" ).arg( def->name(), escapeIfNeeded( partValue ) );
358 }
359 }
360
361 return parts.join( ' ' );
362}
363
364QVariantMap QgsProcessingAlgorithm::asMap( const QVariantMap &parameters, QgsProcessingContext &context ) const
365{
366 QVariantMap properties = context.exportToMap();
367
368 // we only include the project path argument if a project is actually required by the algorithm
370 properties.remove( QStringLiteral( "project_path" ) );
371
372 QVariantMap paramValues;
373 for ( const QgsProcessingParameterDefinition *def : mParameters )
374 {
375 if ( def->flags() & Qgis::ProcessingParameterFlag::Hidden )
376 continue;
377
378 if ( !parameters.contains( def->name() ) )
379 continue;
380
381 paramValues.insert( def->name(), def->valueAsJsonObject( parameters.value( def->name() ), context ) );
382 }
383
384 properties.insert( QStringLiteral( "inputs" ), paramValues );
385 return properties;
386}
387
389{
390 if ( !definition )
391 return false;
392
393 // check for duplicate named parameters
395 if ( existingDef && existingDef->name() == definition->name() ) // parameterDefinition is case-insensitive, but we DO allow case-different duplicate names
396 {
397 QgsMessageLog::logMessage( QObject::tr( "Duplicate parameter %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
398 delete definition;
399 return false;
400 }
401
402 if ( definition->isDestination() && mProvider )
403 {
404 QgsProcessingDestinationParameter *destParam = static_cast< QgsProcessingDestinationParameter *>( definition );
405 if ( !mProvider->supportsNonFileBasedOutput() )
406 destParam->setSupportsNonFileBasedOutput( false );
407 }
408
409 mParameters << definition;
410 definition->mAlgorithm = this;
411
412 if ( createOutput )
413 return createAutoOutputForParameter( definition );
414 else
415 return true;
416}
417
419{
421 if ( def )
422 {
423 delete def;
424 mParameters.removeAll( def );
425
426 // remove output automatically created when adding parameter
428 if ( outputDef && outputDef->autoCreated() )
429 {
430 delete outputDef;
431 mOutputs.removeAll( outputDef );
432 }
433 }
434}
435
437{
438 if ( !definition )
439 return false;
440
441 // check for duplicate named outputs
442 if ( QgsProcessingAlgorithm::outputDefinition( definition->name() ) )
443 {
444 QgsMessageLog::logMessage( QObject::tr( "Duplicate output %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
445 delete definition;
446 return false;
447 }
448
449 mOutputs << definition;
450 return true;
451}
452
454{
455 return true;
456}
457
462
464{
465 // first pass - case sensitive match
466 for ( const QgsProcessingParameterDefinition *def : mParameters )
467 {
468 if ( def->name() == name )
469 return def;
470 }
471
472 // second pass - case insensitive
473 for ( const QgsProcessingParameterDefinition *def : mParameters )
474 {
475 if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
476 return def;
477 }
478 return nullptr;
479}
480
482{
483 int count = 0;
484 for ( const QgsProcessingParameterDefinition *def : mParameters )
485 {
486 if ( !( def->flags() & Qgis::ProcessingParameterFlag::Hidden ) )
487 count++;
488 }
489 return count;
490}
491
493{
495 for ( const QgsProcessingParameterDefinition *def : mParameters )
496 {
497 if ( def->isDestination() )
498 result << def;
499 }
500 return result;
501}
502
504{
505 for ( const QgsProcessingOutputDefinition *def : mOutputs )
506 {
507 if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
508 return def;
509 }
510 return nullptr;
511}
512
514{
515 for ( const QgsProcessingOutputDefinition *def : mOutputs )
516 {
517 if ( def->type() == QLatin1String( "outputHtml" ) )
518 return true;
519 }
520 return false;
521}
522
523QgsProcessingAlgorithm::VectorProperties QgsProcessingAlgorithm::sinkProperties( const QString &, const QVariantMap &, QgsProcessingContext &, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> & ) const
524{
525 return VectorProperties();
526}
527
528QVariantMap QgsProcessingAlgorithm::run( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok, const QVariantMap &configuration, bool catchExceptions ) const
529{
530 std::unique_ptr< QgsProcessingAlgorithm > alg( create( configuration ) );
531 if ( ok )
532 *ok = false;
533
534 bool res = alg->prepare( parameters, context, feedback );
535 if ( !res )
536 return QVariantMap();
537
538 QVariantMap runRes;
539 try
540 {
541 runRes = alg->runPrepared( parameters, context, feedback );
542 }
543 catch ( QgsProcessingException &e )
544 {
545 if ( !catchExceptions )
546 throw e;
547
548 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
549 feedback->reportError( e.what() );
550 return QVariantMap();
551 }
552
553 if ( ok )
554 *ok = true;
555
556 QVariantMap ppRes = alg->postProcess( context, feedback );
557 if ( !ppRes.isEmpty() )
558 return ppRes;
559 else
560 return runRes;
561}
562
563bool QgsProcessingAlgorithm::prepare( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
564{
565 // cppcheck-suppress assertWithSideEffect
566 Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::prepare", "prepare() must be called from the same thread as context was created in" );
567 Q_ASSERT_X( !mHasPrepared, "QgsProcessingAlgorithm::prepare", "prepare() has already been called for the algorithm instance" );
568 try
569 {
570 mHasPrepared = prepareAlgorithm( parameters, context, feedback );
571 return mHasPrepared;
572 }
573 catch ( QgsProcessingException &e )
574 {
575 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
576 feedback->reportError( e.what() );
577 return false;
578 }
579}
580
581QVariantMap QgsProcessingAlgorithm::runPrepared( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
582{
583 Q_ASSERT_X( mHasPrepared, "QgsProcessingAlgorithm::runPrepared", QStringLiteral( "prepare() was not called for the algorithm instance %1" ).arg( name() ).toLatin1() );
584 Q_ASSERT_X( !mHasExecuted, "QgsProcessingAlgorithm::runPrepared", "runPrepared() was already called for this algorithm instance" );
585
586 // Hey kids, let's all be thread safe! It's the fun thing to do!
587 //
588 // First, let's see if we're going to run into issues.
589 QgsProcessingContext *runContext = nullptr;
590 if ( context.thread() == QThread::currentThread() )
591 {
592 // OH. No issues. Seems you're running everything in the same thread, so go about your business. Sorry about
593 // the intrusion, we're just making sure everything's nice and safe here. We like to keep a clean and tidy neighbourhood,
594 // you know, for the kids and dogs and all.
595 runContext = &context;
596 }
597 else
598 {
599 // HA! I knew things looked a bit suspicious - seems you're running this algorithm in a different thread
600 // from that which the passed context has an affinity for. That's fine and all, but we need to make sure
601 // we proceed safely...
602
603 // So first we create a temporary local context with affinity for the current thread
604 mLocalContext.reset( new QgsProcessingContext() );
605 // copy across everything we can safely do from the passed context
606 mLocalContext->copyThreadSafeSettings( context );
607 // and we'll run the actual algorithm processing using the local thread safe context
608 runContext = mLocalContext.get();
609 }
610
611 try
612 {
613 QVariantMap runResults = processAlgorithm( parameters, *runContext, feedback );
614
615 mHasExecuted = true;
616 if ( mLocalContext )
617 {
618 // ok, time to clean things up. We need to push the temporary context back into
619 // the thread that the passed context is associated with (we can only push from the
620 // current thread, so we HAVE to do this here)
621 mLocalContext->pushToThread( context.thread() );
622 }
623 return runResults;
624 }
625 catch ( QgsProcessingException & )
626 {
627 if ( mLocalContext )
628 {
629 // see above!
630 mLocalContext->pushToThread( context.thread() );
631 }
632 //rethrow
633 throw;
634 }
635}
636
638{
639 // cppcheck-suppress assertWithSideEffect
640 Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::postProcess", "postProcess() must be called from the same thread the context was created in" );
641 Q_ASSERT_X( mHasExecuted, "QgsProcessingAlgorithm::postProcess", QStringLiteral( "algorithm instance %1 was not executed" ).arg( name() ).toLatin1() );
642 Q_ASSERT_X( !mHasPostProcessed, "QgsProcessingAlgorithm::postProcess", "postProcess() was already called for this algorithm instance" );
643
644 if ( mLocalContext )
645 {
646 // algorithm was processed using a temporary thread safe context. So now we need
647 // to take the results from that temporary context, and smash them into the passed
648 // context
649 context.takeResultsFrom( *mLocalContext );
650 // now get lost, we don't need you anymore
651 mLocalContext.reset();
652 }
653
654 mHasPostProcessed = true;
655 try
656 {
657 return postProcessAlgorithm( context, feedback );
658 }
659 catch ( QgsProcessingException &e )
660 {
661 QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
662 feedback->reportError( e.what() );
663 return QVariantMap();
664 }
665}
666
667QString QgsProcessingAlgorithm::parameterAsString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
668{
670}
671
672QString QgsProcessingAlgorithm::parameterAsExpression( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
673{
675}
676
677double QgsProcessingAlgorithm::parameterAsDouble( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
678{
680}
681
682int QgsProcessingAlgorithm::parameterAsInt( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
683{
684 return QgsProcessingParameters::parameterAsInt( parameterDefinition( name ), parameters, context );
685}
686
687QList<int> QgsProcessingAlgorithm::parameterAsInts( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
688{
689 return QgsProcessingParameters::parameterAsInts( parameterDefinition( name ), parameters, context );
690}
691
692int QgsProcessingAlgorithm::parameterAsEnum( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
693{
694 return QgsProcessingParameters::parameterAsEnum( parameterDefinition( name ), parameters, context );
695}
696
697QList<int> QgsProcessingAlgorithm::parameterAsEnums( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
698{
700}
701
702QString QgsProcessingAlgorithm::parameterAsEnumString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
703{
705}
706
707QStringList QgsProcessingAlgorithm::parameterAsEnumStrings( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
708{
710}
711
712bool QgsProcessingAlgorithm::parameterAsBool( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
713{
714 return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
715}
716
717bool QgsProcessingAlgorithm::parameterAsBoolean( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
718{
719 return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
720}
721
722QgsFeatureSink *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
723{
724 if ( !parameterDefinition( name ) )
725 throw QgsProcessingException( QObject::tr( "No parameter definition for the sink '%1'" ).arg( name ) );
726
727 return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
728}
729
730QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
731{
733}
734
735QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback ) const
736{
737 return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback );
738}
739
740QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPathAndLayerName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName ) const
741{
742 return QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback, layerName );
743}
744
745QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
746{
748}
749
750QgsRasterLayer *QgsProcessingAlgorithm::parameterAsRasterLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
751{
753}
754
755QgsMeshLayer *QgsProcessingAlgorithm::parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
756{
758}
759
760QString QgsProcessingAlgorithm::parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
761{
763}
764
765QString QgsProcessingAlgorithm::parameterAsFileOutput( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
766{
768}
769
770QgsVectorLayer *QgsProcessingAlgorithm::parameterAsVectorLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
771{
773}
774
775QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
776{
777 return QgsProcessingParameters::parameterAsCrs( parameterDefinition( name ), parameters, context );
778}
779
780QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsExtentCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
781{
783}
784
785QgsRectangle QgsProcessingAlgorithm::parameterAsExtent( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
786{
788}
789
790QgsGeometry QgsProcessingAlgorithm::parameterAsExtentGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
791{
793}
794
795QgsPointXY QgsProcessingAlgorithm::parameterAsPoint( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
796{
798}
799
800QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsPointCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
801{
803}
804
805QgsGeometry QgsProcessingAlgorithm::parameterAsGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
806{
808}
809
810QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsGeometryCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
811{
813}
814
815QString QgsProcessingAlgorithm::parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
816{
817 return QgsProcessingParameters::parameterAsFile( parameterDefinition( name ), parameters, context );
818}
819
820QVariantList QgsProcessingAlgorithm::parameterAsMatrix( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
821{
823}
824
825QList<QgsMapLayer *> QgsProcessingAlgorithm::parameterAsLayerList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags ) const
826{
828}
829
830QStringList QgsProcessingAlgorithm::parameterAsFileList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
831{
833}
834
835QList<double> QgsProcessingAlgorithm::parameterAsRange( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
836{
838}
839
840QStringList QgsProcessingAlgorithm::parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
841{
843}
844
845QStringList QgsProcessingAlgorithm::parameterAsStrings( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
846{
848}
849
850QgsPrintLayout *QgsProcessingAlgorithm::parameterAsLayout( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
851{
853}
854
855QgsLayoutItem *QgsProcessingAlgorithm::parameterAsLayoutItem( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsPrintLayout *layout )
856{
857 return QgsProcessingParameters::parameterAsLayoutItem( parameterDefinition( name ), parameters, context, layout );
858}
859
860QColor QgsProcessingAlgorithm::parameterAsColor( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
861{
863}
864
865QString QgsProcessingAlgorithm::parameterAsConnectionName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
866{
868}
869
870QDateTime QgsProcessingAlgorithm::parameterAsDateTime( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
871{
873}
874
875QString QgsProcessingAlgorithm::parameterAsSchema( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
876{
878}
879
880QString QgsProcessingAlgorithm::parameterAsDatabaseTableName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
881{
883}
884
885QgsPointCloudLayer *QgsProcessingAlgorithm::parameterAsPointCloudLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsProcessing::LayerOptionsFlags flags ) const
886{
888}
889
890QgsAnnotationLayer *QgsProcessingAlgorithm::parameterAsAnnotationLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
891{
893}
894
895QString QgsProcessingAlgorithm::invalidSourceError( const QVariantMap &parameters, const QString &name )
896{
897 if ( !parameters.contains( name ) )
898 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
899 else
900 {
901 QVariant var = parameters.value( name );
902 if ( var.userType() == QMetaType::type( "QgsProcessingFeatureSourceDefinition" ) )
903 {
904 QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
905 var = fromVar.source;
906 }
907 else if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
908 {
909 QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
910 var = fromVar.sink;
911 }
912 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
913 {
914 QgsProperty p = var.value< QgsProperty >();
916 {
917 var = p.staticValue();
918 }
919 }
920 if ( !var.toString().isEmpty() )
921 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
922 else
923 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
924 }
925}
926
927QString QgsProcessingAlgorithm::invalidRasterError( const QVariantMap &parameters, const QString &name )
928{
929 if ( !parameters.contains( name ) )
930 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
931 else
932 {
933 QVariant var = parameters.value( name );
934 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
935 {
936 QgsProperty p = var.value< QgsProperty >();
938 {
939 var = p.staticValue();
940 }
941 }
942 if ( !var.toString().isEmpty() )
943 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
944 else
945 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
946 }
947}
948
949QString QgsProcessingAlgorithm::invalidSinkError( const QVariantMap &parameters, const QString &name )
950{
951 if ( !parameters.contains( name ) )
952 return QObject::tr( "Could not create destination layer for %1: no value specified for parameter" ).arg( name );
953 else
954 {
955 QVariant var = parameters.value( name );
956 if ( var.userType() == QMetaType::type( "QgsProcessingOutputLayerDefinition" ) )
957 {
958 QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
959 var = fromVar.sink;
960 }
961 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
962 {
963 QgsProperty p = var.value< QgsProperty >();
965 {
966 var = p.staticValue();
967 }
968 }
969 if ( !var.toString().isEmpty() )
970 return QObject::tr( "Could not create destination layer for %1: %2" ).arg( name, var.toString() );
971 else
972 return QObject::tr( "Could not create destination layer for %1: invalid value" ).arg( name );
973 }
974}
975
976QString QgsProcessingAlgorithm::invalidPointCloudError( const QVariantMap &parameters, const QString &name )
977{
978 if ( !parameters.contains( name ) )
979 return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
980 else
981 {
982 QVariant var = parameters.value( name );
983 if ( var.userType() == QMetaType::type( "QgsProperty" ) )
984 {
985 QgsProperty p = var.value< QgsProperty >();
987 {
988 var = p.staticValue();
989 }
990 }
991 if ( !var.toString().isEmpty() )
992 return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
993 else
994 return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
995 }
996}
997
998QString QgsProcessingAlgorithm::writeFeatureError( QgsFeatureSink *sink, const QVariantMap &parameters, const QString &name )
999{
1000 Q_UNUSED( sink );
1001 Q_UNUSED( parameters );
1002 if ( !name.isEmpty() )
1003 return QObject::tr( "Could not write feature into %1" ).arg( name );
1004 else
1005 return QObject::tr( "Could not write feature" );
1006}
1007
1009{
1010 Q_UNUSED( layer )
1011 return false;
1012}
1013
1014
1015bool QgsProcessingAlgorithm::createAutoOutputForParameter( QgsProcessingParameterDefinition *parameter )
1016{
1017 if ( !parameter->isDestination() )
1018 return true; // nothing created, but nothing went wrong - so return true
1019
1020 QgsProcessingDestinationParameter *dest = static_cast< QgsProcessingDestinationParameter * >( parameter );
1022 if ( !output )
1023 return true; // nothing created - but nothing went wrong - so return true
1024 output->setAutoCreated( true );
1025
1026 if ( !addOutput( output ) )
1027 {
1028 // couldn't add output - probably a duplicate name
1029 return false;
1030 }
1031 else
1032 {
1033 return true;
1034 }
1035}
1036
1037
1038//
1039// QgsProcessingFeatureBasedAlgorithm
1040//
1041
1042Qgis::ProcessingAlgorithmFlags QgsProcessingFeatureBasedAlgorithm::flags() const
1043{
1044 Qgis::ProcessingAlgorithmFlags f = QgsProcessingAlgorithm::flags();
1046 return f;
1047}
1048
1050{
1052 initParameters( config );
1053 addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), outputName(), outputLayerType(), QVariant(), false, true, true ) );
1054}
1055
1057{
1058 return QStringLiteral( "INPUT" );
1059}
1060
1062{
1063 return QObject::tr( "Input layer" );
1064}
1065
1067{
1068 return QList<int>();
1069}
1070
1075
1076Qgis::ProcessingFeatureSourceFlags QgsProcessingFeatureBasedAlgorithm::sourceFlags() const
1077{
1078 return Qgis::ProcessingFeatureSourceFlags();
1079}
1080
1081QgsFeatureSink::SinkFlags QgsProcessingFeatureBasedAlgorithm::sinkFlags() const
1082{
1083 return QgsFeatureSink::SinkFlags();
1084}
1085
1087{
1088 return inputWkbType;
1089}
1090
1092{
1093 return inputFields;
1094}
1095
1100
1102{
1103}
1104
1106{
1107 if ( mSource )
1108 return mSource->sourceCrs();
1109 else
1111}
1112
1113QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
1114{
1115 prepareSource( parameters, context );
1116 QString dest;
1117 std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest,
1118 outputFields( mSource->fields() ),
1119 outputWkbType( mSource->wkbType() ),
1120 outputCrs( mSource->sourceCrs() ),
1121 sinkFlags() ) );
1122 if ( !sink )
1123 throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );
1124
1125 // prepare expression context for feature iteration
1126 QgsExpressionContext prevContext = context.expressionContext();
1127 QgsExpressionContext algContext = prevContext;
1128
1129 algContext.appendScopes( createExpressionContext( parameters, context, mSource.get() ).takeScopes() );
1130 context.setExpressionContext( algContext );
1131
1132 long count = mSource->featureCount();
1133
1134 QgsFeature f;
1135 QgsFeatureIterator it = mSource->getFeatures( request(), sourceFlags() );
1136
1137 double step = count > 0 ? 100.0 / count : 1;
1138 int current = 0;
1139 while ( it.nextFeature( f ) )
1140 {
1141 if ( feedback->isCanceled() )
1142 {
1143 break;
1144 }
1145
1146 context.expressionContext().setFeature( f );
1147 const QgsFeatureList transformed = processFeature( f, context, feedback );
1148 for ( QgsFeature transformedFeature : transformed )
1149 sink->addFeature( transformedFeature, QgsFeatureSink::FastInsert );
1150
1151 feedback->setProgress( current * step );
1152 current++;
1153 }
1154
1155 mSource.reset();
1156
1157 // probably not necessary - context's aren't usually recycled, but can't hurt
1158 context.setExpressionContext( prevContext );
1159
1160 QVariantMap outputs;
1161 outputs.insert( QStringLiteral( "OUTPUT" ), dest );
1162 return outputs;
1163}
1164
1169
1171{
1172 const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
1173 if ( !layer )
1174 return false;
1175
1176 Qgis::GeometryType inPlaceGeometryType = layer->geometryType();
1177 if ( !inputLayerTypes().empty() &&
1178 !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::Vector ) ) &&
1179 !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorAnyGeometry ) ) &&
1180 ( ( inPlaceGeometryType == Qgis::GeometryType::Polygon && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorPolygon ) ) ) ||
1181 ( inPlaceGeometryType == Qgis::GeometryType::Line && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorLine ) ) ) ||
1182 ( inPlaceGeometryType == Qgis::GeometryType::Point && !inputLayerTypes().contains( static_cast< int >( Qgis::ProcessingSourceType::VectorPoint ) ) ) ) )
1183 return false;
1184
1186 if ( inPlaceGeometryType == Qgis::GeometryType::Point )
1187 type = Qgis::WkbType::Point;
1188 else if ( inPlaceGeometryType == Qgis::GeometryType::Line )
1190 else if ( inPlaceGeometryType == Qgis::GeometryType::Polygon )
1192
1193 if ( QgsWkbTypes::geometryType( outputWkbType( type ) ) != inPlaceGeometryType )
1194 return false;
1195
1196 return true;
1197}
1198
1200{
1201 if ( ! mSource )
1202 {
1203 mSource.reset( parameterAsSource( parameters, inputParameterName(), context ) );
1204 if ( !mSource )
1206 }
1207}
1208
1209
1210QgsProcessingAlgorithm::VectorProperties QgsProcessingFeatureBasedAlgorithm::sinkProperties( const QString &sink, const QVariantMap &parameters, QgsProcessingContext &context, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> &sourceProperties ) const
1211{
1213 if ( sink == QLatin1String( "OUTPUT" ) )
1214 {
1215 if ( sourceProperties.value( QStringLiteral( "INPUT" ) ).availability == Qgis::ProcessingPropertyAvailability::Available )
1216 {
1217 const VectorProperties inputProps = sourceProperties.value( QStringLiteral( "INPUT" ) );
1218 result.fields = outputFields( inputProps.fields );
1219 result.crs = outputCrs( inputProps.crs );
1220 result.wkbType = outputWkbType( inputProps.wkbType );
1222 return result;
1223 }
1224 else
1225 {
1226 std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
1227 if ( source )
1228 {
1229 result.fields = outputFields( source->fields() );
1230 result.crs = outputCrs( source->sourceCrs() );
1231 result.wkbType = outputWkbType( source->wkbType() );
1233 return result;
1234 }
1235 }
1236 }
1237 return result;
1238}
1239
ProcessingSourceType
Processing data source types.
Definition qgis.h:2836
@ 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:102
@ Static
Static property.
@ Available
Properties are available.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:255
@ Polygon
Polygons.
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:182
@ 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.
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.
@ 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:56
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:45
A geometry is the spatial representation of a feature.
Base class for graphical items within a QgsLayout.
Base class for all map layer types.
Definition qgsmaplayer.h:75
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:81
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...
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.
QVariantMap postProcess(QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Should be called in the main thread following the completion of runPrepared().
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...
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.
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.
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...
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
Definition qgsfeature.h:917
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.