Skip to content

Commit 57f2c62

Browse files
committed
Move invalid geometry callback from Python to c++
1 parent 98617c9 commit 57f2c62

4 files changed

Lines changed: 18 additions & 16 deletions

File tree

‎python/core/processing/qgsprocessingcontext.sip‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ Destination project
137137
void setInvalidGeometryCheck( const QgsFeatureRequest::InvalidGeometryCheck &check );
138138
%Docstring
139139
Sets the behavior used for checking invalid geometries in input layers.
140+
Settings this to anything but QgsFeatureRequest.GeometryNoCheck will also
141+
reset the invalidGeometryCallback() to a default implementation.
140142
.. seealso:: invalidGeometryCheck()
141143
%End
142144

‎python/plugins/processing/tools/dataobjects.py‎

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

80-
def raise_error(f):
81-
raise GeoAlgorithmExecutionException(QCoreApplication.translate("FeatureIterator",
82-
'Features with invalid geometries found. Please fix these geometries or specify the "Ignore invalid input features" flag'))
83-
84-
context.setInvalidGeometryCallback(raise_error)
85-
8680
def raise_transform_error(f):
8781
raise GeoAlgorithmExecutionException(QCoreApplication.translate("FeatureIterator",
8882
'Encountered a transform error when reprojecting feature with id {}.'.format(f.id())))

‎src/core/processing/qgsprocessingcontext.h‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "qgsexpressioncontext.h"
2525
#include "qgsfeaturerequest.h"
2626
#include "qgsmaplayerlistutils.h"
27+
#include "qgsprocessingexception.h"
2728

2829
/**
2930
* \class QgsProcessingContext
@@ -167,9 +168,23 @@ class CORE_EXPORT QgsProcessingContext
167168

168169
/**
169170
* Sets the behavior used for checking invalid geometries in input layers.
171+
* Settings this to anything but QgsFeatureRequest::GeometryNoCheck will also
172+
* reset the invalidGeometryCallback() to a default implementation.
170173
* \see invalidGeometryCheck()
171174
*/
172-
void setInvalidGeometryCheck( const QgsFeatureRequest::InvalidGeometryCheck &check ) { mInvalidGeometryCheck = check; }
175+
void setInvalidGeometryCheck( const QgsFeatureRequest::InvalidGeometryCheck &check )
176+
{
177+
mInvalidGeometryCheck = check;
178+
179+
if ( mInvalidGeometryCheck == QgsFeatureRequest::GeometryAbortOnInvalid )
180+
{
181+
auto callback = []( const QgsFeature & feature )
182+
{
183+
throw QgsProcessingException( QObject::tr( "Feature (%1) has invalid geometry. Please fix the geometry or change the Processing setting to the \"Ignore invalid input features\" option." ).arg( feature.id() ) );
184+
};
185+
mInvalidGeometryCallback = callback;
186+
}
187+
}
173188

174189

175190
/**

‎src/core/processing/qgsprocessingutils.cpp‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,3 @@ long QgsProcessingFeatureSource::featureCount() const
475475
{
476476
return mSource->featureCount();
477477
}
478-
479-
480-
481-
482-
483-
484-
485-
486-

0 commit comments

Comments
 (0)