Skip to content

Commit

Permalink
Skip invalid returned features
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 18, 2017
1 parent 29855b3 commit 11cfc78
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion python/core/processing/qgsprocessingalgorithm.sip
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,10 @@ class QgsProcessingFeatureBasedAlgorithm : QgsProcessingAlgorithm
geometry with the centroid of the original feature geometry for a 'centroid' type
algorithm).

Implementations should return the modified feature.
Implementations should return the modified feature. Returning an invalid feature (e.g.
a default constructed QgsFeature) will indicate that this feature should be 'skipped',
and will not be added to the algorithm's output. Subclasses can use this approach to
filter the incoming features as desired.

The provided ``feedback`` object can be used to push messages to the log and for giving feedback
to users. Note that handling of progress reports and algorithm cancelation is handled by
Expand Down
3 changes: 2 additions & 1 deletion src/core/processing/qgsprocessingalgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,8 @@ QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariant
}

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

feedback->setProgress( current * step );
current++;
Expand Down
5 changes: 4 additions & 1 deletion src/core/processing/qgsprocessingalgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,10 @@ class CORE_EXPORT QgsProcessingFeatureBasedAlgorithm : public QgsProcessingAlgor
* geometry with the centroid of the original feature geometry for a 'centroid' type
* algorithm).
*
* Implementations should return the modified feature.
* Implementations should return the modified feature. Returning an invalid feature (e.g.
* a default constructed QgsFeature) will indicate that this feature should be 'skipped',
* and will not be added to the algorithm's output. Subclasses can use this approach to
* filter the incoming features as desired.
*
* The provided \a feedback object can be used to push messages to the log and for giving feedback
* to users. Note that handling of progress reports and algorithm cancelation is handled by
Expand Down

0 comments on commit 11cfc78

Please sign in to comment.