Skip to content

Commit 5ea0768

Browse files
committed
Also call invalidGeometryCallback when skipping features
1 parent a8cdde5 commit 5ea0768

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

python/core/qgsfeaturerequest.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ Get feature IDs that should be fetched.
364364
QgsFeatureRequest &setInvalidGeometryCallback( SIP_PYCALLABLE / AllowNone / );
365365
%Docstring
366366
Sets a callback function to use when encountering an invalid geometry and
367-
invalidGeometryCheck() is set to GeometryAbortOnInvalid. This function will be
367+
invalidGeometryCheck() is set to GeometryAbortOnInvalid or GeometrySkipInvalid. This function will be
368368
called using the feature with invalid geometry as a parameter.
369369
.. versionadded:: 3.0
370370
.. seealso:: invalidGeometryCallback()

python/plugins/processing/tools/dataobjects.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ def createContext(feedback=None):
7777
invalid_features_method = QgsFeatureRequest.GeometryAbortOnInvalid
7878
context.setInvalidGeometryCheck(invalid_features_method)
7979

80+
def raise_invalid_geometry_error(f, feedback=feedback):
81+
if feedback:
82+
feedback.pushInfo(QCoreApplication.translate("FeatureIterator",
83+
'Feature with id {} has invalid geometry, skipping feature.'.format(f.id())))
84+
85+
if context.invalidGeometryCheck() == QgsFeatureRequest.GeometrySkipInvalid:
86+
context.setInvalidGeometryCallback(raise_invalid_geometry_error)
87+
8088
def raise_transform_error(f, feedback=feedback):
8189
if feedback:
8290
feedback.pushInfo(QCoreApplication.translate("FeatureIterator",

src/core/qgsfeaturerequest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class CORE_EXPORT QgsFeatureRequest
346346

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

374374
/**
375375
* Returns the callback function to use when encountering an invalid geometry and
376-
* invalidGeometryCheck() is set to GeometryAbortOnInvalid.
376+
* invalidGeometryCheck() is set to GeometryAbortOnInvalid or GeometrySkipInvalid.
377377
* \since QGIS 3.0
378378
* \note not available in Python bindings
379379
* \see setInvalidGeometryCallback()

src/core/qgsvectorlayerfeatureiterator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,10 @@ bool QgsVectorLayerFeatureIterator::checkGeometryValidity( const QgsFeature &fea
746746
if ( !feature.geometry().isGeosValid() )
747747
{
748748
QgsMessageLog::logMessage( QObject::tr( "Geometry error: One or more input features have invalid geometry." ), QString(), QgsMessageLog::CRITICAL );
749+
if ( mRequest.invalidGeometryCallback() )
750+
{
751+
mRequest.invalidGeometryCallback()( feature );
752+
}
749753
return false;
750754
}
751755
break;

0 commit comments

Comments
 (0)