QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsprocessingalgorithm.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprocessingalgorithm.cpp
3  --------------------------
4  begin : December 2016
5  copyright : (C) 2016 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgsprocessingalgorithm.h"
19 #include "qgsapplication.h"
20 #include "qgsprocessingprovider.h"
22 #include "qgsprocessingoutputs.h"
23 #include "qgsrectangle.h"
24 #include "qgsprocessingcontext.h"
25 #include "qgsprocessingutils.h"
26 #include "qgsexception.h"
27 #include "qgsmessagelog.h"
28 #include "qgsvectorlayer.h"
29 #include "qgsprocessingfeedback.h"
30 #include "qgsmeshlayer.h"
31 #include "qgspointcloudlayer.h"
33 #include <QRegularExpression>
34 #include <QRegularExpressionMatch>
35 
37 {
38  qDeleteAll( mParameters );
39  qDeleteAll( mOutputs );
40 }
41 
42 QgsProcessingAlgorithm *QgsProcessingAlgorithm::create( const QVariantMap &configuration ) const
43 {
44  std::unique_ptr< QgsProcessingAlgorithm > creation( createInstance() );
45  if ( ! creation )
46  throw QgsProcessingException( QObject::tr( "Error creating algorithm from createInstance()" ) );
47  creation->setProvider( provider() );
48  creation->initAlgorithm( configuration );
49  return creation.release();
50 }
51 
53 {
54  if ( mProvider )
55  return QStringLiteral( "%1:%2" ).arg( mProvider->id(), name() );
56  else
57  return name();
58 }
59 
61 {
62  return QString();
63 }
64 
66 {
67  return QString();
68 }
69 
71 {
72  return QString();
73 }
74 
76 {
77  return QString();
78 }
79 
81 {
82  return QgsApplication::getThemeIcon( "/processingAlgorithm.svg" );
83 }
84 
86 {
87  return QgsApplication::iconPath( QStringLiteral( "processingAlgorithm.svg" ) );
88 }
89 
90 QgsProcessingAlgorithm::Flags QgsProcessingAlgorithm::flags() const
91 {
93 }
94 
95 bool QgsProcessingAlgorithm::canExecute( QString * ) const
96 {
97  return true;
98 }
99 
100 bool QgsProcessingAlgorithm::checkParameterValues( const QVariantMap &parameters, QgsProcessingContext &context, QString *message ) const
101 {
102  for ( const QgsProcessingParameterDefinition *def : mParameters )
103  {
104  if ( !def->checkValueIsAcceptable( parameters.value( def->name() ), &context ) )
105  {
106  if ( message )
107  {
108  // TODO QGIS 4 - move the message handling to the parameter subclasses (but this
109  // requires a change in signature for the virtual checkValueIsAcceptable method)
110  if ( def->type() == QgsProcessingParameterFeatureSource::typeName() )
111  *message = invalidSourceError( parameters, def->name() );
112  else if ( def->type() == QgsProcessingParameterFeatureSink::typeName() )
113  *message = invalidSinkError( parameters, def->name() );
114  else if ( def->type() == QgsProcessingParameterRasterLayer::typeName() )
115  *message = invalidRasterError( parameters, def->name() );
116  else
117  *message = QObject::tr( "Incorrect parameter value for %1" ).arg( def->name() );
118  }
119  return false;
120  }
121  }
122  return true;
123 }
124 
125 QVariantMap QgsProcessingAlgorithm::preprocessParameters( const QVariantMap &parameters )
126 {
127  return parameters;
128 }
129 
131 {
132  return mProvider;
133 }
134 
136 {
137  mProvider = provider;
138 
139  if ( mProvider && !mProvider->supportsNonFileBasedOutput() )
140  {
141  // need to update all destination parameters to turn off non file based outputs
142  for ( const QgsProcessingParameterDefinition *definition : std::as_const( mParameters ) )
143  {
144  if ( definition->isDestination() )
145  {
146  const QgsProcessingDestinationParameter *destParam = static_cast< const QgsProcessingDestinationParameter *>( definition );
147  const_cast< QgsProcessingDestinationParameter *>( destParam )->setSupportsNonFileBasedOutput( false );
148  }
149  }
150  }
151 }
152 
154 {
155  return nullptr;
156 }
157 
159  QgsProcessingContext &context, QgsProcessingFeatureSource *source ) const
160 {
161  // start with context's expression context
163 
164  // If there's a source capable of generating a context scope, use it
165  if ( source )
166  {
168  if ( scope )
169  c << scope;
170  }
171  else if ( c.scopeCount() == 0 )
172  {
173  //empty scope, populate with initial scopes
176  }
177 
178  c << QgsExpressionContextUtils::processingAlgorithmScope( this, parameters, context );
179  return c;
180 }
181 
182 bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, QgsProcessingContext &context ) const
183 {
184  if ( !( flags() & FlagRequiresMatchingCrs ) )
185  {
186  // I'm a well behaved algorithm - I take work AWAY from users!
187  return true;
188  }
189 
190  bool foundCrs = false;
192  for ( const QgsProcessingParameterDefinition *def : mParameters )
193  {
195  {
196  QgsMapLayer *layer = QgsProcessingParameters::parameterAsLayer( def, parameters, context );
197  if ( layer )
198  {
199  if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
200  {
201  return false;
202  }
203  else if ( !foundCrs && layer->crs().isValid() )
204  {
205  foundCrs = true;
206  crs = layer->crs();
207  }
208  }
209  }
210  else if ( def->type() == QgsProcessingParameterFeatureSource::typeName() )
211  {
212  std::unique_ptr< QgsFeatureSource > source( QgsProcessingParameters::parameterAsSource( def, parameters, context ) );
213  if ( source )
214  {
215  if ( foundCrs && source->sourceCrs().isValid() && crs != source->sourceCrs() )
216  {
217  return false;
218  }
219  else if ( !foundCrs && source->sourceCrs().isValid() )
220  {
221  foundCrs = true;
222  crs = source->sourceCrs();
223  }
224  }
225  }
226  else if ( def->type() == QgsProcessingParameterMultipleLayers::typeName() )
227  {
228  QList< QgsMapLayer *> layers = QgsProcessingParameters::parameterAsLayerList( def, parameters, context );
229  const auto constLayers = layers;
230  for ( QgsMapLayer *layer : constLayers )
231  {
232  if ( !layer )
233  continue;
234 
235  if ( foundCrs && layer->crs().isValid() && crs != layer->crs() )
236  {
237  return false;
238  }
239  else if ( !foundCrs && layer->crs().isValid() )
240  {
241  foundCrs = true;
242  crs = layer->crs();
243  }
244  }
245  }
246  else if ( def->type() == QgsProcessingParameterExtent::typeName() )
247  {
248  QgsCoordinateReferenceSystem extentCrs = QgsProcessingParameters::parameterAsExtentCrs( def, parameters, context );
249  if ( foundCrs && extentCrs.isValid() && crs != extentCrs )
250  {
251  return false;
252  }
253  else if ( !foundCrs && extentCrs.isValid() )
254  {
255  foundCrs = true;
256  crs = extentCrs;
257  }
258  }
259  else if ( def->type() == QgsProcessingParameterPoint::typeName() )
260  {
261  QgsCoordinateReferenceSystem pointCrs = QgsProcessingParameters::parameterAsPointCrs( def, parameters, context );
262  if ( foundCrs && pointCrs.isValid() && crs != pointCrs )
263  {
264  return false;
265  }
266  else if ( !foundCrs && pointCrs.isValid() )
267  {
268  foundCrs = true;
269  crs = pointCrs;
270  }
271  }
272  else if ( def->type() == QgsProcessingParameterGeometry::typeName() )
273  {
275  if ( foundCrs && geomCrs.isValid() && crs != geomCrs )
276  {
277  return false;
278  }
279  else if ( !foundCrs && geomCrs.isValid() )
280  {
281  foundCrs = true;
282  crs = geomCrs;
283  }
284  }
285 
286  }
287  return true;
288 }
289 
290 QString QgsProcessingAlgorithm::asPythonCommand( const QVariantMap &parameters, QgsProcessingContext &context ) const
291 {
292  QString s = QStringLiteral( "processing.run(\"%1\"," ).arg( id() );
293 
294  QStringList parts;
295  for ( const QgsProcessingParameterDefinition *def : mParameters )
296  {
298  continue;
299 
300  if ( !parameters.contains( def->name() ) )
301  continue;
302 
303  parts << QStringLiteral( "'%1':%2" ).arg( def->name(), def->valueAsPythonString( parameters.value( def->name() ), context ) );
304  }
305 
306  s += QStringLiteral( " {%1})" ).arg( parts.join( ',' ) );
307  return s;
308 }
309 
310 QString QgsProcessingAlgorithm::asQgisProcessCommand( const QVariantMap &parameters, QgsProcessingContext &context, bool &ok ) const
311 {
312  ok = true;
313  QStringList parts;
314  parts.append( QStringLiteral( "qgis_process" ) );
315  parts.append( QStringLiteral( "run" ) );
316  parts.append( id() );
317 
318  QgsProcessingContext::ProcessArgumentFlags argumentFlags;
319  // we only include the project path argument if a project is actually required by the algorithm
320  if ( flags() & FlagRequiresProject )
322 
323  parts.append( context.asQgisProcessArguments( argumentFlags ) );
324 
325  auto escapeIfNeeded = []( const QString & input ) -> QString
326  {
327  // play it safe and escape everything UNLESS it's purely alphanumeric characters (and a very select scattering of other common characters!)
328  const thread_local QRegularExpression nonAlphaNumericRx( QStringLiteral( "[^a-zA-Z0-9.\\-/_]" ) );
329  if ( nonAlphaNumericRx.match( input ).hasMatch() )
330  {
331  QString escaped = input;
332  escaped.replace( '\'', QLatin1String( "'\\''" ) );
333  return QStringLiteral( "'%1'" ).arg( escaped );
334  }
335  else
336  {
337  return input;
338  }
339  };
340 
341  for ( const QgsProcessingParameterDefinition *def : mParameters )
342  {
344  continue;
345 
346  if ( !parameters.contains( def->name() ) )
347  continue;
348 
349  const QStringList partValues = def->valueAsStringList( parameters.value( def->name() ), context, ok );
350  if ( !ok )
351  return QString();
352 
353  for ( const QString &partValue : partValues )
354  {
355  parts << QStringLiteral( "--%1=%2" ).arg( def->name(), escapeIfNeeded( partValue ) );
356  }
357  }
358 
359  return parts.join( ' ' );
360 }
361 
362 QVariantMap QgsProcessingAlgorithm::asMap( const QVariantMap &parameters, QgsProcessingContext &context ) const
363 {
364  QVariantMap properties = context.exportToMap();
365 
366  // we only include the project path argument if a project is actually required by the algorithm
367  if ( !( flags() & FlagRequiresProject ) )
368  properties.remove( QStringLiteral( "project_path" ) );
369 
370  QVariantMap paramValues;
371  for ( const QgsProcessingParameterDefinition *def : mParameters )
372  {
374  continue;
375 
376  if ( !parameters.contains( def->name() ) )
377  continue;
378 
379  paramValues.insert( def->name(), def->valueAsJsonObject( parameters.value( def->name() ), context ) );
380  }
381 
382  properties.insert( QStringLiteral( "inputs" ), paramValues );
383  return properties;
384 }
385 
387 {
388  if ( !definition )
389  return false;
390 
391  // check for duplicate named parameters
393  if ( existingDef && existingDef->name() == definition->name() ) // parameterDefinition is case-insensitive, but we DO allow case-different duplicate names
394  {
395  QgsMessageLog::logMessage( QObject::tr( "Duplicate parameter %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
396  delete definition;
397  return false;
398  }
399 
400  if ( definition->isDestination() && mProvider )
401  {
402  QgsProcessingDestinationParameter *destParam = static_cast< QgsProcessingDestinationParameter *>( definition );
403  if ( !mProvider->supportsNonFileBasedOutput() )
404  destParam->setSupportsNonFileBasedOutput( false );
405  }
406 
407  mParameters << definition;
408  definition->mAlgorithm = this;
409 
410  if ( createOutput )
411  return createAutoOutputForParameter( definition );
412  else
413  return true;
414 }
415 
416 void QgsProcessingAlgorithm::removeParameter( const QString &name )
417 {
419  if ( def )
420  {
421  delete def;
422  mParameters.removeAll( def );
423 
424  // remove output automatically created when adding parameter
426  if ( outputDef && outputDef->autoCreated() )
427  {
428  delete outputDef;
429  mOutputs.removeAll( outputDef );
430  }
431  }
432 }
433 
435 {
436  if ( !definition )
437  return false;
438 
439  // check for duplicate named outputs
440  if ( QgsProcessingAlgorithm::outputDefinition( definition->name() ) )
441  {
442  QgsMessageLog::logMessage( QObject::tr( "Duplicate output %1 registered for alg %2" ).arg( definition->name(), id() ), QObject::tr( "Processing" ) );
443  delete definition;
444  return false;
445  }
446 
447  mOutputs << definition;
448  return true;
449 }
450 
452 {
453  return true;
454 }
455 
457 {
458  return QVariantMap();
459 }
460 
462 {
463  // first pass - case sensitive match
464  for ( const QgsProcessingParameterDefinition *def : mParameters )
465  {
466  if ( def->name() == name )
467  return def;
468  }
469 
470  // second pass - case insensitive
471  for ( const QgsProcessingParameterDefinition *def : mParameters )
472  {
473  if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
474  return def;
475  }
476  return nullptr;
477 }
478 
480 {
481  int count = 0;
482  for ( const QgsProcessingParameterDefinition *def : mParameters )
483  {
484  if ( !( def->flags() & QgsProcessingParameterDefinition::FlagHidden ) )
485  count++;
486  }
487  return count;
488 }
489 
491 {
493  for ( const QgsProcessingParameterDefinition *def : mParameters )
494  {
495  if ( def->isDestination() )
496  result << def;
497  }
498  return result;
499 }
500 
502 {
503  for ( const QgsProcessingOutputDefinition *def : mOutputs )
504  {
505  if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
506  return def;
507  }
508  return nullptr;
509 }
510 
512 {
513  for ( const QgsProcessingOutputDefinition *def : mOutputs )
514  {
515  if ( def->type() == QLatin1String( "outputHtml" ) )
516  return true;
517  }
518  return false;
519 }
520 
521 QgsProcessingAlgorithm::VectorProperties QgsProcessingAlgorithm::sinkProperties( const QString &, const QVariantMap &, QgsProcessingContext &, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> & ) const
522 {
523  return VectorProperties();
524 }
525 
526 QVariantMap QgsProcessingAlgorithm::run( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback, bool *ok, const QVariantMap &configuration, bool catchExceptions ) const
527 {
528  std::unique_ptr< QgsProcessingAlgorithm > alg( create( configuration ) );
529  if ( ok )
530  *ok = false;
531 
532  bool res = alg->prepare( parameters, context, feedback );
533  if ( !res )
534  return QVariantMap();
535 
536  QVariantMap runRes;
537  try
538  {
539  runRes = alg->runPrepared( parameters, context, feedback );
540  }
541  catch ( QgsProcessingException &e )
542  {
543  if ( !catchExceptions )
544  throw e;
545 
546  QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
547  feedback->reportError( e.what() );
548  return QVariantMap();
549  }
550 
551  if ( ok )
552  *ok = true;
553 
554  QVariantMap ppRes = alg->postProcess( context, feedback );
555  if ( !ppRes.isEmpty() )
556  return ppRes;
557  else
558  return runRes;
559 }
560 
561 bool QgsProcessingAlgorithm::prepare( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
562 {
563  Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::prepare", "prepare() must be called from the same thread as context was created in" );
564  Q_ASSERT_X( !mHasPrepared, "QgsProcessingAlgorithm::prepare", "prepare() has already been called for the algorithm instance" );
565  try
566  {
567  mHasPrepared = prepareAlgorithm( parameters, context, feedback );
568  return mHasPrepared;
569  }
570  catch ( QgsProcessingException &e )
571  {
572  QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
573  feedback->reportError( e.what() );
574  return false;
575  }
576 }
577 
578 QVariantMap QgsProcessingAlgorithm::runPrepared( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
579 {
580  Q_ASSERT_X( mHasPrepared, "QgsProcessingAlgorithm::runPrepared", QStringLiteral( "prepare() was not called for the algorithm instance %1" ).arg( name() ).toLatin1() );
581  Q_ASSERT_X( !mHasExecuted, "QgsProcessingAlgorithm::runPrepared", "runPrepared() was already called for this algorithm instance" );
582 
583  // Hey kids, let's all be thread safe! It's the fun thing to do!
584  //
585  // First, let's see if we're going to run into issues.
586  QgsProcessingContext *runContext = nullptr;
587  if ( context.thread() == QThread::currentThread() )
588  {
589  // OH. No issues. Seems you're running everything in the same thread, so go about your business. Sorry about
590  // the intrusion, we're just making sure everything's nice and safe here. We like to keep a clean and tidy neighbourhood,
591  // you know, for the kids and dogs and all.
592  runContext = &context;
593  }
594  else
595  {
596  // HA! I knew things looked a bit suspicious - seems you're running this algorithm in a different thread
597  // from that which the passed context has an affinity for. That's fine and all, but we need to make sure
598  // we proceed safely...
599 
600  // So first we create a temporary local context with affinity for the current thread
601  mLocalContext.reset( new QgsProcessingContext() );
602  // copy across everything we can safely do from the passed context
603  mLocalContext->copyThreadSafeSettings( context );
604  // and we'll run the actual algorithm processing using the local thread safe context
605  runContext = mLocalContext.get();
606  }
607 
608  try
609  {
610  QVariantMap runResults = processAlgorithm( parameters, *runContext, feedback );
611 
612  mHasExecuted = true;
613  if ( mLocalContext )
614  {
615  // ok, time to clean things up. We need to push the temporary context back into
616  // the thread that the passed context is associated with (we can only push from the
617  // current thread, so we HAVE to do this here)
618  mLocalContext->pushToThread( context.thread() );
619  }
620  return runResults;
621  }
622  catch ( QgsProcessingException & )
623  {
624  if ( mLocalContext )
625  {
626  // see above!
627  mLocalContext->pushToThread( context.thread() );
628  }
629  //rethrow
630  throw;
631  }
632 }
633 
635 {
636  Q_ASSERT_X( QThread::currentThread() == context.temporaryLayerStore()->thread(), "QgsProcessingAlgorithm::postProcess", "postProcess() must be called from the same thread the context was created in" );
637  Q_ASSERT_X( mHasExecuted, "QgsProcessingAlgorithm::postProcess", QStringLiteral( "algorithm instance %1 was not executed" ).arg( name() ).toLatin1() );
638  Q_ASSERT_X( !mHasPostProcessed, "QgsProcessingAlgorithm::postProcess", "postProcess() was already called for this algorithm instance" );
639 
640  if ( mLocalContext )
641  {
642  // algorithm was processed using a temporary thread safe context. So now we need
643  // to take the results from that temporary context, and smash them into the passed
644  // context
645  context.takeResultsFrom( *mLocalContext );
646  // now get lost, we don't need you anymore
647  mLocalContext.reset();
648  }
649 
650  mHasPostProcessed = true;
651  try
652  {
653  return postProcessAlgorithm( context, feedback );
654  }
655  catch ( QgsProcessingException &e )
656  {
657  QgsMessageLog::logMessage( e.what(), QObject::tr( "Processing" ), Qgis::MessageLevel::Critical );
658  feedback->reportError( e.what() );
659  return QVariantMap();
660  }
661 }
662 
663 QString QgsProcessingAlgorithm::parameterAsString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
664 {
665  return QgsProcessingParameters::parameterAsString( parameterDefinition( name ), parameters, context );
666 }
667 
668 QString QgsProcessingAlgorithm::parameterAsExpression( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
669 {
671 }
672 
673 double QgsProcessingAlgorithm::parameterAsDouble( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
674 {
675  return QgsProcessingParameters::parameterAsDouble( parameterDefinition( name ), parameters, context );
676 }
677 
678 int QgsProcessingAlgorithm::parameterAsInt( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
679 {
680  return QgsProcessingParameters::parameterAsInt( parameterDefinition( name ), parameters, context );
681 }
682 
683 QList<int> QgsProcessingAlgorithm::parameterAsInts( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
684 {
685  return QgsProcessingParameters::parameterAsInts( parameterDefinition( name ), parameters, context );
686 }
687 
688 int QgsProcessingAlgorithm::parameterAsEnum( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
689 {
690  return QgsProcessingParameters::parameterAsEnum( parameterDefinition( name ), parameters, context );
691 }
692 
693 QList<int> QgsProcessingAlgorithm::parameterAsEnums( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
694 {
695  return QgsProcessingParameters::parameterAsEnums( parameterDefinition( name ), parameters, context );
696 }
697 
698 QString QgsProcessingAlgorithm::parameterAsEnumString( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
699 {
701 }
702 
703 QStringList QgsProcessingAlgorithm::parameterAsEnumStrings( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
704 {
706 }
707 
708 bool QgsProcessingAlgorithm::parameterAsBool( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
709 {
710  return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
711 }
712 
713 bool QgsProcessingAlgorithm::parameterAsBoolean( const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context ) const
714 {
715  return QgsProcessingParameters::parameterAsBool( parameterDefinition( name ), parameters, context );
716 }
717 
718 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
719 {
720  if ( !parameterDefinition( name ) )
721  throw QgsProcessingException( QObject::tr( "No parameter definition for the sink '%1'" ).arg( name ) );
722 
723  return QgsProcessingParameters::parameterAsSink( parameterDefinition( name ), parameters, fields, geometryType, crs, context, destinationIdentifier, sinkFlags, createOptions, datasourceOptions, layerOptions );
724 }
725 
726 QgsProcessingFeatureSource *QgsProcessingAlgorithm::parameterAsSource( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
727 {
728  return QgsProcessingParameters::parameterAsSource( parameterDefinition( name ), parameters, context );
729 }
730 
731 QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback ) const
732 {
733  return QgsProcessingParameters::parameterAsCompatibleSourceLayerPath( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback );
734 }
735 
736 QString QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPathAndLayerName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat, QgsProcessingFeedback *feedback, QString *layerName ) const
737 {
738  return QgsProcessingParameters::parameterAsCompatibleSourceLayerPathAndLayerName( parameterDefinition( name ), parameters, context, compatibleFormats, preferredFormat, feedback, layerName );
739 }
740 
741 QgsMapLayer *QgsProcessingAlgorithm::parameterAsLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
742 {
743  return QgsProcessingParameters::parameterAsLayer( parameterDefinition( name ), parameters, context );
744 }
745 
746 QgsRasterLayer *QgsProcessingAlgorithm::parameterAsRasterLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
747 {
749 }
750 
751 QgsMeshLayer *QgsProcessingAlgorithm::parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
752 {
754 }
755 
756 QString QgsProcessingAlgorithm::parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
757 {
759 }
760 
761 QString QgsProcessingAlgorithm::parameterAsFileOutput( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
762 {
764 }
765 
766 QgsVectorLayer *QgsProcessingAlgorithm::parameterAsVectorLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
767 {
769 }
770 
771 QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
772 {
773  return QgsProcessingParameters::parameterAsCrs( parameterDefinition( name ), parameters, context );
774 }
775 
776 QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsExtentCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
777 {
779 }
780 
781 QgsRectangle QgsProcessingAlgorithm::parameterAsExtent( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
782 {
783  return QgsProcessingParameters::parameterAsExtent( parameterDefinition( name ), parameters, context, crs );
784 }
785 
786 QgsGeometry QgsProcessingAlgorithm::parameterAsExtentGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
787 {
789 }
790 
791 QgsPointXY QgsProcessingAlgorithm::parameterAsPoint( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
792 {
793  return QgsProcessingParameters::parameterAsPoint( parameterDefinition( name ), parameters, context, crs );
794 }
795 
796 QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsPointCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
797 {
799 }
800 
801 QgsGeometry QgsProcessingAlgorithm::parameterAsGeometry( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs ) const
802 {
804 }
805 
806 QgsCoordinateReferenceSystem QgsProcessingAlgorithm::parameterAsGeometryCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
807 {
809 }
810 
811 QString QgsProcessingAlgorithm::parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
812 {
813  return QgsProcessingParameters::parameterAsFile( parameterDefinition( name ), parameters, context );
814 }
815 
816 QVariantList QgsProcessingAlgorithm::parameterAsMatrix( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
817 {
818  return QgsProcessingParameters::parameterAsMatrix( parameterDefinition( name ), parameters, context );
819 }
820 
821 QList<QgsMapLayer *> QgsProcessingAlgorithm::parameterAsLayerList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
822 {
824 }
825 
826 QStringList QgsProcessingAlgorithm::parameterAsFileList( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
827 {
829 }
830 
831 QList<double> QgsProcessingAlgorithm::parameterAsRange( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
832 {
833  return QgsProcessingParameters::parameterAsRange( parameterDefinition( name ), parameters, context );
834 }
835 
836 QStringList QgsProcessingAlgorithm::parameterAsFields( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
837 {
838  return QgsProcessingParameters::parameterAsFields( parameterDefinition( name ), parameters, context );
839 }
840 
841 QgsPrintLayout *QgsProcessingAlgorithm::parameterAsLayout( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context )
842 {
843  return QgsProcessingParameters::parameterAsLayout( parameterDefinition( name ), parameters, context );
844 }
845 
846 QgsLayoutItem *QgsProcessingAlgorithm::parameterAsLayoutItem( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, QgsPrintLayout *layout )
847 {
848  return QgsProcessingParameters::parameterAsLayoutItem( parameterDefinition( name ), parameters, context, layout );
849 }
850 
851 QColor QgsProcessingAlgorithm::parameterAsColor( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
852 {
853  return QgsProcessingParameters::parameterAsColor( parameterDefinition( name ), parameters, context );
854 }
855 
856 QString QgsProcessingAlgorithm::parameterAsConnectionName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
857 {
859 }
860 
861 QDateTime QgsProcessingAlgorithm::parameterAsDateTime( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
862 {
864 }
865 
866 QString QgsProcessingAlgorithm::parameterAsSchema( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
867 {
868  return QgsProcessingParameters::parameterAsSchema( parameterDefinition( name ), parameters, context );
869 }
870 
871 QString QgsProcessingAlgorithm::parameterAsDatabaseTableName( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
872 {
874 }
875 
876 QgsPointCloudLayer *QgsProcessingAlgorithm::parameterAsPointCloudLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
877 {
879 }
880 
881 QgsAnnotationLayer *QgsProcessingAlgorithm::parameterAsAnnotationLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
882 {
884 }
885 
886 QString QgsProcessingAlgorithm::invalidSourceError( const QVariantMap &parameters, const QString &name )
887 {
888  if ( !parameters.contains( name ) )
889  return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
890  else
891  {
892  QVariant var = parameters.value( name );
893  if ( var.canConvert<QgsProcessingFeatureSourceDefinition>() )
894  {
895  QgsProcessingFeatureSourceDefinition fromVar = qvariant_cast<QgsProcessingFeatureSourceDefinition>( var );
896  var = fromVar.source;
897  }
898  else if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
899  {
900  QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
901  var = fromVar.sink;
902  }
903  if ( var.canConvert<QgsProperty>() )
904  {
905  QgsProperty p = var.value< QgsProperty >();
907  {
908  var = p.staticValue();
909  }
910  }
911  if ( !var.toString().isEmpty() )
912  return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
913  else
914  return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
915  }
916 }
917 
918 QString QgsProcessingAlgorithm::invalidRasterError( const QVariantMap &parameters, const QString &name )
919 {
920  if ( !parameters.contains( name ) )
921  return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name );
922  else
923  {
924  QVariant var = parameters.value( name );
925  if ( var.canConvert<QgsProperty>() )
926  {
927  QgsProperty p = var.value< QgsProperty >();
929  {
930  var = p.staticValue();
931  }
932  }
933  if ( !var.toString().isEmpty() )
934  return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() );
935  else
936  return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name );
937  }
938 }
939 
940 QString QgsProcessingAlgorithm::invalidSinkError( const QVariantMap &parameters, const QString &name )
941 {
942  if ( !parameters.contains( name ) )
943  return QObject::tr( "Could not create destination layer for %1: no value specified for parameter" ).arg( name );
944  else
945  {
946  QVariant var = parameters.value( name );
947  if ( var.canConvert<QgsProcessingOutputLayerDefinition>() )
948  {
949  QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var );
950  var = fromVar.sink;
951  }
952  if ( var.canConvert<QgsProperty>() )
953  {
954  QgsProperty p = var.value< QgsProperty >();
956  {
957  var = p.staticValue();
958  }
959  }
960  if ( !var.toString().isEmpty() )
961  return QObject::tr( "Could not create destination layer for %1: %2" ).arg( name, var.toString() );
962  else
963  return QObject::tr( "Could not create destination layer for %1: invalid value" ).arg( name );
964  }
965 }
966 
967 QString QgsProcessingAlgorithm::writeFeatureError( QgsFeatureSink *sink, const QVariantMap &parameters, const QString &name )
968 {
969  Q_UNUSED( sink );
970  Q_UNUSED( parameters );
971  if ( !name.isEmpty() )
972  return QObject::tr( "Could not write feature into %1" ).arg( name );
973  else
974  return QObject::tr( "Could not write feature" );
975 }
976 
978 {
979  Q_UNUSED( layer )
980  return false;
981 }
982 
983 
984 bool QgsProcessingAlgorithm::createAutoOutputForParameter( QgsProcessingParameterDefinition *parameter )
985 {
986  if ( !parameter->isDestination() )
987  return true; // nothing created, but nothing went wrong - so return true
988 
989  QgsProcessingDestinationParameter *dest = static_cast< QgsProcessingDestinationParameter * >( parameter );
991  if ( !output )
992  return true; // nothing created - but nothing went wrong - so return true
993  output->setAutoCreated( true );
994 
995  if ( !addOutput( output ) )
996  {
997  // couldn't add output - probably a duplicate name
998  return false;
999  }
1000  else
1001  {
1002  return true;
1003  }
1004 }
1005 
1006 
1007 //
1008 // QgsProcessingFeatureBasedAlgorithm
1009 //
1010 
1011 QgsProcessingAlgorithm::Flags QgsProcessingFeatureBasedAlgorithm::flags() const
1012 {
1013  Flags f = QgsProcessingAlgorithm::flags();
1015  return f;
1016 }
1017 
1018 void QgsProcessingFeatureBasedAlgorithm::initAlgorithm( const QVariantMap &config )
1019 {
1021  initParameters( config );
1022  addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), outputName(), outputLayerType(), QVariant(), false, true, true ) );
1023 }
1024 
1026 {
1027  return QStringLiteral( "INPUT" );
1028 }
1029 
1031 {
1032  return QObject::tr( "Input layer" );
1033 }
1034 
1036 {
1037  return QList<int>();
1038 }
1039 
1041 {
1043 }
1044 
1046 {
1047  return static_cast<QgsProcessingFeatureSource::Flag>( 0 );
1048 }
1049 
1050 QgsFeatureSink::SinkFlags QgsProcessingFeatureBasedAlgorithm::sinkFlags() const
1051 {
1052  return QgsFeatureSink::SinkFlags();
1053 }
1054 
1056 {
1057  return inputWkbType;
1058 }
1059 
1061 {
1062  return inputFields;
1063 }
1064 
1066 {
1067  return inputCrs;
1068 }
1069 
1071 {
1072 }
1073 
1075 {
1076  if ( mSource )
1077  return mSource->sourceCrs();
1078  else
1080 }
1081 
1082 QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
1083 {
1084  prepareSource( parameters, context );
1085  QString dest;
1086  std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, dest,
1087  outputFields( mSource->fields() ),
1088  outputWkbType( mSource->wkbType() ),
1089  outputCrs( mSource->sourceCrs() ),
1090  sinkFlags() ) );
1091  if ( !sink )
1092  throw QgsProcessingException( invalidSinkError( parameters, QStringLiteral( "OUTPUT" ) ) );
1093 
1094  // prepare expression context for feature iteration
1095  QgsExpressionContext prevContext = context.expressionContext();
1096  QgsExpressionContext algContext = prevContext;
1097 
1098  algContext.appendScopes( createExpressionContext( parameters, context, mSource.get() ).takeScopes() );
1099  context.setExpressionContext( algContext );
1100 
1101  long count = mSource->featureCount();
1102 
1103  QgsFeature f;
1104  QgsFeatureIterator it = mSource->getFeatures( request(), sourceFlags() );
1105 
1106  double step = count > 0 ? 100.0 / count : 1;
1107  int current = 0;
1108  while ( it.nextFeature( f ) )
1109  {
1110  if ( feedback->isCanceled() )
1111  {
1112  break;
1113  }
1114 
1115  context.expressionContext().setFeature( f );
1116  const QgsFeatureList transformed = processFeature( f, context, feedback );
1117  for ( QgsFeature transformedFeature : transformed )
1118  sink->addFeature( transformedFeature, QgsFeatureSink::FastInsert );
1119 
1120  feedback->setProgress( current * step );
1121  current++;
1122  }
1123 
1124  mSource.reset();
1125 
1126  // probably not necessary - context's aren't usually recycled, but can't hurt
1127  context.setExpressionContext( prevContext );
1128 
1129  QVariantMap outputs;
1130  outputs.insert( QStringLiteral( "OUTPUT" ), dest );
1131  return outputs;
1132 }
1133 
1135 {
1136  return QgsFeatureRequest();
1137 }
1138 
1140 {
1141  const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
1142  if ( !layer )
1143  return false;
1144 
1145  QgsWkbTypes::GeometryType inPlaceGeometryType = layer->geometryType();
1146  if ( !inputLayerTypes().empty() &&
1147  !inputLayerTypes().contains( QgsProcessing::TypeVector ) &&
1149  ( ( inPlaceGeometryType == QgsWkbTypes::PolygonGeometry && !inputLayerTypes().contains( QgsProcessing::TypeVectorPolygon ) ) ||
1150  ( inPlaceGeometryType == QgsWkbTypes::LineGeometry && !inputLayerTypes().contains( QgsProcessing::TypeVectorLine ) ) ||
1151  ( inPlaceGeometryType == QgsWkbTypes::PointGeometry && !inputLayerTypes().contains( QgsProcessing::TypeVectorPoint ) ) ) )
1152  return false;
1153 
1155  if ( inPlaceGeometryType == QgsWkbTypes::PointGeometry )
1156  type = QgsWkbTypes::Point;
1157  else if ( inPlaceGeometryType == QgsWkbTypes::LineGeometry )
1158  type = QgsWkbTypes::LineString;
1159  else if ( inPlaceGeometryType == QgsWkbTypes::PolygonGeometry )
1160  type = QgsWkbTypes::Polygon;
1161 
1162  if ( QgsWkbTypes::geometryType( outputWkbType( type ) ) != inPlaceGeometryType )
1163  return false;
1164 
1165  return true;
1166 }
1167 
1168 void QgsProcessingFeatureBasedAlgorithm::prepareSource( const QVariantMap &parameters, QgsProcessingContext &context )
1169 {
1170  if ( ! mSource )
1171  {
1172  mSource.reset( parameterAsSource( parameters, inputParameterName(), context ) );
1173  if ( !mSource )
1175  }
1176 }
1177 
1178 
1179 QgsProcessingAlgorithm::VectorProperties QgsProcessingFeatureBasedAlgorithm::sinkProperties( const QString &sink, const QVariantMap &parameters, QgsProcessingContext &context, const QMap<QString, QgsProcessingAlgorithm::VectorProperties> &sourceProperties ) const
1180 {
1182  if ( sink == QLatin1String( "OUTPUT" ) )
1183  {
1184  if ( sourceProperties.value( QStringLiteral( "INPUT" ) ).availability == QgsProcessingAlgorithm::Available )
1185  {
1186  const VectorProperties inputProps = sourceProperties.value( QStringLiteral( "INPUT" ) );
1187  result.fields = outputFields( inputProps.fields );
1188  result.crs = outputCrs( inputProps.crs );
1189  result.wkbType = outputWkbType( inputProps.wkbType );
1190  result.availability = Available;
1191  return result;
1192  }
1193  else
1194  {
1195  std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );
1196  if ( source )
1197  {
1198  result.fields = outputFields( source->fields() );
1199  result.crs = outputCrs( source->sourceCrs() );
1200  result.wkbType = outputWkbType( source->wkbType() );
1201  result.availability = Available;
1202  return result;
1203  }
1204  }
1205  }
1206  return result;
1207 }
1208 
QgsProcessingContext::asQgisProcessArguments
QStringList asQgisProcessArguments(QgsProcessingContext::ProcessArgumentFlags flags=QgsProcessingContext::ProcessArgumentFlags()) const
Returns list of the equivalent qgis_process arguments representing the settings from the context.
Definition: qgsprocessingcontext.cpp:157
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsProcessingAlgorithm::parameterAsEnumString
QString parameterAsEnumString(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to a static enum string.
Definition: qgsprocessingalgorithm.cpp:698
QgsMapLayer::crs
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:79
QgsProcessingAlgorithm::shortDescription
virtual QString shortDescription() const
Returns an optional translated short description of the algorithm.
Definition: qgsprocessingalgorithm.cpp:60
QgsProcessingDestinationParameter::toOutputDefinition
virtual QgsProcessingOutputDefinition * toOutputDefinition() const =0
Returns a new QgsProcessingOutputDefinition corresponding to the definition of the destination parame...
QgsProcessingAlgorithm::parameterAsEnumStrings
QStringList parameterAsEnumStrings(const QVariantMap &parameters, const QString &name, const QgsProcessingContext &context) const
Evaluates the parameter with matching name to list of static enum strings.
Definition: qgsprocessingalgorithm.cpp:703
qgsexpressioncontextutils.h
QgsFeedback::setProgress
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition: qgsfeedback.h:76
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:1712
QgsExpressionContext::appendScopes
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Definition: qgsexpressioncontext.cpp:499
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:834
QgsProcessingAlgorithm::prepare
bool prepare(const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Prepares the algorithm for execution.
Definition: qgsprocessingalgorithm.cpp:561
QgsProcessingAlgorithm::removeParameter
void removeParameter(const QString &name)
Removes the parameter with matching name from the algorithm, and deletes any existing definition.
Definition: qgsprocessingalgorithm.cpp:416
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:1050
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:826
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:2126
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:886
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:841
QgsProperty
A store for object properties.
Definition: qgsproperty.h:230
QgsProcessingAlgorithm::canExecute
virtual bool canExecute(QString *errorMessage=nullptr) const
Returns true if the algorithm can execute.
Definition: qgsprocessingalgorithm.cpp:95
QgsWkbTypes::Point
@ Point
Definition: qgswkbtypes.h:72
QgsProcessingAlgorithm::parameterAsDatabaseTableName
QString parameterAsDatabaseTableName(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a database table name string.
Definition: qgsprocessingalgorithm.cpp:871
QgsProcessingParameterDefinition::mAlgorithm
QgsProcessingAlgorithm * mAlgorithm
Pointer to algorithm which owns this parameter.
Definition: qgsprocessingparameters.h:867
QgsProcessingFeatureBasedAlgorithm::prepareSource
void prepareSource(const QVariantMap &parameters, QgsProcessingContext &context)
Read the source from parameters and context and set it.
Definition: qgsprocessingalgorithm.cpp:1168
QgsExpressionContextUtils::globalScope
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Definition: qgsexpressioncontextutils.cpp:40
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:447
qgsrectangle.h
QgsProcessingParameters::parameterAsEnumStrings
static QStringList parameterAsEnumStrings(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to list of static enum strings.
Definition: qgsprocessingparameters.cpp:537
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:1517
QgsProcessingContext::project
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Definition: qgsprocessingcontext.h:121
QgsProcessingAlgorithm::VectorProperties::fields
QgsFields fields
Fields.
Definition: qgsprocessingalgorithm.h:339
QgsProcessingContext::ProcessArgumentFlag::IncludeProjectPath
@ IncludeProjectPath
Include the associated project path argument.
QgsProcessingProvider::id
virtual QString id() const =0
Returns the unique provider id, used for identifying the provider.
QgsProcessingAlgorithm::parameterAsColor
QColor parameterAsColor(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a color, or returns an invalid color if the parameter w...
Definition: qgsprocessingalgorithm.cpp:851
QgsProcessingAlgorithm::VectorProperties::crs
QgsCoordinateReferenceSystem crs
Coordinate Reference System.
Definition: qgsprocessingalgorithm.h:345
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition: qgsprocessingfeedback.h:37
QgsPointCloudLayer
Represents a map layer supporting display of point clouds.
Definition: qgspointcloudlayer.h:45
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:1055
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:2156
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsProcessingAlgorithm::parameterAsExtentGeometry
QgsGeometry parameterAsExtentGeometry(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem()) const
Evaluates the parameter with matching name to a rectangular extent, and returns a geometry covering t...
Definition: qgsprocessingalgorithm.cpp:786
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:1971
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:683
QgsProcessingFeedback::reportError
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
Definition: qgsprocessingfeedback.cpp:59
QgsProcessingAlgorithm::parameterAsCompatibleSourceLayerPath
QString parameterAsCompatibleSourceLayerPath(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context, const QStringList &compatibleFormats, const QString &preferredFormat=QString("shp"), QgsProcessingFeedback *feedback=nullptr) const
Evaluates the parameter with matching name to a source vector layer file path of compatible format.
Definition: qgsprocessingalgorithm.cpp:731
QgsProcessing::TypeVectorPolygon
@ TypeVectorPolygon
Vector polygon layers.
Definition: qgsprocessing.h:51
QgsProcessingFeatureSource::createExpressionContextScope
QgsExpressionContextScope * createExpressionContextScope() const
Returns an expression context scope suitable for this source.
Definition: qgsprocessingutils.cpp:1512
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:386
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:766
QgsFields
Container of fields for a vector layer.
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:1030
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:851
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:1317
QgsProcessingFeatureBasedAlgorithm::initParameters
virtual void initParameters(const QVariantMap &configuration=QVariantMap())
Initializes any extra parameters added by the algorithm subclass.
Definition: qgsprocessingalgorithm.cpp:1070
QgsProcessingAlgorithm::parameterAsExtentCrs
QgsCoordinateReferenceSystem parameterAsExtentCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Returns the coordinate reference system associated with an extent parameter value.
Definition: qgsprocessingalgorithm.cpp:776
QgsFeedback::isCanceled
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
Definition: qgsfeedback.h:67
QgsProcessingParameterGeometry::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:1853
QgsProcessingContext::thread
QThread * thread()
Returns the thread in which the context lives.
Definition: qgsprocessingcontext.h:524
QgsProcessingParameterMultipleLayers::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:2111
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:334
QgsProcessing::TypeVectorLine
@ TypeVectorLine
Vector line layers.
Definition: qgsprocessing.h:50
QgsProcessingAlgorithm::asMap
virtual QVariantMap asMap(const QVariantMap &parameters, QgsProcessingContext &context) const
Returns a JSON serializable variant map containing the specified parameters and context settings.
Definition: qgsprocessingalgorithm.cpp:362
QgsProcessingAlgorithm::svgIconPath
virtual QString svgIconPath() const
Returns a path to an SVG version of the algorithm's icon.
Definition: qgsprocessingalgorithm.cpp:85
QgsProcessingParameterFeatureSource
An input feature source (such as vector layers) parameter for processing algorithms.
Definition: qgsprocessingparameters.h:3057
QgsProcessingOutputLayerDefinition
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
Definition: qgsprocessingparameters.h:202
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
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:526
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:182
QgsProperty::propertyType
Type propertyType() const
Returns the property type.
Definition: qgsproperty.cpp:286
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:1139
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:451
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:688
QgsApplication::iconPath
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
Definition: qgsapplication.cpp:682
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:663
QgsProcessing::TypeVectorPoint
@ TypeVectorPoint
Vector point layers.
Definition: qgsprocessing.h:49
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:2141
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:908
QgsProcessingFeatureSourceDefinition::source
QgsProperty source
Source definition.
Definition: qgsprocessingparameters.h:119
QgsProcessingAlgorithm::outputDefinition
const QgsProcessingOutputDefinition * outputDefinition(const QString &name) const
Returns a matching output by name.
Definition: qgsprocessingalgorithm.cpp:501
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:100
QgsExpressionContext::takeScopes
QList< QgsExpressionContextScope * > takeScopes()
Returns all scopes from this context and remove them, leaving this context without any context.
Definition: qgsexpressioncontext.cpp:512
QgsRectangle
A rectangle specified with double values.
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:673
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:1050
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:585
QgsProcessingAlgorithm::Available
@ Available
Properties are available.
Definition: qgsprocessingalgorithm.h:328
QgsProcessingParameterDefinitions
QList< const QgsProcessingParameterDefinition * > QgsProcessingParameterDefinitions
List of processing parameters.
Definition: qgsprocessingparameters.h:889
QgsProcessingAlgorithm::parameterAsPointCrs
QgsCoordinateReferenceSystem parameterAsPointCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Returns the coordinate reference system associated with an point parameter value.
Definition: qgsprocessingalgorithm.cpp:796
QgsProcessingFeatureBasedAlgorithm::sourceFlags
virtual QgsProcessingFeatureSource::Flag sourceFlags() const
Returns the processing feature source flags to be used in the algorithm.
Definition: qgsprocessingalgorithm.cpp:1045
QgsProcessingParameterFeatureSink::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:3235
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:713
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:3134
QgsProcessingParameterFeatureSink
A feature sink output for processing algorithms.
Definition: qgsprocessingparameters.h:3219
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:1905
QgsProcessingDestinationParameter
Base class for all parameter definitions which represent file or layer destinations,...
Definition: qgsprocessingparameters.h:3097
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:1690
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:756
QgsProcessingOutputDefinition
Base class for the definition of processing outputs.
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:1756
QgsProcessingAlgorithm::addOutput
bool addOutput(QgsProcessingOutputDefinition *outputDefinition)
Adds an output definition to the algorithm.
Definition: qgsprocessingalgorithm.cpp:434
QgsProcessingFeatureSourceDefinition
Encapsulates settings relating to a feature source input to a processing algorithm.
Definition: qgsprocessingparameters.h:57
QgsProcessingOutputDefinition::autoCreated
bool autoCreated() const
Returns true if the output was automatically created when adding a parameter.
Definition: qgsprocessingoutputs.h:130
QgsFeatureRequest
This class wraps a request for features to a vector layer (or directly its vector data provider).
Definition: qgsfeaturerequest.h:83
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:811
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:291
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:1199
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:821
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:846
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:1066
qgspointcloudlayer.h
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:115
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:54
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:52
QgsProcessingFeatureBasedAlgorithm::initAlgorithm
void initAlgorithm(const QVariantMap &configuration=QVariantMap()) override
Initializes the algorithm using the specified configuration.
Definition: qgsprocessingalgorithm.cpp:1018
QgsProcessingAlgorithm::parameterAsAnnotationLayer
QgsAnnotationLayer * parameterAsAnnotationLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to an annotation layer.
Definition: qgsprocessingalgorithm.cpp:881
QgsProcessingParameterRasterLayer::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:2508
QgsProcessingParameterPoint::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:1818
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:1785
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:1040
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:1399
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:308
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition: qgsprocessingcontext.h:46
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:521
QgsProcessingAlgorithm::parameterAsPointCloudLayer
QgsPointCloudLayer * parameterAsPointCloudLayer(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a point cloud layer.
Definition: qgsprocessingalgorithm.cpp:876
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:918
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:1011
QgsProcessingParameters::parameterAsAnnotationLayer
static QgsAnnotationLayer * parameterAsAnnotationLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to an annotation layer.
Definition: qgsprocessingparameters.cpp:2181
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:98
QgsProcessingAlgorithm::~QgsProcessingAlgorithm
virtual ~QgsProcessingAlgorithm()
Definition: qgsprocessingalgorithm.cpp:36
QgsProcessingParameterDefinition::name
QString name() const
Returns the name of the parameter.
Definition: qgsprocessingparameters.h:488
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:839
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:1082
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:290
QgsProcessing::TypeVectorAnyGeometry
@ TypeVectorAnyGeometry
Any vector layer with geometry.
Definition: qgsprocessing.h:48
QgsProcessingAlgorithm::hasHtmlOutputs
bool hasHtmlOutputs() const
Returns true if this algorithm generates HTML outputs.
Definition: qgsprocessingalgorithm.cpp:511
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:836
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:252
QgsProcessingAlgorithm::parameterAsSchema
QString parameterAsSchema(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a database schema name string.
Definition: qgsprocessingalgorithm.cpp:866
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:850
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:1065
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:882
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:801
qgsprocessingfeedback.h
QgsMessageLog::logMessage
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Definition: qgsmessagelog.cpp:27
QgsCoordinateReferenceSystem::isValid
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Definition: qgscoordinatereferencesystem.cpp:977
QgsProcessingContext::exportToMap
QVariantMap exportToMap() const
Exports the context's settings to a variant map.
Definition: qgsprocessingcontext.cpp:142
QgsProcessingAlgorithm::shortHelpString
virtual QString shortHelpString() const
Returns a localised short helper string for the algorithm.
Definition: qgsprocessingalgorithm.cpp:65
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:2029
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:1483
QgsProcessingContext::setExpressionContext
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Definition: qgsprocessingcontext.h:159
QgsProcessingAlgorithm::parameterAsGeometryCrs
QgsCoordinateReferenceSystem parameterAsGeometryCrs(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Returns the coordinate reference system associated with a geometry parameter value.
Definition: qgsprocessingalgorithm.cpp:806
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:831
QgsProcessingAlgorithm::parameterAsConnectionName
QString parameterAsConnectionName(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a connection name string.
Definition: qgsprocessingalgorithm.cpp:856
QgsProcessingAlgorithm::FlagRequiresProject
@ FlagRequiresProject
The algorithm requires that a valid QgsProject is available from the processing context in order to e...
Definition: qgsprocessingalgorithm.h:84
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:741
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:781
QgsProcessingParameterFeatureSource::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:3071
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:76
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:1851
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:578
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:1637
QgsProcessingParameters::parameterAsPointCloudLayer
static QgsPointCloudLayer * parameterAsPointCloudLayer(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context)
Evaluates the parameter with matching definition to a point cloud layer.
Definition: qgsprocessingparameters.cpp:2171
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:977
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:1040
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsProcessingContext::temporaryLayerStore
QgsMapLayerStore * temporaryLayerStore()
Returns a reference to the layer store used for storing temporary layers during algorithm execution.
Definition: qgsprocessingcontext.h:255
QgsProcessingAlgorithm::destinationParameterDefinitions
QgsProcessingParameterDefinitions destinationParameterDefinitions() const
Returns a list of destination parameters definitions utilized by the algorithm.
Definition: qgsprocessingalgorithm.cpp:490
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:113
QgsProcessingAlgorithm::asQgisProcessCommand
virtual QString asQgisProcessCommand(const QVariantMap &parameters, QgsProcessingContext &context, bool &ok) const
Returns a command string which will execute the algorithm using the specified parameters via the comm...
Definition: qgsprocessingalgorithm.cpp:310
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:1060
qgsvectorlayer.h
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
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:918
QgsProcessingAlgorithm::helpUrl
virtual QString helpUrl() const
Returns a url pointing to the algorithm's help page.
Definition: qgsprocessingalgorithm.cpp:75
qgsprocessingoutputs.h
QgsProcessingAlgorithm::FlagCanCancel
@ FlagCanCancel
Algorithm can be canceled.
Definition: qgsprocessingalgorithm.h:74
qgsprocessingutils.h
QgsProcessingAlgorithm::setProvider
void setProvider(QgsProcessingProvider *provider)
Associates this algorithm with its provider.
Definition: qgsprocessingalgorithm.cpp:135
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:153
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:746
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:582
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:708
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:140
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:761
QgsProcessingAlgorithm::countVisibleParameters
int countVisibleParameters() const
Returns the number of visible (non-hidden) parameters defined by this algorithm.
Definition: qgsprocessingalgorithm.cpp:479
QgsFeatureIterator::nextFeature
bool nextFeature(QgsFeature &f)
Definition: qgsfeatureiterator.h:399
QgsProcessingAlgorithm::icon
virtual QIcon icon() const
Returns an icon for the algorithm.
Definition: qgsprocessingalgorithm.cpp:80
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:1025
QgsProcessingParameterDefinition::FlagHidden
@ FlagHidden
Parameter is hidden and should not be shown to users.
Definition: qgsprocessingparameters.h:452
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:1179
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
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:791
QgsProcessingAlgorithm::create
QgsProcessingAlgorithm * create(const QVariantMap &configuration=QVariantMap()) const SIP_THROW(QgsProcessingException)
Creates a copy of the algorithm, ready for execution.
Definition: qgsprocessingalgorithm.cpp:42
QgsProcessingAlgorithm::preprocessParameters
virtual QVariantMap preprocessParameters(const QVariantMap &parameters)
Pre-processes a set of parameters, allowing the algorithm to clean their values.
Definition: qgsprocessingalgorithm.cpp:125
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsProcessingAlgorithm::postProcessAlgorithm
virtual QVariantMap postProcessAlgorithm(QgsProcessingContext &context, QgsProcessingFeedback *feedback) SIP_THROW(QgsProcessingException)
Allows the algorithm to perform any required cleanup tasks.
Definition: qgsprocessingalgorithm.cpp:456
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:928
QgsProcessingAlgorithm::VectorProperties::wkbType
QgsWkbTypes::Type wkbType
Geometry (WKB) type.
Definition: qgsprocessingalgorithm.h:342
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:940
QgsWkbTypes::Polygon
@ Polygon
Definition: qgswkbtypes.h:74
QgsAnnotationLayer
Represents a map layer containing a set of georeferenced annotations, e.g. markers,...
Definition: qgsannotationlayer.h:46
QgsProcessingContext::expressionContext
QgsExpressionContext & expressionContext()
Returns the expression context.
Definition: qgsprocessingcontext.h:149
QgsProcessingFeatureSource
QgsFeatureSource subclass which proxies methods to an underlying QgsFeatureSource,...
Definition: qgsprocessingutils.h:577
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:726
QgsProcessingAlgorithm::FlagRequiresMatchingCrs
@ FlagRequiresMatchingCrs
Algorithm requires that all input layers have matching coordinate reference systems.
Definition: qgsprocessingalgorithm.h:75
QgsProcessingParameters::parameterAsEnumString
static QString parameterAsEnumString(const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, const QgsProcessingContext &context)
Evaluates the parameter with matching definition to a static enum string.
Definition: qgsprocessingparameters.cpp:516
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:158
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:2053
QgsProcessingAlgorithm::helpString
virtual Q_DECL_DEPRECATED QString helpString() const
Returns a localised help string for the algorithm.
Definition: qgsprocessingalgorithm.cpp:70
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:968
qgsprocessingcontext.h
QgsProcessingAlgorithm::FlagSupportsBatch
@ FlagSupportsBatch
Algorithm supports batch mode.
Definition: qgsprocessingalgorithm.h:73
QgsProcessingAlgorithm::postProcess
QVariantMap postProcess(QgsProcessingContext &context, QgsProcessingFeedback *feedback)
Should be called in the main thread following the completion of runPrepared().
Definition: qgsprocessingalgorithm.cpp:634
QgsProcessingParameterDefinition::isDestination
virtual bool isDestination() const
Returns true if this parameter represents a file or layer destination, e.g.
Definition: qgsprocessingparameters.h:481
QgsProcessingFeatureBasedAlgorithm::sourceCrs
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source's coordinate reference system.
Definition: qgsprocessingalgorithm.cpp:1074
qgsexception.h
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsProperty::staticValue
QVariant staticValue() const
Returns the current static value for the property.
Definition: qgsproperty.cpp:341
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:997
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Definition: qgsapplication.cpp:693
QgsProcessingAlgorithm::parameterAsDateTime
QDateTime parameterAsDateTime(const QVariantMap &parameters, const QString &name, QgsProcessingContext &context) const
Evaluates the parameter with matching name to a DateTime, or returns an invalid date time if the para...
Definition: qgsprocessingalgorithm.cpp:861
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:155
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:655
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:2079
QgsProcessingOutputLayerDefinition::sink
QgsProperty sink
Sink/layer definition.
Definition: qgsprocessingparameters.h:229
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:90
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:718
QgsProcessingAlgorithm::provider
QgsProcessingProvider * provider() const
Returns the provider to which this algorithm belongs.
Definition: qgsprocessingalgorithm.cpp:130
QgsProperty::StaticProperty
@ StaticProperty
Static property (QgsStaticProperty)
Definition: qgsproperty.h:238
QgsProcessingAlgorithm::writeFeatureError
static QString writeFeatureError(QgsFeatureSink *sink, const QVariantMap &parameters, const QString &name)
Returns a user-friendly string to use as an error when a feature cannot be written into a sink.
Definition: qgsprocessingalgorithm.cpp:967
QgsProcessingOutputDefinition::name
QString name() const
Returns the name of the output.
Definition: qgsprocessingoutputs.h:94
QgsFeatureIterator
Wrapper for iterator of features from vector data provider or vector layer.
Definition: qgsfeatureiterator.h:289
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:678
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:720
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:425
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:693
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:816
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) const
Evaluates the parameter with matching name to a source vector layer file path and layer name of compa...
Definition: qgsprocessingalgorithm.cpp:736
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:751
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:274
QgsProcessingException
Custom exception class for processing related exceptions.
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:1035
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:771
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:668
QgsFeatureSink
An interface for objects which accept features via addFeature(s) methods.
Definition: qgsfeaturesink.h:33
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:183
QgsProcessingFeatureBasedAlgorithm::request
virtual QgsFeatureRequest request() const
Returns the feature request used for fetching features to process from the source layer.
Definition: qgsprocessingalgorithm.cpp:1134
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:210
QgsProcessingAlgorithm::FlagSupportsInPlaceEdits
@ FlagSupportsInPlaceEdits
Algorithm supports in-place editing.
Definition: qgsprocessingalgorithm.h:78
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:744
QgsProcessingParameterMapLayer::typeName
static QString typeName()
Returns the type name for the parameter class.
Definition: qgsprocessingparameters.h:2915
QgsProcessingAlgorithm::parameterDefinition
const QgsProcessingParameterDefinition * parameterDefinition(const QString &name) const
Returns a matching parameter by name.
Definition: qgsprocessingalgorithm.cpp:461
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:525
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:607
QgsProcessingAlgorithm::VectorProperties::availability
QgsProcessingAlgorithm::PropertyAvailability availability
Availability of the properties. By default properties are not available.
Definition: qgsprocessingalgorithm.h:348
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:123