Skip to content

Commit c9e5a2c

Browse files
author
g_j_m
committed
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
1 parent 6b84471 commit c9e5a2c

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

src/gui/qgsmaplayer.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,10 @@ bool QgsMapLayer::projectExtent(QgsRect& extent, QgsRect& r2)
631631
catch (QgsCsException &cse)
632632
{
633633
QgsLogger::warning("Transform error caught in " + QString(__FILE__) + ", line " + QString::number(__LINE__));
634-
extent = QgsRect(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
635-
r2 = QgsRect(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
634+
// Return the untransformed extent when the transformation
635+
// fails rather then the largest extent possible!
636+
//extent = QgsRect(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
637+
//r2 = QgsRect(-DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX);
636638
}
637639
}
638640
return split;

src/legend/qgslegend.cpp

+16-30
Original file line numberDiff line numberDiff line change
@@ -1687,59 +1687,45 @@ void QgsLegend::zoomToLayerExtent()
16871687
return;
16881688
}
16891689

1690-
double xmin = DBL_MAX;
1691-
double ymin = DBL_MAX;
1692-
double xmax = -DBL_MAX;
1693-
double ymax = -DBL_MAX;
1694-
16951690
QgsRect transformedExtent;
16961691
QgsRect layerExtent;
1697-
QgsCoordinateTransform *ct;
1692+
QgsRect r2;
16981693
QgsMapLayer* theLayer;
1694+
bool first(true);
16991695

17001696
for(std::list<QgsLegendLayerFile*>::iterator it= layerFiles.begin(); it != layerFiles.end(); ++it)
17011697
{
17021698
theLayer = (*it)->layer();
17031699
if(theLayer)
17041700
{
17051701
layerExtent = theLayer->extent();
1706-
1707-
if (QgsProject::instance()->readNumEntry("SpatialRefSys", "/ProjectionsEnabled",0) != 0
1708-
&& (ct = theLayer->coordinateTransform()))
1709-
{
1710-
//transform layer extent to canvas coordinate system
1711-
transformedExtent = ct->transform(layerExtent);
1712-
}
1713-
else
1714-
{
1715-
// do not transform when projections are not enabled
1716-
transformedExtent = layerExtent;
1717-
}
17181702

1719-
if(transformedExtent.xMin() < xmin)
1703+
if (theLayer->projectionsEnabled())
17201704
{
1721-
xmin = transformedExtent.xMin();
1722-
}
17231705

1724-
if(transformedExtent.yMin() < ymin)
1725-
{
1726-
ymin = transformedExtent.yMin();
1706+
// std::cerr<<__FILE__<<__LINE__<<' '
1707+
// << layerExtent.stringRep().toLocal8Bit().data() << '\n';
1708+
1709+
bool split = theLayer->projectExtent(layerExtent, r2);
1710+
1711+
// std::cerr<<__FILE__<<__LINE__<<' '
1712+
// << layerExtent.stringRep().toLocal8Bit().data() << '\n';
17271713
}
17281714

1729-
if(transformedExtent.xMax() > xmax)
1715+
if (first)
17301716
{
1731-
xmax = transformedExtent.xMax();
1717+
transformedExtent = layerExtent;
1718+
first = false;
17321719
}
1733-
1734-
if(transformedExtent.yMax() > ymax)
1720+
else
17351721
{
1736-
ymax = transformedExtent.yMax();
1722+
transformedExtent.combineExtentWith(&layerExtent);
17371723
}
17381724
}
17391725
}
17401726

17411727
//zoom to bounding box
1742-
mMapCanvas->setExtent(QgsRect(xmin, ymin, xmax, ymax));
1728+
mMapCanvas->setExtent(transformedExtent);
17431729
mMapCanvas->render();
17441730
mMapCanvas->refresh();
17451731
}

0 commit comments

Comments
 (0)