Skip to content

Commit

Permalink
Also call invalidGeometryCallback when skipping features
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 23, 2017
1 parent a8cdde5 commit 5ea0768
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsfeaturerequest.sip
Expand Up @@ -364,7 +364,7 @@ Get feature IDs that should be fetched.
QgsFeatureRequest &setInvalidGeometryCallback( SIP_PYCALLABLE / AllowNone / );
%Docstring
Sets a callback function to use when encountering an invalid geometry and
invalidGeometryCheck() is set to GeometryAbortOnInvalid. This function will be
invalidGeometryCheck() is set to GeometryAbortOnInvalid or GeometrySkipInvalid. This function will be
called using the feature with invalid geometry as a parameter.
.. versionadded:: 3.0
.. seealso:: invalidGeometryCallback()
Expand Down
8 changes: 8 additions & 0 deletions python/plugins/processing/tools/dataobjects.py
Expand Up @@ -77,6 +77,14 @@ def createContext(feedback=None):
invalid_features_method = QgsFeatureRequest.GeometryAbortOnInvalid
context.setInvalidGeometryCheck(invalid_features_method)

def raise_invalid_geometry_error(f, feedback=feedback):
if feedback:
feedback.pushInfo(QCoreApplication.translate("FeatureIterator",
'Feature with id {} has invalid geometry, skipping feature.'.format(f.id())))

if context.invalidGeometryCheck() == QgsFeatureRequest.GeometrySkipInvalid:
context.setInvalidGeometryCallback(raise_invalid_geometry_error)

def raise_transform_error(f, feedback=feedback):
if feedback:
feedback.pushInfo(QCoreApplication.translate("FeatureIterator",
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsfeaturerequest.h
Expand Up @@ -346,7 +346,7 @@ class CORE_EXPORT QgsFeatureRequest

/**
* Sets a callback function to use when encountering an invalid geometry and
* invalidGeometryCheck() is set to GeometryAbortOnInvalid. This function will be
* invalidGeometryCheck() is set to GeometryAbortOnInvalid or GeometrySkipInvalid. This function will be
* called using the feature with invalid geometry as a parameter.
* \since QGIS 3.0
* \see invalidGeometryCallback()
Expand All @@ -373,7 +373,7 @@ class CORE_EXPORT QgsFeatureRequest

/**
* Returns the callback function to use when encountering an invalid geometry and
* invalidGeometryCheck() is set to GeometryAbortOnInvalid.
* invalidGeometryCheck() is set to GeometryAbortOnInvalid or GeometrySkipInvalid.
* \since QGIS 3.0
* \note not available in Python bindings
* \see setInvalidGeometryCallback()
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsvectorlayerfeatureiterator.cpp
Expand Up @@ -746,6 +746,10 @@ bool QgsVectorLayerFeatureIterator::checkGeometryValidity( const QgsFeature &fea
if ( !feature.geometry().isGeosValid() )
{
QgsMessageLog::logMessage( QObject::tr( "Geometry error: One or more input features have invalid geometry." ), QString(), QgsMessageLog::CRITICAL );
if ( mRequest.invalidGeometryCallback() )
{
mRequest.invalidGeometryCallback()( feature );
}
return false;
}
break;
Expand Down

0 comments on commit 5ea0768

Please sign in to comment.