diff --git a/python/core/auto_generated/processing/qgsprocessingutils.sip.in b/python/core/auto_generated/processing/qgsprocessingutils.sip.in index 4a52163d2597..63070e628422 100644 --- a/python/core/auto_generated/processing/qgsprocessingutils.sip.in +++ b/python/core/auto_generated/processing/qgsprocessingutils.sip.in @@ -711,7 +711,18 @@ Returns an expression context scope suitable for this source. %Docstring Overrides the default geometry check method for the source. +.. seealso:: :py:func:`invalidGeometryCheck` + .. versionadded:: 3.14 +%End + + QgsFeatureRequest::InvalidGeometryCheck invalidGeometryCheck() const; +%Docstring +Returns the geometry check method for the source. + +.. seealso:: :py:func:`setInvalidGeometryCheck` + +.. versionadded:: 3.36 %End }; diff --git a/src/analysis/processing/qgsalgorithmcoveragesimplify.cpp b/src/analysis/processing/qgsalgorithmcoveragesimplify.cpp index 5a827a5f3134..95d8a19b1be4 100644 --- a/src/analysis/processing/qgsalgorithmcoveragesimplify.cpp +++ b/src/analysis/processing/qgsalgorithmcoveragesimplify.cpp @@ -123,10 +123,26 @@ QVariantMap QgsCoverageSimplifyAlgorithm::processAlgorithm( const QVariantMap &p current++; } + QString error; + QgsGeos geos( &collection ); + switch ( source->invalidGeometryCheck() ) + { + case QgsFeatureRequest::GeometryNoCheck: + break; + + case QgsFeatureRequest::GeometrySkipInvalid: + case QgsFeatureRequest::GeometryAbortOnInvalid: + { + if ( geos.validateCoverage( 0, nullptr, &error ) != Qgis::CoverageValidityResult::Valid ) + { + throw QgsProcessingException( QObject::tr( "Coverage is not valid" ) ); + } + break; + } + } + feedback->pushInfo( QObject::tr( "Simplifying coverage" ) ); - QgsGeos geos( &collection ); - QString error; std::unique_ptr< QgsAbstractGeometry > simplified; try { diff --git a/src/analysis/processing/qgsalgorithmcoverageunion.cpp b/src/analysis/processing/qgsalgorithmcoverageunion.cpp index 4f00112b0268..766814a2dc5a 100644 --- a/src/analysis/processing/qgsalgorithmcoverageunion.cpp +++ b/src/analysis/processing/qgsalgorithmcoverageunion.cpp @@ -113,6 +113,23 @@ QVariantMap QgsCoverageUnionAlgorithm::processAlgorithm( const QVariantMap ¶ QgsGeos geos( &collection ); QString error; + + switch ( source->invalidGeometryCheck() ) + { + case QgsFeatureRequest::GeometryNoCheck: + break; + + case QgsFeatureRequest::GeometrySkipInvalid: + case QgsFeatureRequest::GeometryAbortOnInvalid: + { + if ( geos.validateCoverage( 0, nullptr, &error ) != Qgis::CoverageValidityResult::Valid ) + { + throw QgsProcessingException( QObject::tr( "Coverage is not valid" ) ); + } + break; + } + } + std::unique_ptr< QgsAbstractGeometry > dissolved = geos.unionCoverage( &error ); if ( !dissolved ) diff --git a/src/core/processing/qgsprocessingutils.cpp b/src/core/processing/qgsprocessingutils.cpp index f00301f15f60..65491ba66f04 100644 --- a/src/core/processing/qgsprocessingutils.cpp +++ b/src/core/processing/qgsprocessingutils.cpp @@ -1849,6 +1849,11 @@ void QgsProcessingFeatureSource::setInvalidGeometryCheck( QgsFeatureRequest::Inv } } +QgsFeatureRequest::InvalidGeometryCheck QgsProcessingFeatureSource::invalidGeometryCheck() const +{ + return mInvalidGeometryCheck; +} + // // QgsProcessingFeatureSink diff --git a/src/core/processing/qgsprocessingutils.h b/src/core/processing/qgsprocessingutils.h index 5ef0851ac8c1..3ab450939694 100644 --- a/src/core/processing/qgsprocessingutils.h +++ b/src/core/processing/qgsprocessingutils.h @@ -730,10 +730,19 @@ class CORE_EXPORT QgsProcessingFeatureSource : public QgsFeatureSource /** * Overrides the default geometry check method for the source. * + * \see invalidGeometryCheck() * \since QGIS 3.14 */ void setInvalidGeometryCheck( QgsFeatureRequest::InvalidGeometryCheck method ); + /** + * Returns the geometry check method for the source. + * + * \see setInvalidGeometryCheck() + * \since QGIS 3.36 + */ + QgsFeatureRequest::InvalidGeometryCheck invalidGeometryCheck() const; + private: QgsFeatureSource *mSource = nullptr;