Skip to content

Commit

Permalink
Move invalid geometry callback from Python to c++
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 23, 2017
1 parent 98617c9 commit 57f2c62
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 2 additions & 0 deletions python/core/processing/qgsprocessingcontext.sip
Expand Up @@ -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

Expand Down
6 changes: 0 additions & 6 deletions python/plugins/processing/tools/dataobjects.py
Expand Up @@ -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())))
Expand Down
17 changes: 16 additions & 1 deletion src/core/processing/qgsprocessingcontext.h
Expand Up @@ -24,6 +24,7 @@
#include "qgsexpressioncontext.h"
#include "qgsfeaturerequest.h"
#include "qgsmaplayerlistutils.h"
#include "qgsprocessingexception.h"

/**
* \class QgsProcessingContext
Expand Down Expand Up @@ -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;
}
}


/**
Expand Down
9 changes: 0 additions & 9 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -475,12 +475,3 @@ long QgsProcessingFeatureSource::featureCount() const
{
return mSource->featureCount();
}









0 comments on commit 57f2c62

Please sign in to comment.