Skip to content
Permalink
Browse files

Add method to retrieve all features from a QgsProcessingFeatureSource

...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 ec7477cac7fe99fbb3bedb0706a9ea61f391a42e
Showing with 30 additions and 0 deletions.
  1. +16 −0 src/core/processing/qgsprocessingutils.cpp
  2. +14 −0 src/core/processing/qgsprocessingutils.h
@@ -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 );
@@ -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.
@@ -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;

0 comments on commit ec7477c

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