Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Catch CRS exception for invalid point and handle as if nothing was se…
…lected rather than crashing. This can occur if a world map is projected onto a globe and then clicking somewhere off the globe. Fix for ##1159.

git-svn-id: http://svn.osgeo.org/qgis/trunk@9320 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
telwertowski committed Sep 13, 2008
1 parent b254446 commit 5facf32
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
44 changes: 27 additions & 17 deletions src/app/qgsmaptoolidentify.cpp
Expand Up @@ -37,7 +37,6 @@
#include <QMouseEvent>
#include <QCursor>
#include <QPixmap>
#include "qgslogger.h"

QgsMapToolIdentify::QgsMapToolIdentify( QgsMapCanvas* canvas )
: QgsMapTool( canvas ),
Expand Down Expand Up @@ -237,19 +236,7 @@ void QgsMapToolIdentify::identifyVectorLayer( const QgsPoint& point )
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
QString ellipsoid = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();

// create the search rectangle
double searchRadius = mCanvas->extent().width() * ( identifyValue / 100.0 );

QgsRect r;
r.setXMinimum( point.x() - searchRadius );
r.setXMaximum( point.x() + searchRadius );
r.setYMinimum( point.y() - searchRadius );
r.setYMaximum( point.y() + searchRadius );

r = toLayerCoordinates( layer, r );

int featureCount = 0;
//QgsFeature feat;
QgsAttributeAction& actions = *layer->actions();
QString fieldIndex = layer->displayField();
const QgsFieldMap& fields = layer->pendingFields();
Expand All @@ -263,10 +250,33 @@ void QgsMapToolIdentify::identifyVectorLayer( const QgsPoint& point )
mFeatureList.clear();
QApplication::setOverrideCursor( Qt::WaitCursor );

layer->select( layer->pendingAllAttributesList(), r, true, true );
QgsFeature f;
while ( layer->getNextFeature( f ) )
mFeatureList << QgsFeature( f );
// toLayerCoordinates will throw an exception for an 'invalid' point.
// For example, if you project a world map onto a globe using EPSG 2163
// and then click somewhere off the globe, an exception will be thrown.
try
{
// create the search rectangle
double searchRadius = mCanvas->extent().width() * ( identifyValue / 100.0 );

QgsRect r;
r.setXMinimum( point.x() - searchRadius );
r.setXMaximum( point.x() + searchRadius );
r.setYMinimum( point.y() - searchRadius );
r.setYMaximum( point.y() + searchRadius );

r = toLayerCoordinates( layer, r );

layer->select( layer->pendingAllAttributesList(), r, true, true );
QgsFeature f;
while ( layer->getNextFeature( f ) )
mFeatureList << QgsFeature( f );
}
catch ( QgsCsException & cse )
{
Q_UNUSED( cse );
// catch exception for 'invalid' point and proceed with no features found
QgsLogger::warning( "Caught CRS exception " + QString( __FILE__ ) + ": " + QString::number( __LINE__ ) );
}

QApplication::restoreOverrideCursor();

Expand Down
19 changes: 18 additions & 1 deletion src/app/qgsmaptoolselect.cpp
Expand Up @@ -18,7 +18,9 @@
#include "qgsmapcanvas.h"
#include "qgsmaptopixel.h"
#include "qgsvectorlayer.h"
#include "qgscsexception.h"
#include "qgscursors.h"
#include "qgslogger.h"

#include <QApplication>
#include <QMessageBox>
Expand Down Expand Up @@ -92,7 +94,22 @@ void QgsMapToolSelect::canvasReleaseEvent( QMouseEvent * e )
bool lock = ( e->modifiers() & Qt::ControlModifier );

QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( mCanvas->currentLayer() );
search = toLayerCoordinates( vlayer, search );
// toLayerCoordinates will throw an exception for an 'invalid' rectangle.
// For example, if you project a world map onto a globe using EPSG 2163
// and then click somewhere off the globe, an exception will be thrown.
try
{
search = toLayerCoordinates( vlayer, search );
}
catch ( QgsCsException &cse )
{
Q_UNUSED( cse );
// catch exception for 'invalid' rectangle and leave existing selection unchanged
QgsLogger::warning( "Caught CRS exception " + QString( __FILE__ ) + ": " + QString::number( __LINE__ ) );
QMessageBox::warning( mCanvas, QObject::tr( "CRS Exception" ),
QObject::tr( "Selection extends beyond layer's coordinate system." ) );
return;
}

QApplication::setOverrideCursor( Qt::WaitCursor );
vlayer->select( search, lock );
Expand Down

0 comments on commit 5facf32

Please sign in to comment.