QGIS API Documentation  3.17.0-Master (a84647cf30)
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 
18 #include "qgsprocessingalgorithm.h"
19 #include "qgsapplication.h"
20 #include "qgsprocessingprovider.h"
22 #include "qgsprocessingoutputs.h"
23 #include "qgsrectangle.h"
24 #include "qgsprocessingcontext.h"
25 #include "qgsprocessingutils.h"
26 #include "qgsexception.h"
27 #include "qgsmessagelog.h"
28 #include "qgsvectorlayer.h"
29 #include "qgsprocessingfeedback.h"
30 #include "qgsmeshlayer.h"
32 
33 
35 {
36  qDeleteAll( mParameters );
37  qDeleteAll( mOutputs );
38 }
39 
40 QgsProcessingAlgorithm *QgsProcessingAlgorithm::create( const QVariantMap &configuration ) const
41 {
42  std::unique_ptr< QgsProcessingAlgorithm > creation( createInstance() );
43  if ( ! creation )
44  throw QgsProcessingException( QObject::tr( "Error creating algorithm from createInstance()" ) );
45  creation->setProvider( provider() );
46  creation->initAlgorithm( configuration );
47  return creation.release();
48 }
49 
51 {
52  if ( mProvider )
53  return QStringLiteral( "%1:%2" ).arg( mProvider->id(), name() );
54  else
55  return name();
56 }
57 
59 {
60  return QString();
61 }
62 
64 {
65  return QString();
66 }
67 
69 {
70  return QString();
71 }
72 
74 {
75  return QString();
76 }
77 
79 {
80  return QgsApplication::getThemeIcon( "/processingAlgorithm.svg" );
81 }
82 
84 {
85  return QgsApplication::iconPath( QStringLiteral( "processingAlgorithm.svg" ) );
86 }
87 
88 QgsProcessingAlgorithm::Flags QgsProcessingAlgorithm::flags() const
89 {
91 }
92 
93 bool QgsProcessingAlgorithm::canExecute( QString * ) const
94 {
95  return true;
96 }
97 
98 bool QgsProcessingAlgorithm::checkParameterValues( const QVariantMap &parameters, QgsProcessingContext &context, QString *message ) const
99 {
100  for ( const QgsProcessingParameterDefinition *def : mParameters )
101  {
102  if ( !def->checkValueIsAcceptable( parameters.value( def->name() ), &context ) )
103  {
104  if ( message )
105  {
106  // TODO QGIS 4 - move the message handling to the parameter subclasses (but this
107  // requires a change in signature for the virtual checkValueIsAcceptable method)
108  if ( def->type() == QgsProcessingParameterFeatureSource::typeName() )
109  *message = invalidSourceError( parameters, def->name() );
110  else if ( def->type() == QgsProcessingParameterFeatureSink::typeName() )
111  *message = invalidSinkError( parameters, def->name() );
112  else if ( def->type() == QgsProcessingParameterRasterLayer::typeName() )
113  *message = invalidRasterError( parameters, def->name() );
114  else
115  *message = QObject::tr( "Incorrect parameter value for %1" ).arg( def->name() );
116  }
117  return false;
118  }
119  }
120  return true;
121 }
122 
123 QVariantMap QgsProcessingAlgorithm::preprocessParameters( const QVariantMap &parameters )
124 {
125  return parameters;
126 }
127 
129 {
130  return mProvider;
131 }
132 
134 {
135  mProvider = provider;
136 
137  if ( mProvider && !mProvider->supportsNonFileBasedOutput() )
138  {
139  // need to update all destination parameters to turn off non file based outputs
140  for ( const QgsProcessingParameterDefinition *definition : qgis::as_const( mParameters ) )
141  {
142  if ( definition->isDestination() )
143  {
144  const QgsProcessingDestinationParameter *destParam = static_cast< const QgsProcessingDestinationParameter *>( definition );
145  const_cast< QgsProcessingDestinationParameter *>( destParam )->setSupportsNonFileBasedOutput( false );
146  }
147  }
148  }
149 }
150 
152 {
153  return nullptr;
154 }
155 
157  QgsProcessingContext &context, QgsProcessingFeatureSource *source ) const
158 {
159  // start with context's expression context
161 
162  // If there's a source capable of generating a context scope, use it
163  if ( source )
164  {
166  if ( scope )
167  c << scope;
168  }
169  else if ( c.scopeCount() == 0 )
170  {
171  //empty scope, populate with initial scopes
174  }
175 
176  c << QgsExpressionContextUtils::processingAlgorithmScope( this, parameters, context );
177  return c;
178 }
179 
180 bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, QgsProcessingContext &context ) const
181 {
182  if ( !( flags() & FlagRequiresMatchingCrs ) )
183  {
184  // I'm a well behaved algorithm - I take work AWAY from users!
185  return true;
186  }
187 
188  bool foundCrs = false;
190  for ( const QgsProcessingParameterDefinition *def : mParameters )
191  {
193  {
194  QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( def, parameters, context );
195  if ( layer )
196  {
197  if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
198  {
199  return false;
200  }
201  else if ( !foundCrs && layer->crs().isValid() )
202  {
203  foundCrs = true;
204  crs = layer->crs();
205  }
206  }
207  }
208  else if ( def->type() == QgsProcessingParameterFeatureSource::typeName() )
209  {
210  std::unique_ptr< QgsFeatureSource > source( QgsProcessingParameters::parameterAsSource( def, parameters, context ) );
211  if ( source )
212  {
213  if ( foundCrs && source->sourceCrs().isValid() && crs != source->sourceCrs() )
214  {
215  return false;
216  }
217  else if ( !foundCrs && source->sourceCrs().isValid() )
218  {
219  foundCrs = true;
220  crs = source->sourceCrs();
221  }
222  }
223  }
224  else if ( def->type() == QgsProcessingParameterMultipleLayers::typeName() )
225  {
226  QList< QgsMapLayer *> layers = QgsProcessingParameters::parameterAsLayerList( def, parameters, context );
227  const auto constLayers = layers;
228  for ( QgsMapLayer *layer : constLayers )
229  {
230  if ( !layer )
231  continue;
232 
233  if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
234  {
235  return false;
236  }
237  else if ( !foundCrs && layer->crs().isValid() )
238  {
239  foundCrs = true;
240  crs = layer->crs();
241  }
242  }
243  }
244  else if ( def->type() == QgsProcessingParameterExtent::typeName() )
245  {
246  QgsCoordinateReferenceSystem extentCrs = QgsProcessingParameters::parameterAsExtentCrs( def, parameters, context );
247  if ( foundCrs && extentCrs.isValid() && crs != extentCrs )
248  {
249  return false;
250  }
251  else if ( !foundCrs && extentCrs.isValid() )
252  {
253  foundCrs = true;
254  crs = extentCrs;
255  }
256  }
257  else if ( def->type() == QgsProcessingParameterPoint::typeName() )
258  {
259  QgsCoordinateReferenceSystem pointCrs = QgsProcessingParameters::parameterAsPointCrs( def, parameters, context );
260  if ( foundCrs && pointCrs.isValid() && crs != pointCrs )
261  {
262  return false;
263  }
264  else if ( !foundCrs && pointCrs.isValid() )
265  {
266  foundCrs = true;
267  crs = pointCrs;
268  }
269  }
270  else if ( def->type() == QgsProcessingParameterGeometry::typeName() )
271  {
273  if ( foundCrs && geomCrs.isValid() && crs != geomCrs )
274  {
275  return false;
276  }
277  else if ( !foundCrs && geomCrs.isValid() )
278  {
279  foundCrs = true;
280  crs = geomCrs;
281  }
282  }
283 
284  }
285  return true;
286 }
287 
288 QString QgsProcessingAlgorithm::asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const
289 {
290  QString s = QStringLiteral( "processing.run(\"%1\"," ).arg( id() );
291 
292  QStringList parts;
293  for ( const QgsProcessingParameterDefinition *def : mParameters )
294  {
296  continue;
297 
298  if ( !parameters.contains( def->name() ) )
299  continue;
300 
301  parts << QStringLiteral( "'%1':%2" ).arg( def->name(), def->valueAsPythonString( parameters.value( def->name() ), context ) );
302  }
303 
304  s += QStringLiteral( " {%1})" ).arg( parts.join( ',' ) );
305  return s;
306 }
307 
309 {
310  if ( !definition )
311  return false;
312 
313  // check for duplicate named parameters
315  if ( existingDef && existingDef->name() == definition->name() ) // parameterDefinition is case-insensitive, but we DO allow case-different duplicate names
316  {
317  QgsMessageLog::logMessage( QObject::tr( "Duplicate parameter %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
318  delete definition;
319  return false;
320  }
321 
322  if ( definition->isDestination() && mProvider )
323  {
324  QgsProcessingDestinationParameter *destParam = static_cast< QgsProcessingDestinationParameter *>( definition );
325  if ( !mProvider->supportsNonFileBasedOutput() )
326  destParam->setSupportsNonFileBasedOutput( false );
327  }
328 
329  mParameters << definition;
330  definition->mAlgorithm = this;
331 
332  if ( createOutput )
333  return createAutoOutputForParameter( definition );
334  else
335  return true;
336 }
337 
339 {
341  if ( def )
342  {
343  delete def;
344  mParameters.removeAll( def );
345 
346  // remove output automatically created when adding parameter
348  if ( outputDef && outputDef->autoCreated() )
349  {
350  delete outputDef;
351  mOutputs.removeAll( outputDef );
352  }
353  }
354 }
355 
357 {
358  if ( !definition )
359  return false;
360 
361  // check for duplicate named outputs
362  if ( QgsProcessingAlgorithm::outputDefinition( definition->name() ) )
363  {
364  QgsMessageLog::logMessage( QObject::tr( "Duplicate output %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
365  delete definition;
366  return false;
367  }
368 
369  mOutputs << definition;
370  return true;
371 }
372 
374 {
375  return true;
376 }
377 
379 {
380  return QVariantMap();
381 }
382 
384 {
385  // first pass - case sensitive match
386  for ( const QgsProcessingParameterDefinition *def : mParameters )
387  {
388  if ( def->name() == name )
389  return def;
390  }
391 
392  // second pass - case insensitive
393  for ( const QgsProcessingParameterDefinition *def : mParameters )
394  {
395  if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
396  return def;
397  }
398  return nullptr;
399 }
400 
402 {
403  int count = 0;
404  for ( const QgsProcessingParameterDefinition *def : mParameters )
405  {
406  if ( !( def->flags() & QgsProcessingParameterDefinition::FlagHidden ) )
407  count++;
408  }
409  return count;
410 }
411 
413 {
415  for ( const QgsProcessingParameterDefinition *def : mParameters )
416  {
417  if ( def->isDestination() )
418  result << def;
419  }
420  return result;
421 }
422 
424 {
425  for ( const QgsProcessingOutputDefinition *def : mOutputs )
426  {
427  if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
428  return def;
429  }
430  return nullptr;
431 }
432 
434 {
435  for ( const QgsProcessingOutputDefinition *def : mOutputs )
436  {
437  if ( def->type() == QLatin1String( "outputHtml" ) )
438  return true;
439  }
440  return false;
441 }
442 
443 QgsProcessingAlgorithm::VectorProperties QgsProcessingAlgorithm::sinkProperties( const QString &, const QVariantMap &, QgsProcessingContext &, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> & ) const
444 {
445  return VectorProperties();
446 }
447 
448 QVariantMap QgsProcessingAlgorithm::run( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok, const QVariantMap &configuration, bool catchExceptions ) const
449 {
450  std::unique_ptr< QgsProcessingAlgorithm > alg( create( configuration ) );
451  if ( ok )
452  *ok = false;
453 
454  bool res = alg->prepare( parameters, context, feedback );
455  if ( !res )
456  return QVariantMap();
457 
458  QVariantMap runRes;
459  try
460  {
461  runRes = alg->runPrepared( parameters, context, feedback );
462  }
463  catch ( QgsProcessingException &e )
464  {
465  if ( !catchExceptions )
466  throw e;
467 
468  QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::Critical );
469  feedback->reportError( e.what() );
470  return QVariantMap();
471  }
472 
473  if ( ok )
474  *ok = true;
475 
476  QVariantMap ppRes = alg->postProcess( context, feedback );
477  if ( !ppRes.isEmpty() )
478  return ppRes;
479  else
480  return runRes;
481 }
482 
483 bool QgsProcessingAlgorithm::prepare( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
484 {
485  Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::prepare", "prepare() must be called from the same thread as context was created in" );
486  Q_ASSERT_X( !mHasPrepared, "QgsProcessingAlgorithm::prepare", "prepare() has already been called for the algorithm instance" );
487  try
488  {
489  mHasPrepared = prepareAlgorithm( parameters, context, feedback );
490  return mHasPrepared;
491  }
492  catch ( QgsProcessingException &e )
493  {
494  QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::Critical );
495  feedback->reportError( e.what() );
496  return false;
497  }
498 }
499 
500 QVariantMap QgsProcessingAlgorithm::runPrepared( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
501 {
502  Q_ASSERT_X( mHasPrepared, "QgsProcessingAlgorithm::runPrepared", QStringLiteral( "prepare() was not called for the algorithm instance %1" ).arg( name() ).toLatin1() );
503  Q_ASSERT_X( !mHasExecuted, "QgsProcessingAlgorithm::runPrepared", "runPrepared() was already called for this algorithm instance" );
504 
505  // Hey kids, let's all be thread safe! It's the fun thing to do!
506  //
507  // First, let's see if we're going to run into issues.
508  QgsProcessingContext *runContext = nullptr;
509  if ( context.thread() == QThread::currentThread() )
510  {
511  // OH. No issues. Seems you're running everything in the same thread, so go about your business. Sorry about
512  // the intrusion, we're just making sure everything's nice and safe here. We like to keep a clean and tidy neighbourhood,
513  // you know, for the kids and dogs and all.
514  runContext = &context;
515  }
516  else
517  {
518  // HA! I knew things looked a bit suspicious - seems you're running this algorithm in a different thread
519  // from that which the passed context has an affinity for. That's fine and all, but we need to make sure
520  // we proceed safely...
521 
522  // So first we create a temporary local context with affinity for the current thread
523  mLocalContext.reset( new QgsProcessingContext() );
524  // copy across everything we can safely do from the passed context
525  mLocalContext->copyThreadSafeSettings( context );
526  // and we'll run the actual algorithm processing using the local thread safe context
527  runContext = mLocalContext.get();
528  }
529 
530  try
531  {
532  QVariantMap runResults = processAlgorithm( parameters, *runContext, feedback );
533 
534  mHasExecuted = true;
535  if ( mLocalContext )
536  {
537  // ok, time to clean things up. We need to push the temporary context back into
538  // the thread that the passed context is associated with (we can only push from the
539  // current thread, so we HAVE to do this here)
540  mLocalContext->pushToThread( context.thread() );
541  }
542  return runResults;
543  }
544  catch ( QgsProcessingException & )
545  {
546  if ( mLocalContext )
547  {
548  // see above!
549  mLocalContext->pushToThread( context.thread() );
550  }
551  //rethrow
552  throw;
553  }
554 }
555 
557 {
558  Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::postProcess", "postProcess() must be called from the same thread the context was created in" );
559  Q_ASSERT_X( mHasExecuted, "QgsProcessingAlgorithm::postProcess", QStringLiteral( "algorithm instance %1 was not executed" ).arg( name() ).toLatin1() );
560  Q_ASSERT_X( !mHasPostProcessed, "QgsProcessingAlgorithm::postProcess", "postProcess() was already called for this algorithm instance" );
561 
562  if ( mLocalContext )
563  {
564  // algorithm was processed using a temporary thread safe context. So now we need
565  // to take the results from that temporary context, and smash them into the passed
566  // context
567  context.takeResultsFrom( *mLocalContext );
568  // now get lost, we don't need you anymore
569  mLocalContext.reset();
570  }
571 
572  mHasPostProcessed = true;
573  try
574  {
575  return postProcessAlgorithm( context, feedback );
576  }
577  catch ( QgsProcessingException &e )
578  {
579  QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::Critical );
580  feedback->reportError( e.what() );
581  return QVariantMap();
582  }
583 }
584 
585 QString QgsProcessingAlgorithm::parameterAsString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
586 {
587  return QgsProcessingParameters::parameterAsString( parameterDefinition( name ), parameters, context );
588 }
589 
590 QString QgsProcessingAlgorithm::parameterAsExpression( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
591 {
592  return QgsProcessingParameters::parameterAsExpression( parameterDefinition( name ), parameters, context );
593 }
594 
595 double QgsProcessingAlgorithm::parameterAsDouble( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
596 {
597  return QgsProcessingParameters::parameterAsDouble( parameterDefinition( name ), parameters, context );
598 }
599 
600 int QgsProcessingAlgorithm::parameterAsInt( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
601 {
602  return QgsProcessingParameters::parameterAsInt( parameterDefinition( name ), parameters, context );
603 }
604 
605 QList<int> QgsProcessingAlgorithm::parameterAsInts( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
606 {
607  return QgsProcessingParameters::parameterAsInts( parameterDefinition( name ), parameters, context );
608 }
609 
610 int QgsProcessingAlgorithm::parameterAsEnum( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
611 {
612  return QgsProcessingParameters::parameterAsEnum( parameterDefinition( name ), parameters, context );
613 }
614 
615 QList<int> QgsProcessingAlgorithm::parameterAsEnums( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
616 {
617  return QgsProcessingParameters::parameterAsEnums( parameterDefinition( name ), parameters, context );
618 }
619 
620 QString QgsProcessingAlgorithm::parameterAsEnumString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
621 {
622  return QgsProcessingParameters::parameterAsEnumString( parameterDefinition( name ), parameters, context );
623 }
624 
625 QStringList QgsProcessingAlgorithm::parameterAsEnumStrings( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
626 {
627  return QgsProcessingParameters::parameterAsEnumStrings( parameterDefinition( name ), parameters, context );
628 }
629 
630 bool QgsProcessingAlgorithm::parameterAsBool( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
631 {
632  return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
633 }
634 
635 bool QgsProcessingAlgorithm::parameterAsBoolean( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
636 {
637  return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
638 }
639 
640 QgsFeatureSink *QgsProcessingAlgorithm::parameterAsSink( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QString &destinationIdentifier, const QgsFields &fields, QgsWkbTypes::Type geometryType, const QgsCoordinateReferenceSystem &crs, QgsFeatureSink::SinkFlags sinkFlags, const QVariantMap &createOptions, const QStringList &datasourceOptions, const QStringList &layerOptions ) const
641 {
642  if ( !parameterDefinition( name ) )
643  throw QgsProcessingException( QObject::tr( "No parameter definition for the sink '%1'" ).arg( name ) );
644 
645  return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
646 }
647 
648 QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
649 {
650  return QgsProcessingParameters::parameterAsSource( parameterDefinition( name ), parameters, context );
651 }
652 
653 QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
654 {
655  return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback );
656 }
657 
658 QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPathAndLayerName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
659 {
660  return QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback, layerName );
661 }
662 
663 QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
664 {
665  return QgsProcessingParameters::parameterAsLayer( parameterDefinition( name ), parameters, context );
666 }
667 
668 QgsRasterLayer *QgsProcessingAlgorithm::parameterAsRasterLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
669 {
670  return QgsProcessingParameters::parameterAsRasterLayer( parameterDefinition( name ), parameters, context );
671 }
672 
673 QgsMeshLayer *QgsProcessingAlgorithm::parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
674 {
675  return QgsProcessingParameters::parameterAsMeshLayer( parameterDefinition( name ), parameters, context );
676 }
677 
678 QString QgsProcessingAlgorithm::parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
679 {
680  return QgsProcessingParameters::parameterAsOutputLayer( parameterDefinition( name ), parameters, context );
681 }
682 
683 QString QgsProcessingAlgorithm::parameterAsFileOutput( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
684 {
685  return QgsProcessingParameters::parameterAsFileOutput( parameterDefinition( name ), parameters, context );
686 }
687 
688 QgsVectorLayer *QgsProcessingAlgorithm::parameterAsVectorLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
689 {
690  return QgsProcessingParameters::parameterAsVectorLayer( parameterDefinition( name ), parameters, context );
691 }
692 
693 QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
694 {
695  return QgsProcessingParameters::parameterAsCrs( parameterDefinition( name ), parameters, context );
696 }
697 
699 {
700  return QgsProcessingParameters::parameterAsExtentCrs( parameterDefinition( name ), parameters, context );
701 }
702 
703 QgsRectangle QgsProcessingAlgorithm::parameterAsExtent( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
704 {
705  return QgsProcessingParameters::parameterAsExtent( parameterDefinition( name ), parameters, context, crs );
706 }
707 
709 {
710  return QgsProcessingParameters::parameterAsExtentGeometry( parameterDefinition( name ), parameters, context, crs );
711 }
712 
713 QgsPointXY QgsProcessingAlgorithm::parameterAsPoint( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
714 {
715  return QgsProcessingParameters::parameterAsPoint( parameterDefinition( name ), parameters, context, crs );
716 }
717 
719 {
720  return QgsProcessingParameters::parameterAsPointCrs( parameterDefinition( name ), parameters, context );
721 }
722 
723 QgsGeometry QgsProcessingAlgorithm::parameterAsGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
724 {
725  return QgsProcessingParameters::parameterAsGeometry( parameterDefinition( name ), parameters, context, crs );
726 }
727 
729 {
730  return QgsProcessingParameters::parameterAsGeometryCrs( parameterDefinition( name ), parameters, context );
731 }
732 
733 QString QgsProcessingAlgorithm::parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
734 {
735  return QgsProcessingParameters::parameterAsFile( parameterDefinition( name ), parameters, context );
736 }
737 
738 QVariantList QgsProcessingAlgorithm::parameterAsMatrix( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
739 {
740  return QgsProcessingParameters::parameterAsMatrix( parameterDefinition( name ), parameters, context );
741 }
742 
743 QList<QgsMapLayer *> QgsProcessingAlgorithm::parameterAsLayerList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
744 {
745  return QgsProcessingParameters::parameterAsLayerList( parameterDefinition( name ), parameters, context );
746 }
747 
748 QStringList QgsProcessingAlgorithm::parameterAsFileList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
749 {
750  return QgsProcessingParameters::parameterAsFileList( parameterDefinition( name ), parameters, context );
751 }
752 
753 QList<double> QgsProcessingAlgorithm::parameterAsRange( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
754 {
755  return QgsProcessingParameters::parameterAsRange( parameterDefinition( name ), parameters, context );
756 }
757 
758 QStringList QgsProcessingAlgorithm::parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
759 {
760  return QgsProcessingParameters::parameterAsFields( parameterDefinition( name ), parameters, context );
761 }
762 
763 QgsPrintLayout *QgsProcessingAlgorithm::parameterAsLayout( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
764 {
765  return QgsProcessingParameters::parameterAsLayout( parameterDefinition( name ), parameters, context );
766 }
767 
768 QgsLayoutItem *QgsProcessingAlgorithm::parameterAsLayoutItem( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsPrintLayout *layout )
769 {
770  return QgsProcessingParameters::parameterAsLayoutItem( parameterDefinition( name ), parameters, context, layout );
771 }
772 
773 QColor QgsProcessingAlgorithm::parameterAsColor( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
774 {
775  return QgsProcessingParameters::parameterAsColor( parameterDefinition( name ), parameters, context );
776 }
777 
778 QString QgsProcessingAlgorithm::parameterAsConnectionName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
779 {
780  return QgsProcessingParameters::parameterAsConnectionName( parameterDefinition( name ), parameters, context );
781 }
782 
783 QDateTime QgsProcessingAlgorithm::parameterAsDateTime( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
784 {
785  return QgsProcessingParameters::parameterAsDateTime( parameterDefinition( name ), parameters, context );
786 }
787 
788 QString QgsProcessingAlgorithm::parameterAsSchema( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
789 {
790  return QgsProcessingParameters::parameterAsSchema( parameterDefinition( name ), parameters, context );
791 }
792 
793 QString QgsProcessingAlgorithm::parameterAsDatabaseTableName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
794 {
795  return QgsProcessingParameters::parameterAsDatabaseTableName( parameterDefinition( name ), parameters, context );
796 }
797 
798 QString QgsProcessingAlgorithm::invalidSourceError( const QVariantMap &parameters, const QString &name )
799 {
800  if ( !parameters.contains( name ) )
801  return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
802  else
803  {
804  QVariant var = parameters.value( name );
805  if ( var.canConvert<QgsProcessingFeatureSourceDefinition>() )
806  {
808  var = fromVar.source;
809  }
810  else if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
811  {
813  var = fromVar.sink;
814  }
815  if ( var.canConvert<QgsProperty>() )
816  {
817  QgsProperty p = var.value< QgsProperty >();
819  {
820  var = p.staticValue();
821  }
822  }
823  if ( !var.toString().isEmpty() )
824  return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
825  else
826  return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
827  }
828 }
829 
830 QString QgsProcessingAlgorithm::invalidRasterError( const QVariantMap &parameters, const QString &name )
831 {
832  if ( !parameters.contains( name ) )
833  return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
834  else
835  {
836  QVariant var = parameters.value( name );
837  if ( var.canConvert<QgsProperty>() )
838  {
839  QgsProperty p = var.value< QgsProperty >();
841  {
842  var = p.staticValue();
843  }
844  }
845  if ( !var.toString().isEmpty() )
846  return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
847  else
848  return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
849  }
850 }
851 
852 QString QgsProcessingAlgorithm::invalidSinkError( const QVariantMap &parameters, const QString &name )
853 {
854  if ( !parameters.contains( name ) )
855  return QObject::tr( "Could not create destination layer for %1: no value specified for parameter" ).arg( name );
856  else
857  {
858  QVariant var = parameters.value( name );
859  if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
860  {
862  var = fromVar.sink;
863  }
864  if ( var.canConvert<QgsProperty>() )
865  {
866  QgsProperty p = var.value< QgsProperty >();
868  {
869  var = p.staticValue();
870  }
871  }
872  if ( !var.toString().isEmpty() )
873  return QObject::tr( "Could not create destination layer for %1: %2" ).arg( name, var.toString() );
874  else
875  return QObject::tr( "Could not create destination layer for %1: invalid value" ).arg( name );
876  }
877 }
878 
880 {
881  Q_UNUSED( layer )
882  return false;
883 }
884 
885 
886 bool QgsProcessingAlgorithm::createAutoOutputForParameter( QgsProcessingParameterDefinition *parameter )
887 {
888  if ( !parameter->isDestination() )
889  return true; // nothing created, but nothing went wrong - so return true
890 
891  QgsProcessingDestinationParameter *dest = static_cast< QgsProcessingDestinationParameter * >( parameter );
893  if ( !output )
894  return true; // nothing created - but nothing went wrong - so return true
895  output->setAutoCreated( true );
896 
897  if ( !addOutput( output ) )
898  {
899  // couldn't add output - probably a duplicate name
900  return false;
901  }
902  else
903  {
904  return true;
905  }
906 }
907 
908 
909 //
910 // QgsProcessingFeatureBasedAlgorithm
911 //
912 
913 QgsProcessingAlgorithm::Flags QgsProcessingFeatureBasedAlgorithm::flags() const
914 {
915  Flags f = QgsProcessingAlgorithm::flags();
917  return f;
918 }
919 
920 void QgsProcessingFeatureBasedAlgorithm::initAlgorithm( const QVariantMap &config )
921 {
922  addParameter( new QgsProcessingParameterFeatureSource( inputParameterName(), inputParameterDescription(), inputLayerTypes() ) );
923  initParameters( config );
924  addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), outputName(), outputLayerType(), QVariant(), false, true, true ) );
925 }
926 
928 {
929  return QStringLiteral( "INPUT" );
930 }
931 
933 {
934  return QObject::tr( "Input layer" );
935 }
936 
938 {
939  return QList<int>();
940 }
941 
943 {
945 }
946 
948 {
949  return static_cast<QgsProcessingFeatureSource::Flag>( 0 );
950 }
951 
952 QgsFeatureSink::SinkFlags QgsProcessingFeatureBasedAlgorithm::sinkFlags() const
953 {
954  return QgsFeatureSink::SinkFlags();
955 }
956 
958 {
959  return inputWkbType;
960 }
961 
963 {
964  return inputFields;
965 }
966 
968 {
969  return inputCrs;
970 }
971 
973 {
974 }
975 
977 {
978  if ( mSource )
979  return mSource->sourceCrs();
980  else
982 }
983 
984 QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
985 {
986  prepareSource( parameters, context );
987  QString dest;
988  std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest,
989  outputFields( mSource->fields() ),
990  outputWkbType( mSource->wkbType() ),
991  outputCrs( mSource->sourceCrs() ),
992  sinkFlags() ) );
993  if ( !sink )
994  throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );
995 
996  // prepare expression context for feature iteration
997  QgsExpressionContext prevContext = context.expressionContext();
998  QgsExpressionContext algContext = prevContext;
999 
1000  algContext.appendScopes( createExpressionContext( parameters, context, mSource.get() ).takeScopes() );
1001  context.setExpressionContext( algContext );
1002 
1003  long count = mSource->featureCount();
1004 
1005  QgsFeature f;
1006  QgsFeatureIterator it = mSource->getFeatures( request(), sourceFlags() );
1007 
1008  double step = count > 0 ? 100.0 / count : 1;
1009  int current = 0;
1010  while ( it.nextFeature( f ) )
1011  {
1012  if ( feedback->isCanceled() )
1013  {
1014  break;
1015  }
1016 
1017  context.expressionContext().setFeature( f );
1018  const QgsFeatureList transformed = processFeature( f, context, feedback );
1019  for ( QgsFeature transformedFeature : transformed )
1020  sink->addFeature( transformedFeature, QgsFeatureSink::FastInsert );
1021 
1022  feedback->setProgress( current * step );
1023  current++;
1024  }
1025 
1026  mSource.reset();
1027 
1028  // probably not necessary - context's aren't usually recycled, but can't hurt
1029  context.setExpressionContext( prevContext );
1030 
1031  QVariantMap outputs;
1032  outputs.insert( QStringLiteral( "OUTPUT" ), dest );
1033  return outputs;
1034 }
1035 
1037 {
1038  return QgsFeatureRequest();
1039 }
1040 
1042 {
1043  const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
1044  if ( !layer )
1045  return false;
1046 
1047  QgsWkbTypes::GeometryType inPlaceGeometryType = layer->geometryType();
1048  if ( !inputLayerTypes().empty() &&
1049  !inputLayerTypes().contains( QgsProcessing::TypeVector ) &&
1050  !inputLayerTypes().contains( QgsProcessing::TypeVectorAnyGeometry ) &&
1051  ( ( inPlaceGeometryType == QgsWkbTypes::PolygonGeometry && !inputLayerTypes().contains( QgsProcessing::TypeVectorPolygon ) ) ||
1052  ( inPlaceGeometryType == QgsWkbTypes::LineGeometry && !inputLayerTypes().contains( QgsProcessing::TypeVectorLine ) ) ||
1053  ( inPlaceGeometryType == QgsWkbTypes::PointGeometry && !inputLayerTypes().contains( QgsProcessing::TypeVectorPoint ) ) ) )
1054  return false;
1055 
1057  if ( inPlaceGeometryType == QgsWkbTypes::PointGeometry )
1058  type = QgsWkbTypes::Point;
1059  else if ( inPlaceGeometryType == QgsWkbTypes::LineGeometry )
1060  type = QgsWkbTypes::LineString;
1061  else if ( inPlaceGeometryType == QgsWkbTypes::PolygonGeometry )
1062  type = QgsWkbTypes::Polygon;
1063 
1064  if ( QgsWkbTypes::geometryType( outputWkbType( type ) ) != inPlaceGeometryType )
1065  return false;
1066 
1067  return true;
1068 }
1069 
1070 void QgsProcessingFeatureBasedAlgorithm::prepareSource( const QVariantMap &parameters, QgsProcessingContext &context )
1071 {
1072  if ( ! mSource )
1073  {
1074  mSource.reset( parameterAsSource( parameters, inputParameterName(), context ) );
1075  if ( !mSource )
1076  throw QgsProcessingException( invalidSourceError( parameters, inputParameterName() ) );
1077  }
1078 }
1079 
1080 
1081 QgsProcessingAlgorithm::VectorProperties QgsProcessingFeatureBasedAlgorithm::sinkProperties( const QString &sink, const QVariantMap &parameters, QgsProcessingContext &context, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> &sourceProperties ) const
1082 {
1084  if ( sink == QLatin1String( "OUTPUT" ) )
1085  {
1086  if ( sourceProperties.value( QStringLiteral( "INPUT" ) ).availability == QgsProcessingAlgorithm::Available )
1087  {
1088  const VectorProperties inputProps = sourceProperties.value( QStringLiteral( "INPUT" ) );
1089  result.fields = outputFields( inputProps.fields );
1090  result.crs = outputCrs( inputProps.crs );
1091  result.wkbType = outputWkbType( inputProps.wkbType );
1092  result.availability = Available;
1093  return result;
1094  }
1095  else
1096  {
1097  std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
1098  if ( source )
1099  {
1100  result.fields = outputFields( source->fields() );
1101  result.crs = outputCrs( source->sourceCrs() );
1102  result.wkbType = outputWkbType( source->wkbType() );
1103  result.availability = Available;
1104  return result;
1105  }
1106  }
1107  }
1108  return result;
1109 }
1110 
QgsProperty sink
Sink/layer definition.
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
QString parameterAsSchema(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a database schema name string.
virtual QgsFields outputFields(const QgsFields &inputFields) const
Maps the input source fields (inputFields) to corresponding output fields generated by the algorithm...
QList< const QgsProcessingParameterDefinition *> QgsProcessingParameterDefinitions
List of processing parameters.
void setProvider(QgsProcessingProvider *provider)
Associates this algorithm with its provider.
virtual bool prepareAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
Prepares the algorithm to run using the specified parameters.
QString parameterAsFile(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a file/folder name.
QgsProcessingFeatureSource * parameterAsSource(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a feature source.
virtual QString helpUrl() const
Returns a url pointing to the algorithm&#39;s help page.
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...
Wrapper for iterator of features from vector data provider or vector layer.
double parameterAsDouble(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static double value.
QVariantMap processAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) override SIP_THROW(QgsProcessingException)
Runs the algorithm using the specified parameters.
static QgsMapLayer * parameterAsLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingUtils::LayerHint layerHint=QgsProcessingUtils::LayerHint::UnknownType)
Evaluates the parameter with matching definition to a map layer.
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
QList< QgsMapLayer * > parameterAsLayerList(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of map layers.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:84
QgsCoordinateReferenceSystem parameterAsPointCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value. ...
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
QgsRasterLayer * parameterAsRasterLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a raster layer.
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
Properties of a vector source or sink used in an algorithm.
QString id() const
Returns the unique ID for the algorithm, which is a combination of the algorithm provider&#39;s ID and th...
virtual QIcon icon() const
Returns an icon for the algorithm.
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
virtual Q_DECL_DEPRECATED QString helpString() const
Returns a localised help string for the algorithm.
Base class for providing feedback from a processing algorithm.
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
Base class for graphical items within a QgsLayout.
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm...
int countVisibleParameters() const
Returns the number of visible (non-hidden) parameters defined by this algorithm.
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...
QVariantMap postProcess(QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Should be called in the main thread following the completion of runPrepared().
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 QgsExpressionContext createExpressionContext(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeatureSource *source=nullptr) const
Creates an expression context relating to the algorithm.
static QString typeName()
Returns the type name for the parameter class.
bool hasHtmlOutputs() const
Returns true if this algorithm generates HTML outputs.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Represents 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.
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:614
QVariantList parameterAsMatrix(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a matrix/table of values.
virtual QString name() const =0
Returns the algorithm name, used for identifying the algorithm.
QgsProcessingProvider * provider() const
Returns the provider to which this algorithm belongs.
QString name() const
Returns the name of the output.
A class to represent a 2D point.
Definition: qgspointxy.h:43
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source&#39;s coordinate reference system.
QList< int > parameterAsEnums(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to list of enum values.
static QString typeName()
Returns the type name for the parameter class.
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition: qgsfeedback.h:62
QColor parameterAsColor(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a color, or returns an invalid color if the parameter w...
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
virtual QString inputParameterName() const
Returns the name of the parameter corresponding to the input layer.
An interface for objects which accept features via addFeature(s) methods.
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. ...
QgsMeshLayer * parameterAsMeshLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a mesh layer.
QgsProcessingAlgorithm * mAlgorithm
Pointer to algorithm which owns this parameter.
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
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.
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users...
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource, modifying results according to the settings in a QgsProcessingContext.
Container of fields for a vector layer.
Definition: qgsfields.h:44
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:123
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QgsFeatureSink * parameterAsSink(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QString &destinationIdentifier, const QgsFields &fields, QgsWkbTypes::Type geometryType=QgsWkbTypes::NoGeometry, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem(), QgsFeatureSink::SinkFlags sinkFlags=QgsFeatureSink::SinkFlags(), const QVariantMap &createOptions=QVariantMap(), const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList()) const SIP_THROW(QgsProcessingException)
Evaluates the parameter with matching name to a feature sink.
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
QgsMapLayer * parameterAsLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a map layer.
Abstract base class for processing providers.
QgsProcessingAlgorithm::PropertyAvailability availability
Availability of the properties. By default properties are not available.
Algorithm requires that all input layers have matching coordinate reference systems.
QString parameterAsConnectionName(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a connection name string.
QThread * thread()
Returns the thread in which the context lives.
virtual bool supportsNonFileBasedOutput() const
Returns true if the provider supports non-file based outputs (such as memory layers or direct databas...
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...
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...
QStringList parameterAsFields(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of fields.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
QString parameterAsDatabaseTableName(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a database table name string.
QStringList parameterAsEnumStrings(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to list of static enum strings.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
const QgsCoordinateReferenceSystem & crs
virtual QList< int > inputLayerTypes() const
Returns the valid input layer types for the source layer for this algorithm.
virtual QString shortHelpString() const
Returns a localised short helper string for 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.
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
Base class for all parameter definitions which represent file or layer destinations, e.g.
Abstract base class for processing algorithms.
QgsCoordinateReferenceSystem parameterAsCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a coordinate reference system.
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 parameterAsFile(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file/folder name.
A feature sink output for processing algorithms.
QStringList parameterAsFileList(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of files (for QgsProcessingParameterMultipleLaye...
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of map layers.
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...
QgsProject * project() const
Returns the project in which the algorithm is being executed.
QVariantMap runPrepared(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
Runs the algorithm, which has been prepared by an earlier call to prepare().
QString what() const
Definition: qgsexception.h:48
static QString typeName()
Returns the type name for the parameter class.
virtual bool supportInPlaceEdit(const QgsMapLayer *layer) const
Checks whether this algorithm supports in-place editing on the given layer Default implementation ret...
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 QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
QgsProcessingParameterDefinitions destinationParameterDefinitions() const
Returns a list of destination parameters definitions utilized by the algorithm.
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.
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
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.
virtual QVariantMap preprocessParameters(const QVariantMap &parameters)
Pre-processes a set of parameters, allowing the algorithm to clean their values.
void removeParameter(const QString &name)
Removes the parameter with matching name from the algorithm, and deletes any existing definition...
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value. ...
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
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...
static QString typeName()
Returns the type name for the parameter class.
QgsMapLayerStore * temporaryLayerStore()
Returns a reference to the layer store used for storing temporary layers during algorithm execution...
QgsProperty source
Source definition.
Type propertyType() const
Returns the property type.
bool prepare(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm for execution.
QgsCoordinateReferenceSystem parameterAsExtentCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
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 QString id() const =0
Returns the unique provider id, used for identifying the provider.
int scopeCount() const
Returns the number of scopes contained in the context.
static QString typeName()
Returns the type name for the parameter class.
bool parameterAsBool(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static boolean value.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
virtual QVariantMap postProcessAlgorithm(QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
Allows the algorithm to perform any required cleanup tasks.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
void takeResultsFrom(QgsProcessingContext &context)
Takes the results from another context and merges them with the results currently stored in this cont...
virtual QgsWkbTypes::Type outputWkbType(QgsWkbTypes::Type inputWkbType) const
Maps the input WKB geometry type (inputWkbType) to the corresponding output WKB type generated by the...
virtual QgsFeatureRequest request() const
Returns the feature request used for fetching features to process from the source layer...
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
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...
Custom exception class for processing related exceptions.
Definition: qgsexception.h:82
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
Vector polygon layers.
Definition: qgsprocessing.h:50
QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter 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 QStringList parameterAsFileList(const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of files (for QgsProcessingParameterMultip...
QgsVectorLayer * parameterAsVectorLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a vector layer.
QString parameterAsString(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static string value.
static QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter value.
Single scope for storing variables and functions for use within a QgsExpressionContext.
int parameterAsInt(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static integer value.
A store for object properties.
Definition: qgsproperty.h:231
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 QgsProcessingAlgorithm * createInstance() const =0
Creates a new instance of the algorithm class.
QString parameterAsExpression(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to an expression.
QgsExpressionContext & expressionContext()
Returns the expression context.
const QgsProcessingParameterDefinition * parameterDefinition(const QString &name) const
Returns a matching parameter by name.
bool parameterAsBoolean(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static boolean value.
QgsGeometry parameterAsExtentGeometry(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching name to a rectangular extent, and returns a geometry covering t...
QVariantMap run(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok=nullptr, const QVariantMap &configuration=QVariantMap(), bool catchExceptions=true) const SIP_THROW(QgsProcessingException)
Executes the algorithm using the specified parameters.
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
QString name() const
Returns the name of the parameter.
QgsExpressionContextScope * createExpressionContextScope() const
Returns an expression context scope suitable for this source.
Encapsulates settings relating to a feature source input to a processing algorithm.
const QgsProcessingOutputDefinition * outputDefinition(const QString &name) const
Returns a matching output by name.
bool autoCreated() const
Returns true if the output was automatically created when adding a parameter.
void prepareSource(const QVariantMap &parameters, QgsProcessingContext &context)
Read the source from parameters and context and set it.
virtual bool isDestination() const
Returns true if this parameter represents a file or layer destination, e.g.
void setAutoCreated(bool autoCreated)
Sets whether an output was automatically created when adding a parameter.
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...
Base class for the definition of processing outputs.
QgsWkbTypes::Type wkbType
Geometry (WKB) type.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
virtual QgsFeatureSink::SinkFlags sinkFlags() const
Returns the feature sink flags to be used for the output.
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 processAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)=0
Runs the algorithm using the specified parameters.
QDateTime parameterAsDateTime(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a DateTime, or returns an invalid date time if the para...
static QgsMeshLayer * parameterAsMeshLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition and value to a mesh layer.
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition: qgsfeedback.h:53
bool addOutput(QgsProcessingOutputDefinition *outputDefinition)
Adds an output definition to the algorithm.
Vector point layers.
Definition: qgsprocessing.h:48
virtual bool canExecute(QString *errorMessage=nullptr) const
Returns true if the algorithm can execute.
QString parameterAsOutputLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a output layer destination.
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 QString typeName()
Returns the type name for the parameter class.
An input feature source (such as vector layers) parameter for processing algorithms.
This class represents a coordinate reference system (CRS).
virtual QString shortDescription() const
Returns an optional translated short description of the algorithm.
Base class for the definition of processing parameters.
Vector line layers.
Definition: qgsprocessing.h:49
virtual QgsProcessingFeatureSource::Flag sourceFlags() const
Returns the processing feature source flags to be used in the algorithm.
QVariant staticValue() const
Returns the current static value for the property.
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition: qgsprocessing.h:53
QgsPrintLayout * parameterAsLayout(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a print layout.
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
void initAlgorithm(const QVariantMap &configuration=QVariantMap()) override
Initializes the algorithm using the specified configuration.
SourceType
Data source types enum.
Definition: qgsprocessing.h:44
static QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
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. ...
const QgsCoordinateReferenceSystem & outputCrs
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 typeName()
Returns the type name for the parameter class.
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
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.
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation for...
virtual void initParameters(const QVariantMap &configuration=QVariantMap())
Initializes any extra parameters added by the algorithm subclass.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:94
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
virtual QString inputParameterDescription() const
Returns the translated description of the parameter corresponding to the input layer.
void setSupportsNonFileBasedOutput(bool supportsNonFileBasedOutput)
Sets whether the destination parameter supports non filed-based outputs, such as memory layers or dir...
static QString typeName()
Returns the type name for the parameter class.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
void appendScopes(const QList< QgsExpressionContextScope *> &scopes)
Appends a list of scopes to the end of the context.
Print layout, a QgsLayout subclass for static or atlas-based layouts.
QgsCoordinateReferenceSystem crs
Coordinate Reference System.
bool nextFeature(QgsFeature &f)
QString parameterAsCompatibleSourceLayerPath(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr)
Evaluates the parameter with matching name to a source vector layer file path of compatible format...
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...
Parameter is hidden and should not be shown to users.
bool addParameter(QgsProcessingParameterDefinition *parameterDefinition, bool createOutput=true)
Adds a parameter definition to the algorithm.
QString parameterAsCompatibleSourceLayerPathAndLayerName(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr, QString *layerName=nullptr)
Evaluates the parameter with matching name to a source vector layer file path and layer name of compa...
QList< double > parameterAsRange(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a range of values.
Represents a vector layer which manages a vector based data sets.
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
static QgsFeatureSink * parameterAsSink(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsFields &fields, QgsWkbTypes::Type 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 property (QgsStaticProperty)
Definition: qgsproperty.h:239
Contains information about the context in which a processing algorithm is executed.
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 ...
QgsProcessingAlgorithm::Flags flags() const override
Returns the flags indicating how and when the algorithm operates and should be exposed to users...
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
virtual QgsProcessingOutputDefinition * toOutputDefinition() const =0
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
Any vector layer with geometry.
Definition: qgsprocessing.h:47
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 GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Definition: qgswkbtypes.h:938
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:91
virtual QgsCoordinateReferenceSystem outputCrs(const QgsCoordinateReferenceSystem &inputCrs) const
Maps the input source coordinate reference system (inputCrs) to a corresponding output CRS generated ...
virtual QgsProcessing::SourceType outputLayerType() const
Returns the layer type for layers generated by this algorithm, if this is possible to determine in ad...
virtual QString svgIconPath() const
Returns a path to an SVG version of the algorithm&#39;s icon.
QString parameterAsFileOutput(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a file based output destination.
QgsProcessingAlgorithm * create(const QVariantMap &configuration=QVariantMap()) const SIP_THROW(QgsProcessingException)
Creates a copy of the algorithm, ready for execution.
int parameterAsEnum(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a enum value.
static QString parameterAsFileOutput(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file based output destination.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
static QStringList parameterAsFields(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of fields.