37
37
#include < QMouseEvent>
38
38
#include < QCursor>
39
39
#include < QPixmap>
40
- #include " qgslogger.h"
41
40
42
41
QgsMapToolIdentify::QgsMapToolIdentify ( QgsMapCanvas* canvas )
43
42
: QgsMapTool( canvas ),
@@ -237,19 +236,7 @@ void QgsMapToolIdentify::identifyVectorLayer( const QgsPoint& point )
237
236
double identifyValue = settings.value ( " /Map/identifyRadius" , QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble ();
238
237
QString ellipsoid = settings.value ( " /qgis/measure/ellipsoid" , " WGS84" ).toString ();
239
238
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
-
251
239
int featureCount = 0 ;
252
- // QgsFeature feat;
253
240
QgsAttributeAction& actions = *layer->actions ();
254
241
QString fieldIndex = layer->displayField ();
255
242
const QgsFieldMap& fields = layer->pendingFields ();
@@ -263,10 +250,33 @@ void QgsMapToolIdentify::identifyVectorLayer( const QgsPoint& point )
263
250
mFeatureList .clear ();
264
251
QApplication::setOverrideCursor ( Qt::WaitCursor );
265
252
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
+ }
270
280
271
281
QApplication::restoreOverrideCursor ();
272
282
0 commit comments