[QGIS Commit] r9320 - trunk/qgis/src/app

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Sep 13 14:30:20 EDT 2008


Author: telwertowski
Date: 2008-09-13 14:30:20 -0400 (Sat, 13 Sep 2008)
New Revision: 9320

Modified:
   trunk/qgis/src/app/qgsmaptoolidentify.cpp
   trunk/qgis/src/app/qgsmaptoolselect.cpp
Log:
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.


Modified: trunk/qgis/src/app/qgsmaptoolidentify.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoolidentify.cpp	2008-09-13 17:42:22 UTC (rev 9319)
+++ trunk/qgis/src/app/qgsmaptoolidentify.cpp	2008-09-13 18:30:20 UTC (rev 9320)
@@ -37,7 +37,6 @@
 #include <QMouseEvent>
 #include <QCursor>
 #include <QPixmap>
-#include "qgslogger.h"
 
 QgsMapToolIdentify::QgsMapToolIdentify( QgsMapCanvas* canvas )
     : QgsMapTool( canvas ),
@@ -237,19 +236,7 @@
   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();
@@ -263,11 +250,34 @@
   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();
 
   if ( layer->isEditable() && mFeatureList.size() == 1 )

Modified: trunk/qgis/src/app/qgsmaptoolselect.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoolselect.cpp	2008-09-13 17:42:22 UTC (rev 9319)
+++ trunk/qgis/src/app/qgsmaptoolselect.cpp	2008-09-13 18:30:20 UTC (rev 9320)
@@ -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>
@@ -92,7 +94,22 @@
   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 );



More information about the QGIS-commit mailing list