Skip to content

Commit

Permalink
Silence noisy GEOS messages when selecting invalid geometries, fix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 21, 2020
1 parent 7e64d74 commit 929e2b1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/app/qgsmaptoolselectutils.cpp
Expand Up @@ -236,6 +236,9 @@ QgsFeatureIds QgsMapToolSelectUtils::getMatchingFeatures( QgsMapCanvas *canvas,
selectGeomTrans = selectGeomTrans.buffer( 0, 1 );
}

std::unique_ptr< QgsGeometryEngine > selectionGeometryEngine( QgsGeometry::createGeometryEngine( selectGeomTrans.constGet() ) );
selectionGeometryEngine->setLogErrors( false );

QgsRenderContext context = QgsRenderContext::fromMapSettings( canvas->mapSettings() );
context.expressionContext() << QgsExpressionContextUtils::layerScope( vlayer );
std::unique_ptr< QgsFeatureRenderer > r;
Expand Down Expand Up @@ -267,14 +270,15 @@ QgsFeatureIds QgsMapToolSelectUtils::getMatchingFeatures( QgsMapCanvas *canvas,
continue;

QgsGeometry g = f.geometry();
QString errorMessage;
if ( doContains )
{
// if we get an error from the contains check then it indicates that the geometry is invalid and GEOS choked on it.
// in this case we consider the bounding box intersection check which has already been performed by the iterator as sufficient and
// allow the feature to be selected
if ( !selectGeomTrans.contains( g ) &&
!selectGeomTrans.lastError().isEmpty() && /* lastError will be non empty if geometry g is invalid */
!selectGeomTrans.contains( g.makeValid() ) /* second chance for invalid geometries, repair and re-test */
if ( !selectionGeometryEngine->contains( g.constGet(), &errorMessage ) &&
( errorMessage.isEmpty() || /* message will be non empty if geometry g is invalid */
!selectionGeometryEngine->contains( g.makeValid().constGet() ) ) /* second chance for invalid geometries, repair and re-test */
)
continue;
}
Expand All @@ -283,9 +287,9 @@ QgsFeatureIds QgsMapToolSelectUtils::getMatchingFeatures( QgsMapCanvas *canvas,
// if we get an error from the intersects check then it indicates that the geometry is invalid and GEOS choked on it.
// in this case we consider the bounding box intersection check which has already been performed by the iterator as sufficient and
// allow the feature to be selected
if ( !selectGeomTrans.intersects( g ) &&
!selectGeomTrans.lastError().isEmpty() && /* lastError will be non empty if geometry g is invalid */
!selectGeomTrans.intersects( g.makeValid() ) /* second chance for invalid geometries, repair and re-test */
if ( !selectionGeometryEngine->intersects( g.constGet(), &errorMessage ) &&
( errorMessage.isEmpty() || /* message will be non empty if geometry g is invalid */
!selectionGeometryEngine->intersects( g.makeValid().constGet() ) ) /* second chance for invalid geometries, repair and re-test */
)
continue;
}
Expand Down

0 comments on commit 929e2b1

Please sign in to comment.