Skip to content
Permalink
Browse files

Tweak processing API to better handle dynamic properties

  • Loading branch information
nyalldawson committed Nov 26, 2017
1 parent 58ab507 commit 86958937ad87be9519b2b68a590c0a4152d1a44b
@@ -872,7 +872,7 @@ class QgsProcessingFeatureBasedAlgorithm : QgsProcessingAlgorithm
:rtype: QgsCoordinateReferenceSystem
%End

virtual QgsFeature processFeature( const QgsFeature &feature, QgsProcessingFeedback *feedback ) = 0;
virtual QgsFeature processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) = 0;
%Docstring
Processes an individual input ``feature`` from the source. Algorithms should implement their
logic in this method for performing the algorithm's operation (e.g. replacing the feature's
@@ -699,6 +699,13 @@ QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariant
if ( !sink )
return QVariantMap();

// prepare expression context for feature iteration
QgsExpressionContext prevContext = context.expressionContext();
QgsExpressionContext algContext = prevContext;

algContext.appendScopes( createExpressionContext( parameters, context, dynamic_cast< QgsProcessingFeatureSource * >( mSource.get() ) ).takeScopes() );
context.setExpressionContext( algContext );

long count = mSource->featureCount();

QgsFeature f;
@@ -713,7 +720,8 @@ QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariant
break;
}

QgsFeature transformed = processFeature( f, feedback );
context.expressionContext().setFeature( f );
QgsFeature transformed = processFeature( f, context, feedback );
if ( transformed.isValid() )
sink->addFeature( transformed, QgsFeatureSink::FastInsert );

@@ -723,6 +731,9 @@ QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariant

mSource.reset();

// probably not necessary - context's aren't usually recycled, but can't hurt
context.setExpressionContext( prevContext );

QVariantMap outputs;
outputs.insert( QStringLiteral( "OUTPUT" ), dest );
return outputs;
@@ -874,7 +874,7 @@ class CORE_EXPORT QgsProcessingFeatureBasedAlgorithm : public QgsProcessingAlgor
* can break valid model execution - so use with extreme caution, and consider using
* \a feedback to instead report non-fatal processing failures for features instead.
*/
virtual QgsFeature processFeature( const QgsFeature &feature, QgsProcessingFeedback *feedback ) = 0;
virtual QgsFeature processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) = 0;

virtual QVariantMap processAlgorithm( const QVariantMap &parameters,
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;

0 comments on commit 8695893

Please sign in to comment.
You can’t perform that action at this time.