Skip to content

Commit 11cfc78

Browse files
committed
Skip invalid returned features
1 parent 29855b3 commit 11cfc78

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

python/core/processing/qgsprocessingalgorithm.sip

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,10 @@ class QgsProcessingFeatureBasedAlgorithm : QgsProcessingAlgorithm
827827
geometry with the centroid of the original feature geometry for a 'centroid' type
828828
algorithm).
829829

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

832835
The provided ``feedback`` object can be used to push messages to the log and for giving feedback
833836
to users. Note that handling of progress reports and algorithm cancelation is handled by

src/core/processing/qgsprocessingalgorithm.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,8 @@ QVariantMap QgsProcessingFeatureBasedAlgorithm::processAlgorithm( const QVariant
656656
}
657657

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

661662
feedback->setProgress( current * step );
662663
current++;

src/core/processing/qgsprocessingalgorithm.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,10 @@ class CORE_EXPORT QgsProcessingFeatureBasedAlgorithm : public QgsProcessingAlgor
798798
* geometry with the centroid of the original feature geometry for a 'centroid' type
799799
* algorithm).
800800
*
801-
* Implementations should return the modified feature.
801+
* Implementations should return the modified feature. Returning an invalid feature (e.g.
802+
* a default constructed QgsFeature) will indicate that this feature should be 'skipped',
803+
* and will not be added to the algorithm's output. Subclasses can use this approach to
804+
* filter the incoming features as desired.
802805
*
803806
* The provided \a feedback object can be used to push messages to the log and for giving feedback
804807
* to users. Note that handling of progress reports and algorithm cancelation is handled by

0 commit comments

Comments
 (0)