Skip to content

Commit a1a1173

Browse files
author
homann
committed
Partial fix for bug #632 (size too large error).
git-svn-id: http://svn.osgeo.org/qgis/branches/Release-0_8_0@6755 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 1834070 commit a1a1173

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

src/raster/qgsrasterlayer.cpp

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,10 +1176,10 @@ __FUNCTION__, __LINE__);
11761176
myRasterViewPort->topLeftPoint = theQgsMapToPixel->transform(myRasterExtent.xMin(), myRasterExtent.yMax());
11771177
myRasterViewPort->bottomRightPoint = theQgsMapToPixel->transform(myRasterExtent.xMax(), myRasterExtent.yMin());
11781178

1179-
myRasterViewPort->drawableAreaXDimInt =
1180-
abs(static_cast<int> (myRasterViewPort->clippedWidthInt / theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[1]));
1181-
myRasterViewPort->drawableAreaYDimInt =
1182-
abs(static_cast<int> (myRasterViewPort->clippedHeightInt / theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[5]));
1179+
myRasterViewPort->drawableAreaXDimInt = static_cast<int>
1180+
(fabs( (myRasterViewPort->clippedWidthInt / theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[1])) + 0.5);
1181+
myRasterViewPort->drawableAreaYDimInt = static_cast<int>
1182+
(fabs( (myRasterViewPort->clippedHeightInt / theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[5])) + 0.5);
11831183

11841184

11851185
#ifdef QGISDEBUG
@@ -1241,14 +1241,6 @@ __FUNCTION__, __LINE__);
12411241

12421242
// /\/\/\ - added to handle zoomed-in rasters
12431243

1244-
if ((myRasterViewPort->drawableAreaXDimInt) > 4000 && (myRasterViewPort->drawableAreaYDimInt > 4000))
1245-
{
1246-
// We have scale one raster pixel to more than 4000 screen pixels. What's the point of showing this layer?
1247-
// Instead, we just stop displaying the layer. Prevents allocating the entire world of memory for showing
1248-
// The pixel in all its glory.
1249-
QgsDebugMsg("Too zoomed out! Raster will not display");
1250-
return TRUE;
1251-
}
12521244

12531245
// Provider mode: See if a provider key is specified, and if so use the provider instead
12541246

@@ -1262,9 +1254,15 @@ QgsDebugMsg("QgsRasterLayer::draw: Checking for provider key.");
12621254

12631255
QImage* image =
12641256
dataProvider->draw(
1265-
myRasterExtent,
1266-
myRasterViewPort->drawableAreaXDimInt,
1267-
myRasterViewPort->drawableAreaYDimInt
1257+
myRasterExtent,
1258+
// Below should calculate to the actual pixel size of the
1259+
// part of the layer that's visible.
1260+
static_cast<int>( fabs( (myRasterViewPort->clippedXMaxDouble - myRasterViewPort->clippedXMinDouble)
1261+
/ theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[1]) + 1),
1262+
static_cast<int>( fabs( (myRasterViewPort->clippedYMaxDouble - myRasterViewPort->clippedYMinDouble)
1263+
/ theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[5]) + 1)
1264+
// myRasterViewPort->drawableAreaXDimInt,
1265+
// myRasterViewPort->drawableAreaYDimInt
12681266
);
12691267

12701268
if (!image)
@@ -1315,15 +1313,24 @@ __FUNCTION__, __LINE__, 1);
13151313
}
13161314
else
13171315
{
1318-
// Otherwise use the old-fashioned GDAL direct-drawing style
1319-
// TODO: Move into its own GDAL provider.
1320-
1321-
// \/\/\/ - commented-out to handle zoomed-in rasters
1316+
if ((myRasterViewPort->drawableAreaXDimInt) > 4000 && (myRasterViewPort->drawableAreaYDimInt > 4000))
1317+
{
1318+
// We have scaled one raster pixel to more than 4000 screen pixels. What's the point of showing this layer?
1319+
// Instead, we just stop displaying the layer. Prevents allocating the entire world of memory for showing
1320+
// very few pixels.
1321+
// (Alternatively, we have a very big screen > 2000 x 2000)
1322+
QgsDebugMsg("Too zoomed in! Displaying raster requires too much memory. Raster will not display");
1323+
} else {
1324+
// Otherwise use the old-fashioned GDAL direct-drawing style
1325+
// TODO: Move into its own GDAL provider.
1326+
1327+
// \/\/\/ - commented-out to handle zoomed-in rasters
13221328
// draw(theQPainter,myRasterViewPort);
1323-
// /\/\/\ - commented-out to handle zoomed-in rasters
1324-
// \/\/\/ - added to handle zoomed-in rasters
1325-
draw(theQPainter, myRasterViewPort, theQgsMapToPixel);
1326-
// /\/\/\ - added to handle zoomed-in rasters
1329+
// /\/\/\ - commented-out to handle zoomed-in rasters
1330+
// \/\/\/ - added to handle zoomed-in rasters
1331+
draw(theQPainter, myRasterViewPort, theQgsMapToPixel);
1332+
// /\/\/\ - added to handle zoomed-in rasters
1333+
}
13271334

13281335
}
13291336

0 commit comments

Comments
 (0)