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