QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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  }
271  return true;
272 }
273 
274 QString QgsProcessingAlgorithm::asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const
275 {
276  QString s = QStringLiteral( "processing.run(\"%1\"," ).arg( id() );
277 
278  QStringList parts;
279  for ( const QgsProcessingParameterDefinition *def : mParameters )
280  {
282  continue;
283 
284  if ( !parameters.contains( def->name() ) )
285  continue;
286 
287  parts << QStringLiteral( "'%1':%2" ).arg( def->name(), def->valueAsPythonString( parameters.value( def->name() ), context ) );
288  }
289 
290  s += QStringLiteral( " {%1})" ).arg( parts.join( ',' ) );
291  return s;
292 }
293 
295 {
296  if ( !definition )
297  return false;
298 
299  // check for duplicate named parameters
301  if ( existingDef && existingDef->name() == definition->name() ) // parameterDefinition is case-insensitive, but we DO allow case-different duplicate names
302  {
303  QgsMessageLog::logMessage( QObject::tr( "Duplicate parameter %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
304  delete definition;
305  return false;
306  }
307 
308  if ( definition->isDestination() && mProvider )
309  {
310  QgsProcessingDestinationParameter *destParam = static_cast< QgsProcessingDestinationParameter *>( definition );
311  if ( !mProvider->supportsNonFileBasedOutput() )
312  destParam->setSupportsNonFileBasedOutput( false );
313  }
314 
315  mParameters << definition;
316  definition->mAlgorithm = this;
317 
318  if ( createOutput )
319  return createAutoOutputForParameter( definition );
320  else
321  return true;
322 }
323 
324 void QgsProcessingAlgorithm::removeParameter( const QString &name )
325 {
327  if ( def )
328  {
329  delete def;
330  mParameters.removeAll( def );
331 
332  // remove output automatically created when adding parameter
334  if ( outputDef && outputDef->autoCreated() )
335  {
336  delete outputDef;
337  mOutputs.removeAll( outputDef );
338  }
339  }
340 }
341 
343 {
344  if ( !definition )
345  return false;
346 
347  // check for duplicate named outputs
348  if ( QgsProcessingAlgorithm::outputDefinition( definition->name() ) )
349  {
350  QgsMessageLog::logMessage( QObject::tr( "Duplicate output %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
351  delete definition;
352  return false;
353  }
354 
355  mOutputs << definition;
356  return true;
357 }
358 
360 {
361  return true;
362 }
363 
365 {
366  return QVariantMap();
367 }
368 
370 {
371  // first pass - case sensitive match
372  for ( const QgsProcessingParameterDefinition *def : mParameters )
373  {
374  if ( def->name() == name )
375  return def;
376  }
377 
378  // second pass - case insensitive
379  for ( const QgsProcessingParameterDefinition *def : mParameters )
380  {
381  if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
382  return def;
383  }
384  return nullptr;
385 }
386 
388 {
389  int count = 0;
390  for ( const QgsProcessingParameterDefinition *def : mParameters )
391  {
392  if ( !( def->flags() & QgsProcessingParameterDefinition::FlagHidden ) )
393  count++;
394  }
395  return count;
396 }
397 
399 {
401  for ( const QgsProcessingParameterDefinition *def : mParameters )
402  {
403  if ( def->isDestination() )
404  result << def;
405  }
406  return result;
407 }
408 
410 {
411  for ( const QgsProcessingOutputDefinition *def : mOutputs )
412  {
413  if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
414  return def;
415  }
416  return nullptr;
417 }
418 
420 {
421  for ( const QgsProcessingOutputDefinition *def : mOutputs )
422  {
423  if ( def->type() == QStringLiteral( "outputHtml" ) )
424  return true;
425  }
426  return false;
427 }
428 
429 QgsProcessingAlgorithm::VectorProperties QgsProcessingAlgorithm::sinkProperties( const QString &, const QVariantMap &, QgsProcessingContext &, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> & ) const
430 {
431  return VectorProperties();
432 }
433 
434 QVariantMap QgsProcessingAlgorithm::run( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok, const QVariantMap &configuration ) const
435 {
436  std::unique_ptr< QgsProcessingAlgorithm > alg( create( configuration ) );
437  if ( ok )
438  *ok = false;
439 
440  bool res = alg->prepare( parameters, context, feedback );
441  if ( !res )
442  return QVariantMap();
443 
444  QVariantMap runRes;
445  try
446  {
447  runRes = alg->runPrepared( parameters, context, feedback );
448  }
449  catch ( QgsProcessingException &e )
450  {
451  QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::Critical );
452  feedback->reportError( e.what() );
453  return QVariantMap();
454  }
455 
456  if ( ok )
457  *ok = true;
458 
459  QVariantMap ppRes = alg->postProcess( context, feedback );
460  if ( !ppRes.isEmpty() )
461  return ppRes;
462  else
463  return runRes;
464 }
465 
466 bool QgsProcessingAlgorithm::prepare( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
467 {
468  Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::prepare", "prepare() must be called from the same thread as context was created in" );
469  Q_ASSERT_X( !mHasPrepared, "QgsProcessingAlgorithm::prepare", "prepare() has already been called for the algorithm instance" );
470  try
471  {
472  mHasPrepared = prepareAlgorithm( parameters, context, feedback );
473  return mHasPrepared;
474  }
475  catch ( QgsProcessingException &e )
476  {
477  QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::Critical );
478  feedback->reportError( e.what() );
479  return false;
480  }
481 }
482 
483 QVariantMap QgsProcessingAlgorithm::runPrepared( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
484 {
485  Q_ASSERT_X( mHasPrepared, "QgsProcessingAlgorithm::runPrepared", QStringLiteral( "prepare() was not called for the algorithm instance %1" ).arg( name() ).toLatin1() );
486  Q_ASSERT_X( !mHasExecuted, "QgsProcessingAlgorithm::runPrepared", "runPrepared() was already called for this algorithm instance" );
487 
488  // Hey kids, let's all be thread safe! It's the fun thing to do!
489  //
490  // First, let's see if we're going to run into issues.
491  QgsProcessingContext *runContext = nullptr;
492  if ( context.thread() == QThread::currentThread() )
493  {
494  // OH. No issues. Seems you're running everything in the same thread, so go about your business. Sorry about
495  // the intrusion, we're just making sure everything's nice and safe here. We like to keep a clean and tidy neighbourhood,
496  // you know, for the kids and dogs and all.
497  runContext = &context;
498  }
499  else
500  {
501  // HA! I knew things looked a bit suspicious - seems you're running this algorithm in a different thread
502  // from that which the passed context has an affinity for. That's fine and all, but we need to make sure
503  // we proceed safely...
504 
505  // So first we create a temporary local context with affinity for the current thread
506  mLocalContext.reset( new QgsProcessingContext() );
507  // copy across everything we can safely do from the passed context
508  mLocalContext->copyThreadSafeSettings( context );
509  // and we'll run the actual algorithm processing using the local thread safe context
510  runContext = mLocalContext.get();
511  }
512 
513  try
514  {
515  QVariantMap runResults = processAlgorithm( parameters, *runContext, feedback );
516 
517  mHasExecuted = true;
518  if ( mLocalContext )
519  {
520  // ok, time to clean things up. We need to push the temporary context back into
521  // the thread that the passed context is associated with (we can only push from the
522  // current thread, so we HAVE to do this here)
523  mLocalContext->pushToThread( context.thread() );
524  }
525  return runResults;
526  }
527  catch ( QgsProcessingException & )
528  {
529  if ( mLocalContext )
530  {
531  // see above!
532  mLocalContext->pushToThread( context.thread() );
533  }
534  //rethrow
535  throw;
536  }
537 }
538 
540 {
541  Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::postProcess", "postProcess() must be called from the same thread the context was created in" );
542  Q_ASSERT_X( mHasExecuted, "QgsProcessingAlgorithm::postProcess", QStringLiteral( "algorithm instance %1 was not executed" ).arg( name() ).toLatin1() );
543  Q_ASSERT_X( !mHasPostProcessed, "QgsProcessingAlgorithm::postProcess", "postProcess() was already called for this algorithm instance" );
544 
545  if ( mLocalContext )
546  {
547  // algorithm was processed using a temporary thread safe context. So now we need
548  // to take the results from that temporary context, and smash them into the passed
549  // context
550  context.takeResultsFrom( *mLocalContext );
551  // now get lost, we don't need you anymore
552  mLocalContext.reset();
553  }
554 
555  mHasPostProcessed = true;
556  try
557  {
558  return postProcessAlgorithm( context, feedback );
559  }
560  catch ( QgsProcessingException &e )
561  {
562  QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::Critical );
563  feedback->reportError( e.what() );
564  return QVariantMap();
565  }
566 }
567 
568 QString QgsProcessingAlgorithm::parameterAsString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
569 {
570  return QgsProcessingParameters::parameterAsString( parameterDefinition( name ), parameters, context );
571 }
572 
573 QString QgsProcessingAlgorithm::parameterAsExpression( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
574 {
576 }
577 
578 double QgsProcessingAlgorithm::parameterAsDouble( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
579 {
580  return QgsProcessingParameters::parameterAsDouble( parameterDefinition( name ), parameters, context );
581 }
582 
583 int QgsProcessingAlgorithm::parameterAsInt( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
584 {
585  return QgsProcessingParameters::parameterAsInt( parameterDefinition( name ), parameters, context );
586 }
587 
588 QList<int> QgsProcessingAlgorithm::parameterAsInts( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
589 {
590  return QgsProcessingParameters::parameterAsInts( parameterDefinition( name ), parameters, context );
591 }
592 
593 int QgsProcessingAlgorithm::parameterAsEnum( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
594 {
595  return QgsProcessingParameters::parameterAsEnum( parameterDefinition( name ), parameters, context );
596 }
597 
598 QList<int> QgsProcessingAlgorithm::parameterAsEnums( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
599 {
600  return QgsProcessingParameters::parameterAsEnums( parameterDefinition( name ), parameters, context );
601 }
602 
603 bool QgsProcessingAlgorithm::parameterAsBool( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
604 {
605  return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
606 }
607 
608 bool QgsProcessingAlgorithm::parameterAsBoolean( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
609 {
610  return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
611 }
612 
613 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
614 {
615  if ( !parameterDefinition( name ) )
616  throw QgsProcessingException( QObject::tr( "No parameter definition for the sink '%1'" ).arg( name ) );
617 
618  return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags );
619 }
620 
621 QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
622 {
623  return QgsProcessingParameters::parameterAsSource( parameterDefinition( name ), parameters, context );
624 }
625 
626 QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback )
627 {
628  return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback );
629 }
630 
631 QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPathAndLayerName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName )
632 {
633  return QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback, layerName );
634 }
635 
636 QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
637 {
638  return QgsProcessingParameters::parameterAsLayer( parameterDefinition( name ), parameters, context );
639 }
640 
641 QgsRasterLayer *QgsProcessingAlgorithm::parameterAsRasterLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
642 {
644 }
645 
646 QgsMeshLayer *QgsProcessingAlgorithm::parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
647 {
649 }
650 
651 QString QgsProcessingAlgorithm::parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
652 {
654 }
655 
656 QString QgsProcessingAlgorithm::parameterAsFileOutput( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
657 {
659 }
660 
661 QgsVectorLayer *QgsProcessingAlgorithm::parameterAsVectorLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
662 {
664 }
665 
666 QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
667 {
668  return QgsProcessingParameters::parameterAsCrs( parameterDefinition( name ), parameters, context );
669 }
670 
671 QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsExtentCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
672 {
674 }
675 
676 QgsRectangle QgsProcessingAlgorithm::parameterAsExtent( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
677 {
678  return QgsProcessingParameters::parameterAsExtent( parameterDefinition( name ), parameters, context, crs );
679 }
680 
681 QgsGeometry QgsProcessingAlgorithm::parameterAsExtentGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs )
682 {
684 }
685 
686 QgsPointXY QgsProcessingAlgorithm::parameterAsPoint( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
687 {
688  return QgsProcessingParameters::parameterAsPoint( parameterDefinition( name ), parameters, context, crs );
689 }
690 
691 QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsPointCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
692 {
694 }
695 
696 QString QgsProcessingAlgorithm::parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
697 {
698  return QgsProcessingParameters::parameterAsFile( parameterDefinition( name ), parameters, context );
699 }
700 
701 QVariantList QgsProcessingAlgorithm::parameterAsMatrix( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
702 {
703  return QgsProcessingParameters::parameterAsMatrix( parameterDefinition( name ), parameters, context );
704 }
705 
706 QList<QgsMapLayer *> QgsProcessingAlgorithm::parameterAsLayerList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
707 {
709 }
710 
711 QStringList QgsProcessingAlgorithm::parameterAsFileList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
712 {
714 }
715 
716 QList<double> QgsProcessingAlgorithm::parameterAsRange( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
717 {
718  return QgsProcessingParameters::parameterAsRange( parameterDefinition( name ), parameters, context );
719 }
720 
721 QStringList QgsProcessingAlgorithm::parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
722 {
723  return QgsProcessingParameters::parameterAsFields( parameterDefinition( name ), parameters, context );
724 }
725 
726 QgsPrintLayout *QgsProcessingAlgorithm::parameterAsLayout( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
727 {
728  return QgsProcessingParameters::parameterAsLayout( parameterDefinition( name ), parameters, context );
729 }
730 
731 QgsLayoutItem *QgsProcessingAlgorithm::parameterAsLayoutItem( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsPrintLayout *layout )
732 {
733  return QgsProcessingParameters::parameterAsLayoutItem( parameterDefinition( name ), parameters, context, layout );
734 }
735 
736 QColor QgsProcessingAlgorithm::parameterAsColor( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
737 {
738  return QgsProcessingParameters::parameterAsColor( parameterDefinition( name ), parameters, context );
739 }
740 
741 QString QgsProcessingAlgorithm::parameterAsConnectionName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
742 {
744 }
745 
746 QDateTime QgsProcessingAlgorithm::parameterAsDateTime( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
747 {
749 }
750 
751 QString QgsProcessingAlgorithm::parameterAsSchema( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
752 {
753  return QgsProcessingParameters::parameterAsSchema( parameterDefinition( name ), parameters, context );
754 }
755 
756 QString QgsProcessingAlgorithm::parameterAsDatabaseTableName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
757 {
759 }
760 
761 QString QgsProcessingAlgorithm::invalidSourceError( const QVariantMap &parameters, const QString &name )
762 {
763  if ( !parameters.contains( name ) )
764  return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
765  else
766  {
767  QVariant var = parameters.value( name );
768  if ( var.canConvert<QgsProcessingFeatureSourceDefinition>() )
769  {
770  QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
771  var = fromVar.source;
772  }
773  else if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
774  {
775  QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
776  var = fromVar.sink;
777  }
778  if ( var.canConvert<QgsProperty>() )
779  {
780  QgsProperty p = var.value< QgsProperty >();
782  {
783  var = p.staticValue();
784  }
785  }
786  if ( !var.toString().isEmpty() )
787  return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
788  else
789  return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
790  }
791 }
792 
793 QString QgsProcessingAlgorithm::invalidRasterError( const QVariantMap &parameters, const QString &name )
794 {
795  if ( !parameters.contains( name ) )
796  return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
797  else
798  {
799  QVariant var = parameters.value( name );
800  if ( var.canConvert<QgsProperty>() )
801  {
802  QgsProperty p = var.value< QgsProperty >();
804  {
805  var = p.staticValue();
806  }
807  }
808  if ( !var.toString().isEmpty() )
809  return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
810  else
811  return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
812  }
813 }
814 
815 QString QgsProcessingAlgorithm::invalidSinkError( const QVariantMap &parameters, const QString &name )
816 {
817  if ( !parameters.contains( name ) )
818  return QObject::tr( "Could not create destination layer for %1: no value specified for parameter" ).arg( name );
819  else
820  {
821  QVariant var = parameters.value( name );
822  if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
823  {
824  QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
825  var = fromVar.sink;
826  }
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 create destination layer for %1: %2" ).arg( name, var.toString() );
837  else
838  return QObject::tr( "Could not create destination layer for %1: invalid value" ).arg( name );
839  }
840 }
841 
843 {
844  Q_UNUSED( layer )
845  return false;
846 }
847 
848 
849 bool QgsProcessingAlgorithm::createAutoOutputForParameter( QgsProcessingParameterDefinition *parameter )
850 {
851  if ( !parameter->isDestination() )
852  return true; // nothing created, but nothing went wrong - so return true
853 
854  QgsProcessingDestinationParameter *dest = static_cast< QgsProcessingDestinationParameter * >( parameter );
856  if ( !output )
857  return true; // nothing created - but nothing went wrong - so return true
858  output->setAutoCreated( true );
859 
860  if ( !addOutput( output ) )
861  {
862  // couldn't add output - probably a duplicate name
863  return false;
864  }
865  else
866  {
867  return true;
868  }
869 }
870 
871 
872 //
873 // QgsProcessingFeatureBasedAlgorithm
874 //
875 
876 QgsProcessingAlgorithm::Flags QgsProcessingFeatureBasedAlgorithm::flags() const
877 {
878  Flags f = QgsProcessingAlgorithm::flags();
880  return f;
881 }
882 
883 void QgsProcessingFeatureBasedAlgorithm::initAlgorithm( const QVariantMap &config )
884 {
886  initParameters( config );
887  addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), outputName(), outputLayerType(), QVariant(), false, true, true ) );
888 }
889 
891 {
892  return QStringLiteral( "INPUT" );
893 }
894 
896 {
897  return QObject::tr( "Input layer" );
898 }
899 
901 {
902  return QList<int>();
903 }
904 
906 {
908 }
909 
911 {
912  return static_cast<QgsProcessingFeatureSource::Flag>( 0 );
913 }
914 
915 QgsFeatureSink::SinkFlags QgsProcessingFeatureBasedAlgorithm::sinkFlags() const
916 {
917  return nullptr;
918 }
919 
921 {
922  return inputWkbType;
923 }
924 
926 {
927  return inputFields;
928 }
929 
931 {
932  return inputCrs;
933 }
934 
936 {
937 }
938 
940 {
941  if ( mSource )
942  return mSource->sourceCrs();
943  else
945 }
946 
947 QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
948 {
949  prepareSource( parameters, context );
950  QString dest;
951  std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest,
952  outputFields( mSource->fields() ),
953  outputWkbType( mSource->wkbType() ),
954  outputCrs( mSource->sourceCrs() ),
955  sinkFlags() ) );
956  if ( !sink )
957  throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );
958 
959  // prepare expression context for feature iteration
960  QgsExpressionContext prevContext = context.expressionContext();
961  QgsExpressionContext algContext = prevContext;
962 
963  algContext.appendScopes( createExpressionContext( parameters, context, mSource.get() ).takeScopes() );
964  context.setExpressionContext( algContext );
965 
966  long count = mSource->featureCount();
967 
968  QgsFeature f;
969  QgsFeatureIterator it = mSource->getFeatures( request(), sourceFlags() );
970 
971  double step = count > 0 ? 100.0 / count : 1;
972  int current = 0;
973  while ( it.nextFeature( f ) )
974  {
975  if ( feedback->isCanceled() )
976  {
977  break;
978  }
979 
980  context.expressionContext().setFeature( f );
981  const QgsFeatureList transformed = processFeature( f, context, feedback );
982  for ( QgsFeature transformedFeature : transformed )
983  sink->addFeature( transformedFeature, QgsFeatureSink::FastInsert );
984 
985  feedback->setProgress( current * step );
986  current++;
987  }
988 
989  mSource.reset();
990 
991  // probably not necessary - context's aren't usually recycled, but can't hurt
992  context.setExpressionContext( prevContext );
993 
994  QVariantMap outputs;
995  outputs.insert( QStringLiteral( "OUTPUT" ), dest );
996  return outputs;
997 }
998 
1000 {
1001  return QgsFeatureRequest();
1002 }
1003 
1005 {
1006  const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
1007  if ( !layer )
1008  return false;
1009 
1010  QgsWkbTypes::GeometryType inPlaceGeometryType = layer->geometryType();
1011  if ( !inputLayerTypes().empty() &&
1012  !inputLayerTypes().contains( QgsProcessing::TypeVector ) &&
1014  ( ( inPlaceGeometryType == QgsWkbTypes::PolygonGeometry && !inputLayerTypes().contains( QgsProcessing::TypeVectorPolygon ) ) ||
1015  ( inPlaceGeometryType == QgsWkbTypes::LineGeometry && !inputLayerTypes().contains( QgsProcessing::TypeVectorLine ) ) ||
1016  ( inPlaceGeometryType == QgsWkbTypes::PointGeometry && !inputLayerTypes().contains( QgsProcessing::TypeVectorPoint ) ) ) )
1017  return false;
1018 
1020  if ( inPlaceGeometryType == QgsWkbTypes::PointGeometry )
1021  type = QgsWkbTypes::Point;
1022  else if ( inPlaceGeometryType == QgsWkbTypes::LineGeometry )
1023  type = QgsWkbTypes::LineString;
1024  else if ( inPlaceGeometryType == QgsWkbTypes::PolygonGeometry )
1025  type = QgsWkbTypes::Polygon;
1026 
1027  if ( QgsWkbTypes::geometryType( outputWkbType( type ) ) != inPlaceGeometryType )
1028  return false;
1029 
1030  return true;
1031 }
1032 
1033 void QgsProcessingFeatureBasedAlgorithm::prepareSource( const QVariantMap &parameters, QgsProcessingContext &context )
1034 {
1035  if ( ! mSource )
1036  {
1037  mSource.reset( parameterAsSource( parameters, inputParameterName(), context ) );
1038  if ( !mSource )
1040  }
1041 }
1042 
1043 
1044 QgsProcessingAlgorithm::VectorProperties QgsProcessingFeatureBasedAlgorithm::sinkProperties( const QString &sink, const QVariantMap &parameters, QgsProcessingContext &context, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> &sourceProperties ) const
1045 {
1047  if ( sink == QStringLiteral( "OUTPUT" ) )
1048  {
1049  if ( sourceProperties.value( QStringLiteral( "INPUT" ) ).availability == QgsProcessingAlgorithm::Available )
1050  {
1051  const VectorProperties inputProps = sourceProperties.value( QStringLiteral( "INPUT" ) );
1052  result.fields = outputFields( inputProps.fields );
1053  result.crs = outputCrs( inputProps.crs );
1054  result.wkbType = outputWkbType( inputProps.wkbType );
1055  result.availability = Available;
1056  return result;
1057  }
1058  else
1059  {
1060  std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
1061  if ( source )
1062  {
1063  result.fields = outputFields( source->fields() );
1064  result.crs = outputCrs( source->sourceCrs() );
1065  result.wkbType = outputWkbType( source->wkbType() );
1066  result.availability = Available;
1067  return result;
1068  }
1069  }
1070  }
1071  return result;
1072 }
1073 
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
QgsMapLayer::crs
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:88
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:75
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:1441
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:740
QgsProcessingAlgorithm::prepare
bool prepare(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm for execution.
Definition: qgsprocessingalgorithm.cpp:466
QgsProcessingAlgorithm::removeParameter
void removeParameter(const QString &name)
Removes the parameter with matching name from the algorithm, and deletes any existing definition.
Definition: qgsprocessingalgorithm.cpp:324
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:955
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:711
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:1850
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:761
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:726
QgsProperty
A store for object properties.
Definition: qgsproperty.h:231
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:605
QgsWkbTypes::Point
@ Point
Definition: qgswkbtypes.h:71
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:671
QgsProcessingParameterDefinition::mAlgorithm
QgsProcessingAlgorithm * mAlgorithm
Pointer to algorithm which owns this parameter.
Definition: qgsprocessingparameters.h:710
QgsProcessingFeatureBasedAlgorithm::prepareSource
void prepareSource(const QVariantMap &parameters, QgsProcessingContext &context)
Read the source from parameters and context and set it.
Definition: qgsprocessingalgorithm.cpp:1033
QgsExpressionContextUtils::globalScope
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Definition: qgsexpressioncontextutils.cpp:33
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
QgsProcessingContext::project
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Definition: qgsprocessingcontext.h:99
QgsProcessingAlgorithm::VectorProperties::fields
QgsFields fields
Fields.
Definition: qgsprocessingalgorithm.h:336
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:342
QgsProcessingFeedback
Definition: qgsprocessingfeedback.h:37
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:920
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:1880
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
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:1695
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:588
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:1328
QgsWkbTypes::LineString
@ LineString
Definition: qgswkbtypes.h:72
QgsProcessingAlgorithm::addParameter
bool addParameter(QgsProcessingParameterDefinition *parameterDefinition, bool createOutput=true)
Adds a parameter definition to the algorithm.
Definition: qgsprocessingalgorithm.cpp:294
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:661
QgsFields
Definition: qgsfields.h:44
QgsProcessingFeatureBasedAlgorithm::inputParameterDescription
virtual QString inputParameterDescription() const
Returns the translated description of the parameter corresponding to the input layer.
Definition: qgsprocessingalgorithm.cpp:895
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:758
QgsProcessingProvider
Definition: qgsprocessingprovider.h:34
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:1219
QgsProcessingFeatureBasedAlgorithm::initParameters
virtual void initParameters(const QVariantMap &configuration=QVariantMap())
Initializes any extra parameters added by the algorithm subclass.
Definition: qgsprocessingalgorithm.cpp:935
QgsProcessingContext::thread
QThread * thread()
Returns the thread in which the context lives.
Definition: qgsprocessingcontext.h:413
QgsProcessingParameterMultipleLayers::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:1770
QgsProcessingAlgorithm::createInstance
virtual QgsProcessingAlgorithm * createInstance() const =0
Creates a new instance of the algorithm class.
QgsProcessingParameterDefinition
Definition: qgsprocessingparameters.h:330
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:626
QgsProcessingAlgorithm::svgIconPath
virtual QString svgIconPath() const
Returns a path to an SVG version of the algorithm's icon.
Definition: qgsprocessingalgorithm.cpp:83
QgsProcessingParameterFeatureSource
Definition: qgsprocessingparameters.h:2612
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:681
QgsProcessingOutputLayerDefinition
Definition: qgsprocessingparameters.h:199
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
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:1004
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:359
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:593
QgsApplication::iconPath
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
Definition: qgsapplication.cpp:594
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:568
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:1865
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:815
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:409
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
Definition: qgsrectangle.h:41
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:578
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:143
QgsProcessingFeatureBasedAlgorithm::sinkFlags
virtual QgsFeatureSink::SinkFlags sinkFlags() const
Returns the feature sink flags to be used for the output.
Definition: qgsprocessingalgorithm.cpp:915
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:325
QgsProcessingParameterDefinitions
QList< const QgsProcessingParameterDefinition * > QgsProcessingParameterDefinitions
List of processing parameters.
Definition: qgsprocessingparameters.h:732
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:691
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())
Evaluates the parameter with matching definition to a feature sink.
Definition: qgsprocessingparameters.cpp:562
QgsProcessingFeatureBasedAlgorithm::sourceFlags
virtual QgsProcessingFeatureSource::Flag sourceFlags() const
Returns the processing feature source flags to be used in the algorithm.
Definition: qgsprocessingalgorithm.cpp:910
QgsProcessingParameterFeatureSink::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:2789
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:608
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:2689
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:751
QgsProcessingParameterFeatureSink
Definition: qgsprocessingparameters.h:2773
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:1629
QgsProcessingDestinationParameter
Definition: qgsprocessingparameters.h:2652
qgsapplication.h
QgsProcessingAlgorithm::run
QVariantMap run(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok=nullptr, const QVariantMap &configuration=QVariantMap()) const
Executes the algorithm using the specified parameters.
Definition: qgsprocessingalgorithm.cpp:434
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:1419
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:651
QgsProcessingOutputDefinition
Definition: qgsprocessingoutputs.h:41
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:1480
QgsProcessingAlgorithm::addOutput
bool addOutput(QgsProcessingOutputDefinition *outputDefinition)
Adds an output definition to the algorithm.
Definition: qgsprocessingalgorithm.cpp:342
QgsProcessingFeatureSourceDefinition
Definition: qgsprocessingparameters.h:55
QgsProcessingOutputDefinition::autoCreated
bool autoCreated() const
Returns true if the output was automatically created when adding a parameter.
Definition: qgsprocessingoutputs.h:128
QgsFeatureRequest
Definition: qgsfeaturerequest.h:75
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:696
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:221
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:1101
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 SIP_THROW(QgsProcessingException)
Evaluates the parameter with matching name to a feature sink.
Definition: qgsprocessingalgorithm.cpp:613
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:706
QgsPrintLayout
Print layout, a QgsLayout subclass for static or atlas-based layouts.
Definition: qgsprintlayout.h:30
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:731
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:971
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:96
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:70
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:883
QgsProcessingParameterRasterLayer::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:2114
QgsProcessingParameterPoint::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:1548
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:1515
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:945
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:1301
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
Definition: qgsprocessingcontext.h:43
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:429
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:793
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:876
QgsMeshLayer
Definition: qgsmeshlayer.h:94
QgsProcessingAlgorithm::~QgsProcessingAlgorithm
virtual ~QgsProcessingAlgorithm()
Definition: qgsprocessingalgorithm.cpp:34
QgsProcessingParameterDefinition::name
QString name() const
Returns the name of the parameter.
Definition: qgsprocessingparameters.h:456
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:745
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:947
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:274
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:419
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:721
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:760
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:930
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:572
qgsprocessingfeedback.h
QgsWkbTypes::geometryType
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Definition: qgswkbtypes.h:937
QgsCoordinateReferenceSystem::isValid
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Definition: qgscoordinatereferencesystem.cpp:902
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:1753
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:1385
QgsProcessingContext::setExpressionContext
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Definition: qgsprocessingcontext.h:129
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:716
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:636
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:112
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:676
QgsProcessingParameterFeatureSource::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:2626
QgsRasterLayer
Definition: qgsrasterlayer.h:72
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:1575
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:483
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:756
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:842
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:905
QgsCoordinateReferenceSystem
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:151
QgsProcessingAlgorithm::destinationParameterDefinitions
QgsProcessingParameterDefinitions destinationParameterDefinitions() const
Returns a list of destination parameters definitions utilized by the algorithm.
Definition: qgsprocessingalgorithm.cpp:398
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:111
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:631
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:925
qgsvectorlayer.h
QgsPointXY
Definition: qgspointxy.h:43
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:825
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:66
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:641
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:142
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:141
QgsProcessingFeatureSource::Flag
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
Definition: qgsprocessingutils.h:473
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:603
QgsProcessingAlgorithm
Definition: qgsprocessingalgorithm.h:51
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:139
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:656
QgsProcessingAlgorithm::countVisibleParameters
int countVisibleParameters() const
Returns the number of visible (non-hidden) parameters defined by this algorithm.
Definition: qgsprocessingalgorithm.cpp:387
QgsFeatureIterator::nextFeature
bool nextFeature(QgsFeature &f)
Definition: qgsfeatureiterator.h:373
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
Definition: qgsgeometry.h:122
QgsProcessingFeatureBasedAlgorithm::inputParameterName
virtual QString inputParameterName() const
Returns the name of the parameter corresponding to the input layer.
Definition: qgsprocessingalgorithm.cpp:890
QgsProcessingParameterDefinition::FlagHidden
@ FlagHidden
Parameter is hidden and should not be shown to users.
Definition: qgsprocessingparameters.h:420
QgsProcessingAlgorithm::VectorProperties
Properties of a vector source or sink used in an algorithm.
Definition: qgsprocessingalgorithm.h:333
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:1044
QgsVectorLayer
Definition: qgsvectorlayer.h:385
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:686
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
Definition: qgsmaplayer.h:81
QgsProcessingAlgorithm::postProcessAlgorithm
virtual QVariantMap postProcessAlgorithm(QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
Allows the algorithm to perform any required cleanup tasks.
Definition: qgsprocessingalgorithm.cpp:364
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:835
QgsProcessingAlgorithm::VectorProperties::wkbType
QgsWkbTypes::Type wkbType
Geometry (WKB) type.
Definition: qgsprocessingalgorithm.h:339
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:815
QgsWkbTypes::Polygon
@ Polygon
Definition: qgswkbtypes.h:73
QgsProcessingContext::expressionContext
QgsExpressionContext & expressionContext()
Returns the expression context.
Definition: qgsprocessingcontext.h:119
QgsProcessingFeatureSource
Definition: qgsprocessingutils.h:468
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:621
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::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:1777
QgsProcessingAlgorithm::helpString
virtual Q_DECL_DEPRECATED QString helpString() const
Returns a localised help string for the algorithm.
Definition: qgsprocessingalgorithm.cpp:68
qgsprocessingcontext.h
QgsProcessingAlgorithm::FlagSupportsBatch
@ FlagSupportsBatch
Algorithm supports batch mode.
Definition: qgsprocessingalgorithm.h:72
Qgis::Critical
@ Critical
Definition: qgis.h:105
QgsProcessingAlgorithm::postProcess
QVariantMap postProcess(QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Should be called in the main thread following the completion of runPrepared().
Definition: qgsprocessingalgorithm.cpp:539
QgsProcessingParameterDefinition::isDestination
virtual bool isDestination() const
Returns true if this parameter represents a file or layer destination, e.g.
Definition: qgsprocessingparameters.h:449
QgsProcessingFeatureBasedAlgorithm::sourceCrs
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source's coordinate reference system.
Definition: qgsprocessingalgorithm.cpp:939
qgsexception.h
QgsFeature
Definition: qgsfeature.h:55
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:902
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:736
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::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:1803
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::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
Definition: qgsfeatureiterator.h:263
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:583
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:598
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:701
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:646
QgsProcessing::SourceType
SourceType
Data source types enum.
Definition: qgsprocessing.h:44
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
Definition: qgsexception.h:82
QgsProcessingFeatureBasedAlgorithm::inputLayerTypes
virtual QList< int > inputLayerTypes() const
Returns the valid input layer types for the source layer for this algorithm.
Definition: qgsprocessingalgorithm.cpp:900
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:666
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:573
QgsFeatureSink
Definition: qgsfeaturesink.h:33
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:746
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:999
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:650
QgsProcessingParameterMapLayer::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:2470
QgsProcessingAlgorithm::parameterDefinition
const QgsProcessingParameterDefinition * parameterDefinition(const QString &name) const
Returns a matching parameter by name.
Definition: qgsprocessingalgorithm.cpp:369
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:741
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:345
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