Skip to content
Permalink
Browse files

Partial fix for ticket #474 (crash with mixture of projections).

Qgis no longer crashes, but the zoom to layer doesn't quite work all
of the time yet. Note that the toolbar zoom to layer works fine - it's
just the legend one that has problems.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6341 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m
g_j_m committed Dec 29, 2006
1 parent 6b84471 commit c9e5a2cb946f1a55ac6ae938720de1a40b85df88
Showing with 20 additions and 32 deletions.
  1. +4 −2 src/gui/qgsmaplayer.cpp
  2. +16 −30 src/legend/qgslegend.cpp
@@ -631,8 +631,10 @@ bool QgsMapLayer::projectExtent(QgsRect& extent, QgsRect& r2)
catch (QgsCsException &cse)
{
QgsLogger::warning("Transform error caught in " + QString(__FILE__) + ", line " + QString::number(__LINE__));
extent = QgsRect(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
r2 = QgsRect(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
// Return the untransformed extent when the transformation
// fails rather then the largest extent possible!
//extent = QgsRect(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
//r2 = QgsRect(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
}
}
return split;
@@ -1687,59 +1687,45 @@ void QgsLegend::zoomToLayerExtent()
return;
}

double xmin = DBL_MAX;
double ymin = DBL_MAX;
double xmax = -DBL_MAX;
double ymax = -DBL_MAX;

QgsRect transformedExtent;
QgsRect layerExtent;
QgsCoordinateTransform *ct;
QgsRect r2;
QgsMapLayer* theLayer;
bool first(true);

for(std::list<QgsLegendLayerFile*>::iterator it= layerFiles.begin(); it != layerFiles.end(); ++it)
{
theLayer = (*it)->layer();
if(theLayer)
{
layerExtent = theLayer->extent();

if (QgsProject::instance()->readNumEntry("SpatialRefSys", "/ProjectionsEnabled",0) != 0
&& (ct = theLayer->coordinateTransform()))
{
//transform layer extent to canvas coordinate system
transformedExtent = ct->transform(layerExtent);
}
else
{
// do not transform when projections are not enabled
transformedExtent = layerExtent;
}

if(transformedExtent.xMin() < xmin)
if (theLayer->projectionsEnabled())
{
xmin = transformedExtent.xMin();
}

if(transformedExtent.yMin() < ymin)
{
ymin = transformedExtent.yMin();
// std::cerr<<__FILE__<<__LINE__<<' '
// << layerExtent.stringRep().toLocal8Bit().data() << '\n';

bool split = theLayer->projectExtent(layerExtent, r2);

// std::cerr<<__FILE__<<__LINE__<<' '
// << layerExtent.stringRep().toLocal8Bit().data() << '\n';
}

if(transformedExtent.xMax() > xmax)
if (first)
{
xmax = transformedExtent.xMax();
transformedExtent = layerExtent;
first = false;
}

if(transformedExtent.yMax() > ymax)
else
{
ymax = transformedExtent.yMax();
transformedExtent.combineExtentWith(&layerExtent);
}
}
}

//zoom to bounding box
mMapCanvas->setExtent(QgsRect(xmin, ymin, xmax, ymax));
mMapCanvas->setExtent(transformedExtent);
mMapCanvas->render();
mMapCanvas->refresh();
}

0 comments on commit c9e5a2c

Please sign in to comment.
You can’t perform that action at this time.