Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Log message if selection cannot be determined even after geometry repair
  • Loading branch information
nyalldawson committed Oct 21, 2020
1 parent 9d2ecb5 commit f1fcd39
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/app/qgsmaptoolselectutils.cpp
Expand Up @@ -30,6 +30,7 @@ email : jpalmer at linz dot govt dot nz
#include "qgis.h"
#include "qgsproject.h"
#include "qgsexpressioncontextutils.h"
#include "qgsmessagelog.h"

#include <QMouseEvent>
#include <QApplication>
Expand Down Expand Up @@ -277,21 +278,35 @@ QgsFeatureIds QgsMapToolSelectUtils::getMatchingFeatures( QgsMapCanvas *canvas,
// 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 ( !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 */
)
const bool notContained = !selectionGeometryEngine->contains( g.constGet(), &errorMessage ) &&
( errorMessage.isEmpty() || /* message will be non empty if geometry g is invalid */
!selectionGeometryEngine->contains( g.makeValid().constGet(), &errorMessage ) ); /* second chance for invalid geometries, repair and re-test */

if ( !errorMessage.isEmpty() )
{
// contains relation test still failed, even after trying to make valid!
QgsMessageLog::logMessage( QObject::tr( "Error determining selection: %1" ).arg( errorMessage ), QString(), Qgis::Warning );
}

if ( notContained )
continue;
}
else
{
// 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 ( !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 */
)
const bool notIntersects = !selectionGeometryEngine->intersects( g.constGet(), &errorMessage ) &&
( errorMessage.isEmpty() || /* message will be non empty if geometry g is invalid */
!selectionGeometryEngine->intersects( g.makeValid().constGet(), &errorMessage ) ); /* second chance for invalid geometries, repair and re-test */

if ( !errorMessage.isEmpty() )
{
// intersects relation test still failed, even after trying to make valid!
QgsMessageLog::logMessage( QObject::tr( "Error determining selection: %1" ).arg( errorMessage ), QString(), Qgis::Warning );
}

if ( notIntersects )
continue;
}
if ( singleSelect )
Expand Down

0 comments on commit f1fcd39

Please sign in to comment.