Skip to content
Permalink
Browse files

Handle geometrycollections also in difference results

  • Loading branch information
mhugent committed Nov 2, 2020
1 parent d6247fd commit b9b6171ef9ba80d757314f1bac08df08c7628fad
Showing with 13 additions and 4 deletions.
  1. +13 −4 src/analysis/processing/qgsoverlayutils.cpp
@@ -54,14 +54,22 @@ bool QgsOverlayUtils::sanitizeIntersectionResult( QgsGeometry &geom, QgsWkbTypes


//! Makes sure that what came out from difference of two geometries is good to be used in the output
static bool sanitizeDifferenceResult( QgsGeometry &geom )
static bool sanitizeDifferenceResult( QgsGeometry &geom, QgsWkbTypes::GeometryType geometryType )
{
if ( geom.isNull() )
{
// TODO: not sure if this ever happens - if it does, that means GEOS failed badly - would be good to have a test for such situation
throw QgsProcessingException( QStringLiteral( "%1\n\n%2" ).arg( QObject::tr( "GEOS geoprocessing error: difference failed." ), geom.lastError() ) );
}

//fix geometry collections
if ( QgsWkbTypes::flatType( geom.wkbType() ) == QgsWkbTypes::GeometryCollection )
{
// try to filter out irrelevant parts with different geometry type than what we want
geom.convertGeometryCollectionToSubclass( geometryType );
}


// if geomB covers the whole source geometry, we get an empty geometry collection
if ( geom.isEmpty() )
return false;
@@ -76,6 +84,7 @@ static bool sanitizeDifferenceResult( QgsGeometry &geom )

void QgsOverlayUtils::difference( const QgsFeatureSource &sourceA, const QgsFeatureSource &sourceB, QgsFeatureSink &sink, QgsProcessingContext &context, QgsProcessingFeedback *feedback, int &count, int totalCount, QgsOverlayUtils::DifferenceOutput outputAttrs )
{
QgsWkbTypes::GeometryType geometryType = QgsWkbTypes::geometryType( QgsWkbTypes::multiType( sourceA.wkbType() ) );
QgsFeatureRequest requestB;
requestB.setNoAttributes();
if ( outputAttrs != OutputBA )
@@ -147,7 +156,7 @@ void QgsOverlayUtils::difference( const QgsFeatureSource &sourceA, const QgsFeat
geom = geom.difference( geomB );
}

if ( !sanitizeDifferenceResult( geom ) )
if ( !sanitizeDifferenceResult( geom, geometryType ) )
continue;

const QgsAttributes attrsA( featA.attributes() );
@@ -369,7 +378,7 @@ void QgsOverlayUtils::resolveOverlaps( const QgsFeatureSource &source, QgsFeatur
index.deleteFeature( f );
geometries.remove( fid1 );

if ( sanitizeDifferenceResult( g12 ) )
if ( sanitizeDifferenceResult( g12, geometryType ) )
{
geometries.insert( fid1, g12 );

@@ -390,7 +399,7 @@ void QgsOverlayUtils::resolveOverlaps( const QgsFeatureSource &source, QgsFeatur

geometries.remove( fid2 );

if ( sanitizeDifferenceResult( g21 ) )
if ( sanitizeDifferenceResult( g21, geometryType ) )
{
geometries.insert( fid2, g21 );

0 comments on commit b9b6171

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