Move invalid geometry callback from Python to c++

This commit is contained in:
Nyall Dawson 2017-06-23 10:12:35 +10:00
parent 98617c90bd
commit 57f2c623ce
4 changed files with 18 additions and 16 deletions

View File

@ -137,6 +137,8 @@ Destination project
void setInvalidGeometryCheck( const QgsFeatureRequest::InvalidGeometryCheck &check );
%Docstring
Sets the behavior used for checking invalid geometries in input layers.
Settings this to anything but QgsFeatureRequest.GeometryNoCheck will also
reset the invalidGeometryCallback() to a default implementation.
.. seealso:: invalidGeometryCheck()
%End

View File

@ -77,12 +77,6 @@ def createContext():
invalid_features_method = QgsFeatureRequest.GeometryAbortOnInvalid
context.setInvalidGeometryCheck(invalid_features_method)
def raise_error(f):
raise GeoAlgorithmExecutionException(QCoreApplication.translate("FeatureIterator",
'Features with invalid geometries found. Please fix these geometries or specify the "Ignore invalid input features" flag'))
context.setInvalidGeometryCallback(raise_error)
def raise_transform_error(f):
raise GeoAlgorithmExecutionException(QCoreApplication.translate("FeatureIterator",
'Encountered a transform error when reprojecting feature with id {}.'.format(f.id())))

View File

@ -24,6 +24,7 @@
#include "qgsexpressioncontext.h"
#include "qgsfeaturerequest.h"
#include "qgsmaplayerlistutils.h"
#include "qgsprocessingexception.h"
/**
* \class QgsProcessingContext
@ -167,9 +168,23 @@ class CORE_EXPORT QgsProcessingContext
/**
* Sets the behavior used for checking invalid geometries in input layers.
* Settings this to anything but QgsFeatureRequest::GeometryNoCheck will also
* reset the invalidGeometryCallback() to a default implementation.
* \see invalidGeometryCheck()
*/
void setInvalidGeometryCheck( const QgsFeatureRequest::InvalidGeometryCheck &check ) { mInvalidGeometryCheck = check; }
void setInvalidGeometryCheck( const QgsFeatureRequest::InvalidGeometryCheck &check )
{
mInvalidGeometryCheck = check;
if ( mInvalidGeometryCheck == QgsFeatureRequest::GeometryAbortOnInvalid )
{
auto callback = []( const QgsFeature & feature )
{
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() ) );
};
mInvalidGeometryCallback = callback;
}
}
/**

View File

@ -475,12 +475,3 @@ long QgsProcessingFeatureSource::featureCount() const
{
return mSource->featureCount();
}