Skip to content
Permalink
Browse files

Move invalid geometry callback from Python to c++

  • Loading branch information
nyalldawson committed Jun 23, 2017
1 parent 98617c9 commit 57f2c623ce5abf8d1749378a407cd40396241014
@@ -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

@@ -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())))
@@ -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;
}
}


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









0 comments on commit 57f2c62

Please sign in to comment.
You can’t perform that action at this time.