mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-07 00:15:48 -04:00
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
This commit is contained in:
parent
b254446bf8
commit
5facf32f5c
@ -37,7 +37,6 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QCursor>
|
||||
#include <QPixmap>
|
||||
#include "qgslogger.h"
|
||||
|
||||
QgsMapToolIdentify::QgsMapToolIdentify( QgsMapCanvas* canvas )
|
||||
: QgsMapTool( canvas ),
|
||||
@ -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();
|
||||
@ -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();
|
||||
|
||||
|
@ -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 @@ 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 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user