Skip to content

Commit

Permalink
Check validity of coverages before running coverage tools, unless
Browse files Browse the repository at this point in the history
geometry validation is disabled
  • Loading branch information
nyalldawson committed Oct 17, 2023
1 parent ed0766e commit a4d0ca6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
11 changes: 11 additions & 0 deletions python/core/auto_generated/processing/qgsprocessingutils.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

};
Expand Down
20 changes: 18 additions & 2 deletions src/analysis/processing/qgsalgorithmcoveragesimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
17 changes: 17 additions & 0 deletions src/analysis/processing/qgsalgorithmcoverageunion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ QVariantMap QgsCoverageUnionAlgorithm::processAlgorithm( const QVariantMap &para

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 )
Expand Down
5 changes: 5 additions & 0 deletions src/core/processing/qgsprocessingutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,11 @@ void QgsProcessingFeatureSource::setInvalidGeometryCheck( QgsFeatureRequest::Inv
}
}

QgsFeatureRequest::InvalidGeometryCheck QgsProcessingFeatureSource::invalidGeometryCheck() const
{
return mInvalidGeometryCheck;
}


//
// QgsProcessingFeatureSink
Expand Down
9 changes: 9 additions & 0 deletions src/core/processing/qgsprocessingutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a4d0ca6

Please sign in to comment.