@@ -1176,10 +1176,10 @@ __FUNCTION__, __LINE__);
1176
1176
myRasterViewPort->topLeftPoint = theQgsMapToPixel->transform (myRasterExtent.xMin (), myRasterExtent.yMax ());
1177
1177
myRasterViewPort->bottomRightPoint = theQgsMapToPixel->transform (myRasterExtent.xMax (), myRasterExtent.yMin ());
1178
1178
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 );
1183
1183
1184
1184
1185
1185
#ifdef QGISDEBUG
@@ -1241,14 +1241,6 @@ __FUNCTION__, __LINE__);
1241
1241
1242
1242
// /\/\/\ - added to handle zoomed-in rasters
1243
1243
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
- }
1252
1244
1253
1245
// Provider mode: See if a provider key is specified, and if so use the provider instead
1254
1246
@@ -1262,9 +1254,15 @@ QgsDebugMsg("QgsRasterLayer::draw: Checking for provider key.");
1262
1254
1263
1255
QImage* image =
1264
1256
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
1268
1266
);
1269
1267
1270
1268
if (!image)
@@ -1315,15 +1313,24 @@ __FUNCTION__, __LINE__, 1);
1315
1313
}
1316
1314
else
1317
1315
{
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
1322
1328
// 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
+ }
1327
1334
1328
1335
}
1329
1336
0 commit comments