QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
338 void QgsProcessingAlgorithm::removeParameter( const QString &name )
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 {
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 bool QgsProcessingAlgorithm::parameterAsBool( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
621 {
622  return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
623 }
624 
625 bool QgsProcessingAlgorithm::parameterAsBoolean( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
626 {
627  return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
628 }
629 
630 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
631 {
632  if ( !parameterDefinition( name ) )
633  throw QgsProcessingException( QObject::tr( "No parameter definition for the sink '%1'" ).arg( name ) );
634 
635  return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
636 }
637 
638 QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
639 {
640  return QgsProcessingParameters::parameterAsSource( parameterDefinition( name ), parameters, context );
641 }
642 
643 QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
644 {
645  return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback );
646 }
647 
648 QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPathAndLayerName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
649 {
650  return QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback, layerName );
651 }
652 
653 QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
654 {
655  return QgsProcessingParameters::parameterAsLayer( parameterDefinition( name ), parameters, context );
656 }
657 
658 QgsRasterLayer *QgsProcessingAlgorithm::parameterAsRasterLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
659 {
661 }
662 
663 QgsMeshLayer *QgsProcessingAlgorithm::parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
664 {
666 }
667 
668 QString QgsProcessingAlgorithm::parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
669 {
671 }
672 
673 QString QgsProcessingAlgorithm::parameterAsFileOutput( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
674 {
676 }
677 
678 QgsVectorLayer *QgsProcessingAlgorithm::parameterAsVectorLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
679 {
681 }
682 
683 QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
684 {
685  return QgsProcessingParameters::parameterAsCrs( parameterDefinition( name ), parameters, context );
686 }
687 
688 QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsExtentCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
689 {
691 }
692 
693 QgsRectangle QgsProcessingAlgorithm::parameterAsExtent( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
694 {
695  return QgsProcessingParameters::parameterAsExtent( parameterDefinition( name ), parameters, context, crs );
696 }
697 
698 QgsGeometry QgsProcessingAlgorithm::parameterAsExtentGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs )
699 {
701 }
702 
703 QgsPointXY QgsProcessingAlgorithm::parameterAsPoint( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
704 {
705  return QgsProcessingParameters::parameterAsPoint( parameterDefinition( name ), parameters, context, crs );
706 }
707 
708 QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsPointCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
709 {
711 }
712 
713 QgsGeometry QgsProcessingAlgorithm::parameterAsGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
714 {
716 }
717 
718 QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsGeometryCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
719 {
721 }
722 
723 QString QgsProcessingAlgorithm::parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
724 {
725  return QgsProcessingParameters::parameterAsFile( parameterDefinition( name ), parameters, context );
726 }
727 
728 QVariantList QgsProcessingAlgorithm::parameterAsMatrix( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
729 {
730  return QgsProcessingParameters::parameterAsMatrix( parameterDefinition( name ), parameters, context );
731 }
732 
733 QList<QgsMapLayer *> QgsProcessingAlgorithm::parameterAsLayerList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
734 {
736 }
737 
738 QStringList QgsProcessingAlgorithm::parameterAsFileList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
739 {
741 }
742 
743 QList<double> QgsProcessingAlgorithm::parameterAsRange( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
744 {
745  return QgsProcessingParameters::parameterAsRange( parameterDefinition( name ), parameters, context );
746 }
747 
748 QStringList QgsProcessingAlgorithm::parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
749 {
750  return QgsProcessingParameters::parameterAsFields( parameterDefinition( name ), parameters, context );
751 }
752 
753 QgsPrintLayout *QgsProcessingAlgorithm::parameterAsLayout( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
754 {
755  return QgsProcessingParameters::parameterAsLayout( parameterDefinition( name ), parameters, context );
756 }
757 
758 QgsLayoutItem *QgsProcessingAlgorithm::parameterAsLayoutItem( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsPrintLayout *layout )
759 {
760  return QgsProcessingParameters::parameterAsLayoutItem( parameterDefinition( name ), parameters, context, layout );
761 }
762 
763 QColor QgsProcessingAlgorithm::parameterAsColor( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
764 {
765  return QgsProcessingParameters::parameterAsColor( parameterDefinition( name ), parameters, context );
766 }
767 
768 QString QgsProcessingAlgorithm::parameterAsConnectionName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
769 {
771 }
772 
773 QDateTime QgsProcessingAlgorithm::parameterAsDateTime( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
774 {
776 }
777 
778 QString QgsProcessingAlgorithm::parameterAsSchema( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
779 {
780  return QgsProcessingParameters::parameterAsSchema( parameterDefinition( name ), parameters, context );
781 }
782 
783 QString QgsProcessingAlgorithm::parameterAsDatabaseTableName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
784 {
786 }
787 
788 QString QgsProcessingAlgorithm::invalidSourceError( const QVariantMap &parameters, const QString &name )
789 {
790  if ( !parameters.contains( name ) )
791  return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
792  else
793  {
794  QVariant var = parameters.value( name );
795  if ( var.canConvert<QgsProcessingFeatureSourceDefinition>() )
796  {
797  QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
798  var = fromVar.source;
799  }
800  else if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
801  {
802  QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
803  var = fromVar.sink;
804  }
805  if ( var.canConvert<QgsProperty>() )
806  {
807  QgsProperty p = var.value< QgsProperty >();
809  {
810  var = p.staticValue();
811  }
812  }
813  if ( !var.toString().isEmpty() )
814  return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
815  else
816  return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
817  }
818 }
819 
820 QString QgsProcessingAlgorithm::invalidRasterError( const QVariantMap &parameters, const QString &name )
821 {
822  if ( !parameters.contains( name ) )
823  return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
824  else
825  {
826  QVariant var = parameters.value( name );
827  if ( var.canConvert<QgsProperty>() )
828  {
829  QgsProperty p = var.value< QgsProperty >();
831  {
832  var = p.staticValue();
833  }
834  }
835  if ( !var.toString().isEmpty() )
836  return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
837  else
838  return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
839  }
840 }
841 
842 QString QgsProcessingAlgorithm::invalidSinkError( const QVariantMap &parameters, const QString &name )
843 {
844  if ( !parameters.contains( name ) )
845  return QObject::tr( "Could not create destination layer for %1: no value specified for parameter" ).arg( name );
846  else
847  {
848  QVariant var = parameters.value( name );
849  if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
850  {
851  QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
852  var = fromVar.sink;
853  }
854  if ( var.canConvert<QgsProperty>() )
855  {
856  QgsProperty p = var.value< QgsProperty >();
858  {
859  var = p.staticValue();
860  }
861  }
862  if ( !var.toString().isEmpty() )
863  return QObject::tr( "Could not create destination layer for %1: %2" ).arg( name, var.toString() );
864  else
865  return QObject::tr( "Could not create destination layer for %1: invalid value" ).arg( name );
866  }
867 }
868 
870 {
871  Q_UNUSED( layer )
872  return false;
873 }
874 
875 
876 bool QgsProcessingAlgorithm::createAutoOutputForParameter( QgsProcessingParameterDefinition *parameter )
877 {
878  if ( !parameter->isDestination() )
879  return true; // nothing created, but nothing went wrong - so return true
880 
881  QgsProcessingDestinationParameter *dest = static_cast< QgsProcessingDestinationParameter * >( parameter );
883  if ( !output )
884  return true; // nothing created - but nothing went wrong - so return true
885  output->setAutoCreated( true );
886 
887  if ( !addOutput( output ) )
888  {
889  // couldn't add output - probably a duplicate name
890  return false;
891  }
892  else
893  {
894  return true;
895  }
896 }
897 
898 
899 //
900 // QgsProcessingFeatureBasedAlgorithm
901 //
902 
903 QgsProcessingAlgorithm::Flags QgsProcessingFeatureBasedAlgorithm::flags() const
904 {
905  Flags f = QgsProcessingAlgorithm::flags();
907  return f;
908 }
909 
910 void QgsProcessingFeatureBasedAlgorithm::initAlgorithm( const QVariantMap &config )
911 {
913  initParameters( config );
914  addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), outputName(), outputLayerType(), QVariant(), false, true, true ) );
915 }
916 
918 {
919  return QStringLiteral( "INPUT" );
920 }
921 
923 {
924  return QObject::tr( "Input layer" );
925 }
926 
928 {
929  return QList<int>();
930 }
931 
933 {
935 }
936 
938 {
939  return static_cast<QgsProcessingFeatureSource::Flag>( 0 );
940 }
941 
942 QgsFeatureSink::SinkFlags QgsProcessingFeatureBasedAlgorithm::sinkFlags() const
943 {
944  return QgsFeatureSink::SinkFlags();
945 }
946 
948 {
949  return inputWkbType;
950 }
951 
953 {
954  return inputFields;
955 }
956 
958 {
959  return inputCrs;
960 }
961 
963 {
964 }
965 
967 {
968  if ( mSource )
969  return mSource->sourceCrs();
970  else
972 }
973 
974 QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
975 {
976  prepareSource( parameters, context );
977  QString dest;
978  std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest,
979  outputFields( mSource->fields() ),
980  outputWkbType( mSource->wkbType() ),
981  outputCrs( mSource->sourceCrs() ),
982  sinkFlags() ) );
983  if ( !sink )
984  throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );
985 
986  // prepare expression context for feature iteration
987  QgsExpressionContext prevContext = context.expressionContext();
988  QgsExpressionContext algContext = prevContext;
989 
990  algContext.appendScopes( createExpressionContext( parameters, context, mSource.get() ).takeScopes() );
991  context.setExpressionContext( algContext );
992 
993  long count = mSource->featureCount();
994 
995  QgsFeature f;
996  QgsFeatureIterator it = mSource->getFeatures( request(), sourceFlags() );
997 
998  double step = count > 0 ? 100.0 / count : 1;
999  int current = 0;
1000  while ( it.nextFeature( f ) )
1001  {
1002  if ( feedback->isCanceled() )
1003  {
1004  break;
1005  }
1006 
1007  context.expressionContext().setFeature( f );
1008  const QgsFeatureList transformed = processFeature( f, context, feedback );
1009  for ( QgsFeature transformedFeature : transformed )
1010  sink->addFeature( transformedFeature, QgsFeatureSink::FastInsert );
1011 
1012  feedback->setProgress( current * step );
1013  current++;
1014  }
1015 
1016  mSource.reset();
1017 
1018  // probably not necessary - context's aren't usually recycled, but can't hurt
1019  context.setExpressionContext( prevContext );
1020 
1021  QVariantMap outputs;
1022  outputs.insert( QStringLiteral( "OUTPUT" ), dest );
1023  return outputs;
1024 }
1025 
1027 {
1028  return QgsFeatureRequest();
1029 }
1030 
1032 {
1033  const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
1034  if ( !layer )
1035  return false;
1036 
1037  QgsWkbTypes::GeometryType inPlaceGeometryType = layer->geometryType();
1038  if ( !inputLayerTypes().empty() &&
1039  !inputLayerTypes().contains( QgsProcessing::TypeVector ) &&
1041  ( ( inPlaceGeometryType == QgsWkbTypes::PolygonGeometry && !inputLayerTypes().contains( QgsProcessing::TypeVectorPolygon ) ) ||
1042  ( inPlaceGeometryType == QgsWkbTypes::LineGeometry && !inputLayerTypes().contains( QgsProcessing::TypeVectorLine ) ) ||
1043  ( inPlaceGeometryType == QgsWkbTypes::PointGeometry && !inputLayerTypes().contains( QgsProcessing::TypeVectorPoint ) ) ) )
1044  return false;
1045 
1047  if ( inPlaceGeometryType == QgsWkbTypes::PointGeometry )
1048  type = QgsWkbTypes::Point;
1049  else if ( inPlaceGeometryType == QgsWkbTypes::LineGeometry )
1050  type = QgsWkbTypes::LineString;
1051  else if ( inPlaceGeometryType == QgsWkbTypes::PolygonGeometry )
1052  type = QgsWkbTypes::Polygon;
1053 
1054  if ( QgsWkbTypes::geometryType( outputWkbType( type ) ) != inPlaceGeometryType )
1055  return false;
1056 
1057  return true;
1058 }
1059 
1060 void QgsProcessingFeatureBasedAlgorithm::prepareSource( const QVariantMap &parameters, QgsProcessingContext &context )
1061 {
1062  if ( ! mSource )
1063  {
1064  mSource.reset( parameterAsSource( parameters, inputParameterName(), context ) );
1065  if ( !mSource )
1067  }
1068 }
1069 
1070 
1071 QgsProcessingAlgorithm::VectorProperties QgsProcessingFeatureBasedAlgorithm::sinkProperties( const QString &sink, const QVariantMap &parameters, QgsProcessingContext &context, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> &sourceProperties ) const
1072 {
1074  if ( sink == QLatin1String( "OUTPUT" ) )
1075  {
1076  if ( sourceProperties.value( QStringLiteral( "INPUT" ) ).availability == QgsProcessingAlgorithm::Available )
1077  {
1078  const VectorProperties inputProps = sourceProperties.value( QStringLiteral( "INPUT" ) );
1079  result.fields = outputFields( inputProps.fields );
1080  result.crs = outputCrs( inputProps.crs );
1081  result.wkbType = outputWkbType( inputProps.wkbType );
1082  result.availability = Available;
1083  return result;
1084  }
1085  else
1086  {
1087  std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
1088  if ( source )
1089  {
1090  result.fields = outputFields( source->fields() );
1091  result.crs = outputCrs( source->sourceCrs() );
1092  result.wkbType = outputWkbType( source->wkbType() );
1093  result.availability = Available;
1094  return result;
1095  }
1096  }
1097  }
1098  return result;
1099 }
1100 
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsMapLayer::crs
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:89
QgsProcessingAlgorithm::shortDescription
virtual QString shortDescription() const
Returns an optional translated short description of the algorithm.
Definition: qgsprocessingalgorithm.cpp:58
QgsProcessingDestinationParameter::toOutputDefinition
virtual QgsProcessingOutputDefinition * toOutputDefinition() const =0
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
qgsexpressioncontextutils.h
QgsFeedback::setProgress
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition: qgsfeedback.h:62
QgsProcessingParameters::parameterAsMatrix
static QVariantList parameterAsMatrix(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a matrix/table of values.
Definition: qgsprocessingparameters.cpp:1619
QgsExpressionContext::appendScopes
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Definition: qgsexpressioncontext.cpp:495
QgsProcessingParameters::parameterAsCompatibleSourceLayerPath
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...
Definition: qgsprocessingparameters.cpp:741
QgsProcessingAlgorithm::prepare
bool prepare(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm for execution.
Definition: qgsprocessingalgorithm.cpp:483
QgsProcessingAlgorithm::removeParameter
void removeParameter(const QString &name)
Removes the parameter with matching name from the algorithm, and deletes any existing definition.
Definition: qgsprocessingalgorithm.cpp:338
QgsProcessingParameters::parameterAsCrs
static QgsCoordinateReferenceSystem parameterAsCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a coordinate reference system.
Definition: qgsprocessingparameters.cpp:956
QgsProcessingAlgorithm::parameterAsFileList
QStringList parameterAsFileList(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of files (for QgsProcessingParameterMultipleLaye...
Definition: qgsprocessingalgorithm.cpp:738
QgsProcessingParameters::parameterAsConnectionName
static QString parameterAsConnectionName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a connection name string.
Definition: qgsprocessingparameters.cpp:2028
QgsProcessingAlgorithm::invalidSourceError
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.
Definition: qgsprocessingalgorithm.cpp:788
QgsProcessingAlgorithm::parameterAsLayout
QgsPrintLayout * parameterAsLayout(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a print layout.
Definition: qgsprocessingalgorithm.cpp:753
QgsProperty
A store for object properties.
Definition: qgsproperty.h:232
QgsProcessingAlgorithm::canExecute
virtual bool canExecute(QString *errorMessage=nullptr) const
Returns true if the algorithm can execute.
Definition: qgsprocessingalgorithm.cpp:93
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Definition: qgsapplication.cpp:626
QgsWkbTypes::Point
@ Point
Definition: qgswkbtypes.h:72
QgsProcessingAlgorithm::parameterAsExtentCrs
QgsCoordinateReferenceSystem parameterAsExtentCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
Definition: qgsprocessingalgorithm.cpp:688
QgsProcessingParameterDefinition::mAlgorithm
QgsProcessingAlgorithm * mAlgorithm
Pointer to algorithm which owns this parameter.
Definition: qgsprocessingparameters.h:739
QgsProcessingFeatureBasedAlgorithm::prepareSource
void prepareSource(const QVariantMap &parameters, QgsProcessingContext &context)
Read the source from parameters and context and set it.
Definition: qgsprocessingalgorithm.cpp:1060
QgsExpressionContextUtils::globalScope
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Definition: qgsexpressioncontextutils.cpp:34
QgsProcessingParameters::parameterAsEnums
static QList< int > parameterAsEnums(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of enum values.
Definition: qgsprocessingparameters.cpp:445
qgsrectangle.h
QgsProcessingParameters::parameterAsGeometry
static QgsGeometry parameterAsGeometry(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a geometry.
Definition: qgsprocessingparameters.cpp:1420
QgsProcessingContext::project
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Definition: qgsprocessingcontext.h:105
QgsProcessingAlgorithm::VectorProperties::fields
QgsFields fields
Fields.
Definition: qgsprocessingalgorithm.h:338
QgsProcessingProvider::id
virtual QString id() const =0
Returns the unique provider id, used for identifying the provider.
QgsProcessingAlgorithm::VectorProperties::crs
QgsCoordinateReferenceSystem crs
Coordinate Reference System.
Definition: qgsprocessingalgorithm.h:344
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition: qgsprocessingfeedback.h:38
QgsProcessingFeatureBasedAlgorithm::outputWkbType
virtual QgsWkbTypes::Type outputWkbType(QgsWkbTypes::Type inputWkbType) const
Maps the input WKB geometry type (inputWkbType) to the corresponding output WKB type generated by the...
Definition: qgsprocessingalgorithm.cpp:947
QgsProcessingParameters::parameterAsDatabaseTableName
static QString parameterAsDatabaseTableName(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database table name.
Definition: qgsprocessingparameters.cpp:2058
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
QgsProcessingParameters::parameterAsFields
static QStringList parameterAsFields(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of fields.
Definition: qgsprocessingparameters.cpp:1873
QgsProcessingAlgorithm::parameterAsInts
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.
Definition: qgsprocessingalgorithm.cpp:605
QgsProcessingFeedback::reportError
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
Definition: qgsprocessingfeedback.cpp:39
QgsProcessing::TypeVectorPolygon
@ TypeVectorPolygon
Vector polygon layers.
Definition: qgsprocessing.h:50
QgsProcessingFeatureSource::createExpressionContextScope
QgsExpressionContextScope * createExpressionContextScope() const
Returns an expression context scope suitable for this source.
Definition: qgsprocessingutils.cpp:1342
QgsWkbTypes::LineString
@ LineString
Definition: qgswkbtypes.h:73
QgsProcessingAlgorithm::addParameter
bool addParameter(QgsProcessingParameterDefinition *parameterDefinition, bool createOutput=true)
Adds a parameter definition to the algorithm.
Definition: qgsprocessingalgorithm.cpp:308
QgsProcessingAlgorithm::parameterAsVectorLayer
QgsVectorLayer * parameterAsVectorLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a vector layer.
Definition: qgsprocessingalgorithm.cpp:678
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:45
QgsProcessingFeatureBasedAlgorithm::inputParameterDescription
virtual QString inputParameterDescription() const
Returns the translated description of the parameter corresponding to the input layer.
Definition: qgsprocessingalgorithm.cpp:922
QgsProcessingParameters::parameterAsLayer
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.
Definition: qgsprocessingparameters.cpp:759
QgsProcessingProvider
Abstract base class for processing providers.
Definition: qgsprocessingprovider.h:35
QgsProcessingParameters::parameterAsExtentCrs
static QgsCoordinateReferenceSystem parameterAsExtentCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an extent parameter value.
Definition: qgsprocessingparameters.cpp:1220
QgsProcessingFeatureBasedAlgorithm::initParameters
virtual void initParameters(const QVariantMap &configuration=QVariantMap())
Initializes any extra parameters added by the algorithm subclass.
Definition: qgsprocessingalgorithm.cpp:962
QgsProcessingParameterGeometry::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:1649
QgsProcessingContext::thread
QThread * thread()
Returns the thread in which the context lives.
Definition: qgsprocessingcontext.h:492
QgsProcessingParameterMultipleLayers::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:1891
QgsProcessingAlgorithm::createInstance
virtual QgsProcessingAlgorithm * createInstance() const =0
Creates a new instance of the algorithm class.
QgsProcessingParameterDefinition
Base class for the definition of processing parameters.
Definition: qgsprocessingparameters.h:331
QgsProcessing::TypeVectorLine
@ TypeVectorLine
Vector line layers.
Definition: qgsprocessing.h:49
QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath
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.
Definition: qgsprocessingalgorithm.cpp:643
QgsProcessingAlgorithm::svgIconPath
virtual QString svgIconPath() const
Returns a path to an SVG version of the algorithm's icon.
Definition: qgsprocessingalgorithm.cpp:83
QgsProcessingParameterFeatureSource
An input feature source (such as vector layers) parameter for processing algorithms.
Definition: qgsprocessingparameters.h:2734
QgsProcessingAlgorithm::parameterAsExtentGeometry
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...
Definition: qgsprocessingalgorithm.cpp:698
QgsProcessingOutputLayerDefinition
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
Definition: qgsprocessingparameters.h:200
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
QgsProcessingAlgorithm::run
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.
Definition: qgsprocessingalgorithm.cpp:448
QgsProcessingAlgorithm::validateInputCrs
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...
Definition: qgsprocessingalgorithm.cpp:180
QgsProperty::propertyType
Type propertyType() const
Returns the property type.
Definition: qgsproperty.cpp:261
QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation for...
Definition: qgsprocessingalgorithm.cpp:1031
QgsProcessingAlgorithm::prepareAlgorithm
virtual bool prepareAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
Prepares the algorithm to run using the specified parameters.
Definition: qgsprocessingalgorithm.cpp:373
QgsProcessingAlgorithm::parameterAsEnum
int parameterAsEnum(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a enum value.
Definition: qgsprocessingalgorithm.cpp:610
QgsApplication::iconPath
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
Definition: qgsapplication.cpp:615
QgsProcessingAlgorithm::parameterAsString
QString parameterAsString(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static string value.
Definition: qgsprocessingalgorithm.cpp:585
QgsProcessing::TypeVectorPoint
@ TypeVectorPoint
Vector point layers.
Definition: qgsprocessing.h:48
QgsProcessingParameters::parameterAsSchema
static QString parameterAsSchema(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a database schema name.
Definition: qgsprocessingparameters.cpp:2043
QgsProcessingParameters::parameterAsRasterLayer
static QgsRasterLayer * parameterAsRasterLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a raster layer.
Definition: qgsprocessingparameters.cpp:816
QgsProcessingFeatureSourceDefinition::source
QgsProperty source
Source definition.
Definition: qgsprocessingparameters.h:117
QgsProcessingAlgorithm::outputDefinition
const QgsProcessingOutputDefinition * outputDefinition(const QString &name) const
Returns a matching output by name.
Definition: qgsprocessingalgorithm.cpp:423
QgsProcessingAlgorithm::checkParameterValues
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...
Definition: qgsprocessingalgorithm.cpp:98
QgsExpressionContext::takeScopes
QList< QgsExpressionContextScope * > takeScopes()
Returns all scopes from this context and remove them, leaving this context without any context.
Definition: qgsexpressioncontext.cpp:508
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsProcessingAlgorithm::parameterAsDouble
double parameterAsDouble(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static double value.
Definition: qgsprocessingalgorithm.cpp:595
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:144
QgsProcessingFeatureBasedAlgorithm::sinkFlags
virtual QgsFeatureSink::SinkFlags sinkFlags() const
Returns the feature sink flags to be used for the output.
Definition: qgsprocessingalgorithm.cpp:942
QgsProperty::value
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...
Definition: qgsproperty.cpp:519
QgsProcessingAlgorithm::Available
@ Available
Properties are available.
Definition: qgsprocessingalgorithm.h:327
QgsProcessingParameterDefinitions
QList< const QgsProcessingParameterDefinition * > QgsProcessingParameterDefinitions
List of processing parameters.
Definition: qgsprocessingparameters.h:761
QgsProcessingAlgorithm::parameterAsPointCrs
QgsCoordinateReferenceSystem parameterAsPointCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
Definition: qgsprocessingalgorithm.cpp:708
QgsProcessingFeatureBasedAlgorithm::sourceFlags
virtual QgsProcessingFeatureSource::Flag sourceFlags() const
Returns the processing feature source flags to be used in the algorithm.
Definition: qgsprocessingalgorithm.cpp:937
QgsProcessingParameterFeatureSink::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:2910
QgsProcessingAlgorithm::parameterAsBoolean
bool parameterAsBoolean(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static boolean value.
Definition: qgsprocessingalgorithm.cpp:625
QgsProcessingDestinationParameter::setSupportsNonFileBasedOutput
void setSupportsNonFileBasedOutput(bool supportsNonFileBasedOutput)
Sets whether the destination parameter supports non filed-based outputs, such as memory layers or dir...
Definition: qgsprocessingparameters.h:2810
QgsProcessingAlgorithm::parameterAsSchema
QString parameterAsSchema(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a database schema name string.
Definition: qgsprocessingalgorithm.cpp:778
QgsProcessingParameterFeatureSink
A feature sink output for processing algorithms.
Definition: qgsprocessingparameters.h:2895
QgsProcessingParameters::parameterAsRange
static QList< double > parameterAsRange(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a range of values.
Definition: qgsprocessingparameters.cpp:1807
QgsProcessingDestinationParameter
Base class for all parameter definitions which represent file or layer destinations,...
Definition: qgsprocessingparameters.h:2774
qgsapplication.h
QgsProcessingParameters::parameterAsFile
static QString parameterAsFile(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file/folder name.
Definition: qgsprocessingparameters.cpp:1597
QgsProcessingAlgorithm::parameterAsOutputLayer
QString parameterAsOutputLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a output layer destination.
Definition: qgsprocessingalgorithm.cpp:668
QgsProcessingOutputDefinition
Base class for the definition of processing outputs.
Definition: qgsprocessingoutputs.h:42
QgsProcessingParameters::parameterAsLayerList
static QList< QgsMapLayer * > parameterAsLayerList(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of map layers.
Definition: qgsprocessingparameters.cpp:1658
QgsProcessingAlgorithm::addOutput
bool addOutput(QgsProcessingOutputDefinition *outputDefinition)
Adds an output definition to the algorithm.
Definition: qgsprocessingalgorithm.cpp:356
QgsProcessingFeatureSourceDefinition
Encapsulates settings relating to a feature source input to a processing algorithm.
Definition: qgsprocessingparameters.h:56
QgsProcessingOutputDefinition::autoCreated
bool autoCreated() const
Returns true if the output was automatically created when adding a parameter.
Definition: qgsprocessingoutputs.h:128
QgsFeatureRequest
This class wraps a request for features to a vector layer (or directly its vector data provider).
Definition: qgsfeaturerequest.h:76
QgsProcessingAlgorithm::parameterAsFile
QString parameterAsFile(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a file/folder name.
Definition: qgsprocessingalgorithm.cpp:723
QgsExpressionContextUtils::projectScope
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
Definition: qgsexpressioncontextutils.cpp:222
QgsProcessingParameters::parameterAsExtentGeometry
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...
Definition: qgsprocessingparameters.cpp:1102
QgsProcessingAlgorithm::parameterAsLayerList
QList< QgsMapLayer * > parameterAsLayerList(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of map layers.
Definition: qgsprocessingalgorithm.cpp:733
QgsPrintLayout
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Definition: qgsprintlayout.h:31
QgsProcessingAlgorithm::parameterAsLayoutItem
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.
Definition: qgsprocessingalgorithm.cpp:758
QgsProcessingParameters::parameterAsExtent
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.
Definition: qgsprocessingparameters.cpp:972
QgsProcessingContext::takeResultsFrom
void takeResultsFrom(QgsProcessingContext &context)
Takes the results from another context and merges them with the results currently stored in this cont...
Definition: qgsprocessingcontext.cpp:114
QgsProcessing::TypeVector
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
Definition: qgsprocessing.h:53
QgsWkbTypes::Unknown
@ Unknown
Definition: qgswkbtypes.h:71
QgsProcessingAlgorithm::name
virtual QString name() const =0
Returns the algorithm name, used for identifying the algorithm.
QgsProcessingAlgorithm::id
QString id() const
Returns the unique ID for the algorithm, which is a combination of the algorithm provider's ID and th...
Definition: qgsprocessingalgorithm.cpp:50
QgsProcessingFeatureBasedAlgorithm::initAlgorithm
void initAlgorithm(const QVariantMap &configuration=QVariantMap()) override
Initializes the algorithm using the specified configuration.
Definition: qgsprocessingalgorithm.cpp:910
QgsProcessingParameterRasterLayer::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:2235
QgsProcessingParameterPoint::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:1615
QgsProcessingAlgorithm::processAlgorithm
virtual QVariantMap processAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)=0
Runs the algorithm using the specified parameters.
QgsProcessingParameterExtent::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:1582
QgsProcessingParameters::parameterAsVectorLayer
static QgsVectorLayer * parameterAsVectorLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a vector layer.
Definition: qgsprocessingparameters.cpp:946
QgsProcessingParameters::parameterAsPoint
static QgsPointXY parameterAsPoint(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Evaluates the parameter with matching definition to a point.
Definition: qgsprocessingparameters.cpp:1302
QgsProcessingFeatureBasedAlgorithm::processFeature
virtual QgsFeatureList processFeature(const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)=0
Processes an individual input feature from the source.
QgsProcessingParameters::parameterAsDateTime
static QDateTime parameterAsDateTime(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static datetime value.
Definition: qgsprocessingparameters.cpp:306
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition: qgsprocessingcontext.h:44
QgsProcessingAlgorithm::sinkProperties
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.
Definition: qgsprocessingalgorithm.cpp:443
QgsProcessingAlgorithm::invalidRasterError
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.
Definition: qgsprocessingalgorithm.cpp:820
qgsprocessingalgorithm.h
QgsProcessingFeatureBasedAlgorithm::flags
QgsProcessingAlgorithm::Flags flags() const override
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Definition: qgsprocessingalgorithm.cpp:903
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:95
QgsProcessingAlgorithm::~QgsProcessingAlgorithm
virtual ~QgsProcessingAlgorithm()
Definition: qgsprocessingalgorithm.cpp:34
QgsProcessingParameterDefinition::name
QString name() const
Returns the name of the parameter.
Definition: qgsprocessingparameters.h:460
QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName
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...
Definition: qgsprocessingparameters.cpp:746
QgsProcessingFeatureBasedAlgorithm::processAlgorithm
QVariantMap processAlgorithm(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback) override SIP_THROW(QgsProcessingException)
Runs the algorithm using the specified parameters.
Definition: qgsprocessingalgorithm.cpp:974
QgsException::what
QString what() const
Definition: qgsexception.h:48
QgsProcessingAlgorithm::asPythonCommand
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...
Definition: qgsprocessingalgorithm.cpp:288
QgsProcessing::TypeVectorAnyGeometry
@ TypeVectorAnyGeometry
Any vector layer with geometry.
Definition: qgsprocessing.h:47
QgsProcessingAlgorithm::hasHtmlOutputs
bool hasHtmlOutputs() const
Returns true if this algorithm generates HTML outputs.
Definition: qgsprocessingalgorithm.cpp:433
QgsProcessingAlgorithm::parameterAsFields
QStringList parameterAsFields(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a list of fields.
Definition: qgsprocessingalgorithm.cpp:748
QgsProcessingParameters::parameterAsInts
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.
Definition: qgsprocessingparameters.cpp:249
QgsExpressionContextUtils::processingAlgorithmScope
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,...
Definition: qgsexpressioncontextutils.cpp:770
QgsProcessingFeatureBasedAlgorithm::outputCrs
virtual QgsCoordinateReferenceSystem outputCrs(const QgsCoordinateReferenceSystem &inputCrs) const
Maps the input source coordinate reference system (inputCrs) to a corresponding output CRS generated ...
Definition: qgsprocessingalgorithm.cpp:957
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:583
QgsProcessingAlgorithm::parameterAsGeometry
QgsGeometry parameterAsGeometry(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Evaluates the parameter with matching name to a geometry.
Definition: qgsprocessingalgorithm.cpp:713
qgsprocessingfeedback.h
QgsCoordinateReferenceSystem::isValid
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Definition: qgscoordinatereferencesystem.cpp:924
QgsProcessingAlgorithm::shortHelpString
virtual QString shortHelpString() const
Returns a localised short helper string for the algorithm.
Definition: qgsprocessingalgorithm.cpp:63
QgsProcessingParameters::parameterAsLayout
static QgsPrintLayout * parameterAsLayout(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a print layout.
Definition: qgsprocessingparameters.cpp:1931
QgsProcessingParameters::parameterAsPointCrs
static QgsCoordinateReferenceSystem parameterAsPointCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with an point parameter value.
Definition: qgsprocessingparameters.cpp:1386
QgsProcessingContext::setExpressionContext
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Definition: qgsprocessingcontext.h:143
QgsProcessingAlgorithm::parameterAsRange
QList< double > parameterAsRange(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a range of values.
Definition: qgsprocessingalgorithm.cpp:743
QgsProcessingAlgorithm::parameterAsLayer
QgsMapLayer * parameterAsLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a map layer.
Definition: qgsprocessingalgorithm.cpp:653
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:113
QgsProcessingAlgorithm::parameterAsExtent
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.
Definition: qgsprocessingalgorithm.cpp:693
QgsProcessingParameterFeatureSource::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:2747
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:71
QgsProcessingParameters::parameterAsFileList
static QStringList parameterAsFileList(const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a list of files (for QgsProcessingParameterMultip...
Definition: qgsprocessingparameters.cpp:1753
QgsProcessingAlgorithm::runPrepared
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().
Definition: qgsprocessingalgorithm.cpp:500
QgsProcessingParameters::parameterAsGeometryCrs
static QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter value.
Definition: qgsprocessingparameters.cpp:1541
QgsProcessingAlgorithm::parameterAsDatabaseTableName
QString parameterAsDatabaseTableName(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a database table name string.
Definition: qgsprocessingalgorithm.cpp:783
QgsProcessingAlgorithm::supportInPlaceEdit
virtual bool supportInPlaceEdit(const QgsMapLayer *layer) const
Checks whether this algorithm supports in-place editing on the given layer Default implementation ret...
Definition: qgsprocessingalgorithm.cpp:869
QgsProcessingFeatureBasedAlgorithm::outputLayerType
virtual QgsProcessing::SourceType outputLayerType() const
Returns the layer type for layers generated by this algorithm, if this is possible to determine in ad...
Definition: qgsprocessingalgorithm.cpp:932
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsProcessingContext::temporaryLayerStore
QgsMapLayerStore * temporaryLayerStore()
Returns a reference to the layer store used for storing temporary layers during algorithm execution.
Definition: qgsprocessingcontext.h:223
QgsProcessingAlgorithm::destinationParameterDefinitions
QgsProcessingParameterDefinitions destinationParameterDefinitions() const
Returns a list of destination parameters definitions utilized by the algorithm.
Definition: qgsprocessingalgorithm.cpp:412
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext.
Definition: qgsexpressioncontext.h:112
QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPathAndLayerName
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...
Definition: qgsprocessingalgorithm.cpp:648
qgsmeshlayer.h
QgsProcessingFeatureBasedAlgorithm::outputName
virtual QString outputName() const =0
Returns the translated, user visible name for any layers created by this algorithm.
QgsProcessingFeatureBasedAlgorithm::outputFields
virtual QgsFields outputFields(const QgsFields &inputFields) const
Maps the input source fields (inputFields) to corresponding output fields generated by the algorithm.
Definition: qgsprocessingalgorithm.cpp:952
qgsvectorlayer.h
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsProcessingParameters::parameterAsMeshLayer
static QgsMeshLayer * parameterAsMeshLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition and value to a mesh layer.
Definition: qgsprocessingparameters.cpp:826
QgsProcessingAlgorithm::helpUrl
virtual QString helpUrl() const
Returns a url pointing to the algorithm's help page.
Definition: qgsprocessingalgorithm.cpp:73
QgsFeedback::isCanceled
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition: qgsfeedback.h:53
qgsprocessingoutputs.h
QgsProcessingAlgorithm::FlagCanCancel
@ FlagCanCancel
Algorithm can be canceled.
Definition: qgsprocessingalgorithm.h:73
qgsprocessingutils.h
QgsProcessingAlgorithm::setProvider
void setProvider(QgsProcessingProvider *provider)
Associates this algorithm with its provider.
Definition: qgsprocessingalgorithm.cpp:133
QgsProcessingAlgorithm::createCustomParametersWidget
virtual QWidget * createCustomParametersWidget(QWidget *parent=nullptr) const
If an algorithm subclass implements a custom parameters widget, a copy of this widget should be const...
Definition: qgsprocessingalgorithm.cpp:151
qgsprocessingparameters.h
QgsProcessingAlgorithm::parameterAsRasterLayer
QgsRasterLayer * parameterAsRasterLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a raster layer.
Definition: qgsprocessingalgorithm.cpp:658
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:143
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:142
QgsProcessingFeatureSource::Flag
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
Definition: qgsprocessingutils.h:476
QgsProcessingAlgorithm::parameterAsBool
bool parameterAsBool(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static boolean value.
Definition: qgsprocessingalgorithm.cpp:620
QgsProcessingAlgorithm
Abstract base class for processing algorithms.
Definition: qgsprocessingalgorithm.h:52
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
QgsProcessingAlgorithm::parameterAsFileOutput
QString parameterAsFileOutput(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a file based output destination.
Definition: qgsprocessingalgorithm.cpp:673
QgsProcessingAlgorithm::countVisibleParameters
int countVisibleParameters() const
Returns the number of visible (non-hidden) parameters defined by this algorithm.
Definition: qgsprocessingalgorithm.cpp:401
QgsFeatureIterator::nextFeature
bool nextFeature(QgsFeature &f)
Definition: qgsfeatureiterator.h:374
QgsProcessingAlgorithm::icon
virtual QIcon icon() const
Returns an icon for the algorithm.
Definition: qgsprocessingalgorithm.cpp:78
c
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
Definition: porting_processing.dox:1
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsProcessingFeatureBasedAlgorithm::inputParameterName
virtual QString inputParameterName() const
Returns the name of the parameter corresponding to the input layer.
Definition: qgsprocessingalgorithm.cpp:917
QgsProcessingParameterDefinition::FlagHidden
@ FlagHidden
Parameter is hidden and should not be shown to users.
Definition: qgsprocessingparameters.h:424
QgsProcessingAlgorithm::VectorProperties
Properties of a vector source or sink used in an algorithm.
Definition: qgsprocessingalgorithm.h:336
QgsProcessingFeatureBasedAlgorithm::sinkProperties
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.
Definition: qgsprocessingalgorithm.cpp:1071
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsProcessingAlgorithm::parameterAsPoint
QgsPointXY parameterAsPoint(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Evaluates the parameter with matching name to a point.
Definition: qgsprocessingalgorithm.cpp:703
QgsProcessingAlgorithm::create
QgsProcessingAlgorithm * create(const QVariantMap &configuration=QVariantMap()) const SIP_THROW(QgsProcessingException)
Creates a copy of the algorithm, ready for execution.
Definition: qgsprocessingalgorithm.cpp:40
QgsProcessingAlgorithm::preprocessParameters
virtual QVariantMap preprocessParameters(const QVariantMap &parameters)
Pre-processes a set of parameters, allowing the algorithm to clean their values.
Definition: qgsprocessingalgorithm.cpp:123
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsProcessingAlgorithm::postProcessAlgorithm
virtual QVariantMap postProcessAlgorithm(QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
Allows the algorithm to perform any required cleanup tasks.
Definition: qgsprocessingalgorithm.cpp:378
QgsProcessingParameters::parameterAsOutputLayer
static QString parameterAsOutputLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a output layer destination.
Definition: qgsprocessingparameters.cpp:836
QgsProcessingAlgorithm::VectorProperties::wkbType
QgsWkbTypes::Type wkbType
Geometry (WKB) type.
Definition: qgsprocessingalgorithm.h:341
QgsProcessingAlgorithm::invalidSinkError
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.
Definition: qgsprocessingalgorithm.cpp:842
QgsWkbTypes::Polygon
@ Polygon
Definition: qgswkbtypes.h:74
QgsProcessingContext::expressionContext
QgsExpressionContext & expressionContext()
Returns the expression context.
Definition: qgsprocessingcontext.h:133
QgsProcessingFeatureSource
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource,...
Definition: qgsprocessingutils.h:471
QgsProcessingAlgorithm::parameterAsSource
QgsProcessingFeatureSource * parameterAsSource(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a feature source.
Definition: qgsprocessingalgorithm.cpp:638
QgsMessageLog::logMessage
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).
Definition: qgsmessagelog.cpp:27
QgsProcessingAlgorithm::parameterAsGeometryCrs
QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Returns the coordinate reference system associated with a geometry parameter value.
Definition: qgsprocessingalgorithm.cpp:718
QgsProcessingAlgorithm::FlagRequiresMatchingCrs
@ FlagRequiresMatchingCrs
Algorithm requires that all input layers have matching coordinate reference systems.
Definition: qgsprocessingalgorithm.h:74
QgsProcessingAlgorithm::createExpressionContext
virtual QgsExpressionContext createExpressionContext(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeatureSource *source=nullptr) const
Creates an expression context relating to the algorithm.
Definition: qgsprocessingalgorithm.cpp:156
QgsProcessingParameters::parameterAsLayoutItem
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...
Definition: qgsprocessingparameters.cpp:1955
QgsProcessingAlgorithm::helpString
virtual Q_DECL_DEPRECATED QString helpString() const
Returns a localised help string for the algorithm.
Definition: qgsprocessingalgorithm.cpp:68
QgsWkbTypes::geometryType
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
qgsprocessingcontext.h
QgsProcessingAlgorithm::FlagSupportsBatch
@ FlagSupportsBatch
Algorithm supports batch mode.
Definition: qgsprocessingalgorithm.h:72
Qgis::Critical
@ Critical
Definition: qgis.h:92
QgsProcessingAlgorithm::postProcess
QVariantMap postProcess(QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Should be called in the main thread following the completion of runPrepared().
Definition: qgsprocessingalgorithm.cpp:556
QgsProcessingParameterDefinition::isDestination
virtual bool isDestination() const
Returns true if this parameter represents a file or layer destination, e.g.
Definition: qgsprocessingparameters.h:453
QgsProcessingFeatureBasedAlgorithm::sourceCrs
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source's coordinate reference system.
Definition: qgsprocessingalgorithm.cpp:966
qgsexception.h
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsProperty::staticValue
QVariant staticValue() const
Returns the current static value for the property.
Definition: qgsproperty.cpp:284
QgsProcessingParameters::parameterAsFileOutput
static QString parameterAsFileOutput(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a file based output destination.
Definition: qgsprocessingparameters.cpp:903
QgsProcessingAlgorithm::parameterAsColor
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...
Definition: qgsprocessingalgorithm.cpp:763
QgsProcessingParameters::parameterAsExpression
static QString parameterAsExpression(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to an expression.
Definition: qgsprocessingparameters.cpp:152
QgsProcessingParameters::parameterAsSink
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.
Definition: qgsprocessingparameters.cpp:562
QgsProcessingParameters::parameterAsColor
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 ...
Definition: qgsprocessingparameters.cpp:1981
QgsProcessingOutputLayerDefinition::sink
QgsProperty sink
Sink/layer definition.
Definition: qgsprocessingparameters.h:226
QgsProcessingAlgorithm::flags
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Definition: qgsprocessingalgorithm.cpp:88
QgsProcessingAlgorithm::parameterAsSink
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.
Definition: qgsprocessingalgorithm.cpp:630
QgsProcessingAlgorithm::provider
QgsProcessingProvider * provider() const
Returns the provider to which this algorithm belongs.
Definition: qgsprocessingalgorithm.cpp:128
QgsProperty::StaticProperty
@ StaticProperty
Static property (QgsStaticProperty)
Definition: qgsproperty.h:239
QgsProcessingOutputDefinition::name
QString name() const
Returns the name of the output.
Definition: qgsprocessingoutputs.h:92
QgsFeatureIterator
Wrapper for iterator of features from vector data provider or vector layer.
Definition: qgsfeatureiterator.h:265
QgsProcessingAlgorithm::parameterAsInt
int parameterAsInt(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static integer value.
Definition: qgsprocessingalgorithm.cpp:600
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:659
QgsProcessingParameters::parameterAsEnum
static int parameterAsEnum(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a enum value.
Definition: qgsprocessingparameters.cpp:423
QgsProcessingAlgorithm::parameterAsEnums
QList< int > parameterAsEnums(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to list of enum values.
Definition: qgsprocessingalgorithm.cpp:615
QgsProcessingAlgorithm::parameterAsMatrix
QVariantList parameterAsMatrix(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a matrix/table of values.
Definition: qgsprocessingalgorithm.cpp:728
qgsprocessingprovider.h
QgsProcessingAlgorithm::parameterAsMeshLayer
QgsMeshLayer * parameterAsMeshLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a mesh layer.
Definition: qgsprocessingalgorithm.cpp:663
QgsProcessing::SourceType
SourceType
Data source types enum.
Definition: qgsprocessing.h:45
QgsProcessingProvider::supportsNonFileBasedOutput
virtual bool supportsNonFileBasedOutput() const
Returns true if the provider supports non-file based outputs (such as memory layers or direct databas...
Definition: qgsprocessingprovider.cpp:239
QgsProcessingException
Custom exception class for processing related exceptions.
Definition: qgsexception.h:83
QgsProcessingFeatureBasedAlgorithm::inputLayerTypes
virtual QList< int > inputLayerTypes() const
Returns the valid input layer types for the source layer for this algorithm.
Definition: qgsprocessingalgorithm.cpp:927
QgsProcessingAlgorithm::parameterAsCrs
QgsCoordinateReferenceSystem parameterAsCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a coordinate reference system.
Definition: qgsprocessingalgorithm.cpp:683
QgsProcessingAlgorithm::parameterAsExpression
QString parameterAsExpression(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to an expression.
Definition: qgsprocessingalgorithm.cpp:590
QgsFeatureSink
An interface for objects which accept features via addFeature(s) methods.
Definition: qgsfeaturesink.h:34
QgsProcessingAlgorithm::parameterAsDateTime
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...
Definition: qgsprocessingalgorithm.cpp:773
QgsProcessingParameters::parameterAsDouble
static double parameterAsDouble(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static double value.
Definition: qgsprocessingparameters.cpp:180
QgsProcessingFeatureBasedAlgorithm::request
virtual QgsFeatureRequest request() const
Returns the feature request used for fetching features to process from the source layer.
Definition: qgsprocessingalgorithm.cpp:1026
QgsProcessingParameters::parameterAsInt
static int parameterAsInt(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static integer value.
Definition: qgsprocessingparameters.cpp:207
QgsProcessingAlgorithm::FlagSupportsInPlaceEdits
@ FlagSupportsInPlaceEdits
Algorithm supports in-place editing.
Definition: qgsprocessingalgorithm.h:77
QgsProcessingParameters::parameterAsSource
static QgsProcessingFeatureSource * parameterAsSource(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a feature source.
Definition: qgsprocessingparameters.cpp:651
QgsProcessingParameterMapLayer::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:2591
QgsProcessingAlgorithm::parameterDefinition
const QgsProcessingParameterDefinition * parameterDefinition(const QString &name) const
Returns a matching parameter by name.
Definition: qgsprocessingalgorithm.cpp:383
QgsFeatureSink::FastInsert
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
Definition: qgsfeaturesink.h:70
qgsmessagelog.h
QgsExpressionContext::setFeature
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Definition: qgsexpressioncontext.cpp:521
QgsProcessingAlgorithm::parameterAsConnectionName
QString parameterAsConnectionName(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context)
Evaluates the parameter with matching name to a connection name string.
Definition: qgsprocessingalgorithm.cpp:768
QgsProcessingParameters::parameterAsBool
static bool parameterAsBool(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static boolean value.
Definition: qgsprocessingparameters.cpp:514
QgsProcessingAlgorithm::VectorProperties::availability
QgsProcessingAlgorithm::PropertyAvailability availability
Availability of the properties. By default properties are not available.
Definition: qgsprocessingalgorithm.h:347
QgsProcessingParameters::parameterAsString
static QString parameterAsString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static string value.
Definition: qgsprocessingparameters.cpp:120