Skip to content

Commit 5facf32

Browse files
author
telwertowski
committedSep 13, 2008
Catch CRS exception for invalid point and handle as if nothing was selected 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
1 parent b254446 commit 5facf32

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed
 

‎src/app/qgsmaptoolidentify.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include <QMouseEvent>
3838
#include <QCursor>
3939
#include <QPixmap>
40-
#include "qgslogger.h"
4140

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

240-
// create the search rectangle
241-
double searchRadius = mCanvas->extent().width() * ( identifyValue / 100.0 );
242-
243-
QgsRect r;
244-
r.setXMinimum( point.x() - searchRadius );
245-
r.setXMaximum( point.x() + searchRadius );
246-
r.setYMinimum( point.y() - searchRadius );
247-
r.setYMaximum( point.y() + searchRadius );
248-
249-
r = toLayerCoordinates( layer, r );
250-
251239
int featureCount = 0;
252-
//QgsFeature feat;
253240
QgsAttributeAction& actions = *layer->actions();
254241
QString fieldIndex = layer->displayField();
255242
const QgsFieldMap& fields = layer->pendingFields();
@@ -263,10 +250,33 @@ void QgsMapToolIdentify::identifyVectorLayer( const QgsPoint& point )
263250
mFeatureList.clear();
264251
QApplication::setOverrideCursor( Qt::WaitCursor );
265252

266-
layer->select( layer->pendingAllAttributesList(), r, true, true );
267-
QgsFeature f;
268-
while ( layer->getNextFeature( f ) )
269-
mFeatureList << QgsFeature( f );
253+
// toLayerCoordinates will throw an exception for an 'invalid' point.
254+
// For example, if you project a world map onto a globe using EPSG 2163
255+
// and then click somewhere off the globe, an exception will be thrown.
256+
try
257+
{
258+
// create the search rectangle
259+
double searchRadius = mCanvas->extent().width() * ( identifyValue / 100.0 );
260+
261+
QgsRect r;
262+
r.setXMinimum( point.x() - searchRadius );
263+
r.setXMaximum( point.x() + searchRadius );
264+
r.setYMinimum( point.y() - searchRadius );
265+
r.setYMaximum( point.y() + searchRadius );
266+
267+
r = toLayerCoordinates( layer, r );
268+
269+
layer->select( layer->pendingAllAttributesList(), r, true, true );
270+
QgsFeature f;
271+
while ( layer->getNextFeature( f ) )
272+
mFeatureList << QgsFeature( f );
273+
}
274+
catch ( QgsCsException & cse )
275+
{
276+
Q_UNUSED( cse );
277+
// catch exception for 'invalid' point and proceed with no features found
278+
QgsLogger::warning( "Caught CRS exception " + QString( __FILE__ ) + ": " + QString::number( __LINE__ ) );
279+
}
270280

271281
QApplication::restoreOverrideCursor();
272282

‎src/app/qgsmaptoolselect.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
#include "qgsmapcanvas.h"
1919
#include "qgsmaptopixel.h"
2020
#include "qgsvectorlayer.h"
21+
#include "qgscsexception.h"
2122
#include "qgscursors.h"
23+
#include "qgslogger.h"
2224

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

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

97114
QApplication::setOverrideCursor( Qt::WaitCursor );
98115
vlayer->select( search, lock );

0 commit comments

Comments
 (0)
Please sign in to comment.