Skip to content
Permalink
Browse files
Allow specifying a callback for encountering invalid geometries while…
… iterating
  • Loading branch information
nyalldawson committed Apr 25, 2017
1 parent 80d07cb commit 595f104830877c494c8ff28e2f1b9fe500ef7123
Showing with 31 additions and 1 deletion.
  1. +6 −0 src/core/qgsfeaturerequest.cpp
  2. +20 −0 src/core/qgsfeaturerequest.h
  3. +5 −1 src/core/qgsvectorlayerfeatureiterator.cpp
@@ -111,6 +111,12 @@ QgsFeatureRequest &QgsFeatureRequest::setInvalidGeometryCheck( QgsFeatureRequest
return *this;
}

QgsFeatureRequest &QgsFeatureRequest::setInvalidGeometryCallback( std::function<void ( const QgsFeature & )> callback )
{
mInvalidGeometryCallback = callback;
return *this;
}

QgsFeatureRequest &QgsFeatureRequest::setFilterExpression( const QString &expression )
{
mFilter = FilterExpression;
@@ -294,6 +294,25 @@ class CORE_EXPORT QgsFeatureRequest
*/
InvalidGeometryCheck invalidGeometryCheck() const { return mInvalidGeometryFilter; }

/**
* Sets a callback function to use when encountering an invalid geometry and
* invalidGeometryCheck() is set to GeometryAbortOnInvalid. This function will be
* called using the feature with invalid geometry as a parameter.
* \since QGIS 3.0
* \note not available in Python bindings
* \see invalidGeometryCallback()
*/
QgsFeatureRequest &setInvalidGeometryCallback( std::function< void( const QgsFeature & ) > callback );

/**
* Returns the callback function to use when encountering an invalid geometry and
* invalidGeometryCheck() is set to GeometryAbortOnInvalid.
* \since QGIS 3.0
* \note not available in Python bindings
* \see setInvalidGeometryCallback()
*/
std::function< void( const QgsFeature & ) > invalidGeometryCallback() const { return mInvalidGeometryCallback; }

/** Set the filter expression. {\see QgsExpression}
* \param expression expression string
* \see filterExpression
@@ -440,6 +459,7 @@ class CORE_EXPORT QgsFeatureRequest
long mLimit = -1;
OrderBy mOrderBy;
InvalidGeometryCheck mInvalidGeometryFilter = GeometryNoCheck;
std::function< void( const QgsFeature & ) > mInvalidGeometryCallback;
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureRequest::Flags )
@@ -698,8 +698,12 @@ bool QgsVectorLayerFeatureIterator::checkGeometry( const QgsFeature &feature )
case QgsFeatureRequest::GeometryAbortOnInvalid:
if ( !feature.geometry().isGeosValid() )
{
QgsMessageLog::logMessage( QObject::tr( "Geometry error: One or more input features have invalid geometry." ), QString(), QgsMessageLog::CRITICAL);
QgsMessageLog::logMessage( QObject::tr( "Geometry error: One or more input features have invalid geometry." ), QString(), QgsMessageLog::CRITICAL );
close();
if ( mRequest.invalidGeometryCallback() )
{
mRequest.invalidGeometryCallback()( feature );
}
return false;
}
break;

0 comments on commit 595f104

Please sign in to comment.