Skip to content

Commit

Permalink
Add method to retrieve all features from a QgsProcessingFeatureSource
Browse files Browse the repository at this point in the history
...even when invalid geometries are present and option is set to
skip invalid or break on invalid.

Some algorithms (e.g. those which repair geometries) need a way
to retrieve all features with invalid geometries, regardless of
the user's settings.
  • Loading branch information
nyalldawson committed Jun 26, 2017
1 parent 3fb1b48 commit ec7477c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/processing/qgsprocessingutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,22 @@ QgsProcessingFeatureSource::~QgsProcessingFeatureSource()
delete mSource;
}

QgsFeatureIterator QgsProcessingFeatureSource::getFeatures( const QgsFeatureRequest &request, Flags flags ) const
{
QgsFeatureRequest req( request );
req.setTransformErrorCallback( mTransformErrorCallback );

if ( flags & FlagSkipGeometryValidityChecks )
req.setInvalidGeometryCheck( QgsFeatureRequest::GeometryNoCheck );
else
{
req.setInvalidGeometryCheck( mInvalidGeometryCheck );
req.setInvalidGeometryCallback( mInvalidGeometryCallback );
}

return mSource->getFeatures( req );
}

QgsFeatureIterator QgsProcessingFeatureSource::getFeatures( const QgsFeatureRequest &request ) const
{
QgsFeatureRequest req( request );
Expand Down
14 changes: 14 additions & 0 deletions src/core/processing/qgsprocessingutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ class CORE_EXPORT QgsProcessingFeatureSource : public QgsFeatureSource
{
public:

//! Flags controlling how QgsProcessingFeatureSource fetches features
enum Flag
{
FlagSkipGeometryValidityChecks = 1 << 1, //!< Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always require invalid geometries, regardless of any user settings (e.g. "repair geometry" type algorithms).
};
Q_DECLARE_FLAGS( Flags, Flag )

/**
* Constructor for QgsProcessingFeatureSource, accepting an original feature source \a originalSource
* and processing \a context.
Expand All @@ -241,6 +248,13 @@ class CORE_EXPORT QgsProcessingFeatureSource : public QgsFeatureSource

~QgsProcessingFeatureSource();

/**
* Returns an iterator for the features in the source, respecting the supplied feature \a flags.
* An optional \a request can be used to optimise the returned
* iterator, eg by restricting the returned attributes or geometry.
*/
QgsFeatureIterator getFeatures( const QgsFeatureRequest &request, Flags flags ) const;

QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const override;
QgsCoordinateReferenceSystem sourceCrs() const override;
QgsFields fields() const override;
Expand Down

0 comments on commit ec7477c

Please sign in to comment.