Skip to content

Commit bdc3894

Browse files
author
g_j_m
committed
Fix for ticket #475. The fix has introduced an intermittent off-by-one-pixel
display problem, but that's better than the original problem! The solution was to remove what looked like some testing code that somehow got committed a while ago. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6358 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 85b6307 commit bdc3894

File tree

1 file changed

+0
-85
lines changed

1 file changed

+0
-85
lines changed

src/raster/qgsrasterlayer.cpp

-85
Original file line numberDiff line numberDiff line change
@@ -1132,14 +1132,6 @@ __FUNCTION__, __LINE__);
11321132
myRasterViewPort->clippedHeightInt =
11331133
abs(static_cast < int >(myRasterViewPort->clippedYMaxDouble - myRasterViewPort->clippedYMinDouble)) + 2;
11341134

1135-
/*
1136-
// Add one to the raster dimensions to guard against the integer truncation
1137-
// effects of static_cast<int>
1138-
// TODO: Can we get rid of this now that we are rounding at the point of the static_cast?
1139-
myRasterViewPort->clippedWidthInt++;
1140-
myRasterViewPort->clippedHeightInt++;
1141-
*/
1142-
11431135
// but make sure the intended SE corner extent doesn't exceed the SE corner
11441136
// of the source raster, otherwise GDAL's RasterIO gives an error and returns nothing.
11451137
// The SE corner = NW origin + dimensions of the image itself.
@@ -1156,92 +1148,15 @@ __FUNCTION__, __LINE__);
11561148
rasterYDimInt - myRasterViewPort->rectYOffsetInt;
11571149
}
11581150

1159-
/*
1160-
if (myRasterViewPort->clippedWidthInt > rasterXDimInt)
1161-
{
1162-
myRasterViewPort->clippedWidthInt = rasterXDimInt;
1163-
}
1164-
if (myRasterViewPort->clippedHeightInt > rasterYDimInt)
1165-
{
1166-
myRasterViewPort->clippedHeightInt = rasterYDimInt;
1167-
}
1168-
*/
1169-
11701151
// get dimensions of clipped raster image in device coordinate space (this is the size of the viewport)
11711152
myRasterViewPort->topLeftPoint = theQgsMapToPixel->transform(myRasterExtent.xMin(), myRasterExtent.yMax());
11721153
myRasterViewPort->bottomRightPoint = theQgsMapToPixel->transform(myRasterExtent.xMax(), myRasterExtent.yMin());
11731154

1174-
// Try a different method - round up to the nearest whole source pixel.
11751155
myRasterViewPort->drawableAreaXDimInt =
11761156
abs(static_cast<int> (myRasterViewPort->clippedWidthInt / theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[1]));
11771157
myRasterViewPort->drawableAreaYDimInt =
11781158
abs(static_cast<int> (myRasterViewPort->clippedHeightInt / theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[5]));
11791159

1180-
/*
1181-
myRasterViewPort->drawableAreaXDimInt =
1182-
static_cast<int> ((myRasterViewPort->clippedXMaxDouble - myRasterViewPort->clippedXMinDouble) /
1183-
theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[1]);
1184-
1185-
myRasterViewPort->drawableAreaYDimInt =
1186-
static_cast<int> ((myRasterViewPort->clippedYMaxDouble - myRasterViewPort->clippedYMinDouble) /
1187-
theQgsMapToPixel->mapUnitsPerPixel() * adfGeoTransform[5]);
1188-
*/
1189-
1190-
/*
1191-
// Since GDAL's RasterIO can't handle floating point, we have to round to
1192-
// the nearest pixel. Add 0.5 to get rounding instead of truncation
1193-
// out of static_cast<int>.
1194-
myRasterViewPort->drawableAreaXDimInt =
1195-
static_cast<int>(myRasterViewPort->bottomRightPoint.x() + 0.5) -
1196-
static_cast<int>(myRasterViewPort->topLeftPoint .x() + 0.5);
1197-
1198-
1199-
*/
1200-
1201-
// get dimensions of clipped raster image in raster pixel space/ RasterIO will do the scaling for us.
1202-
// So for example, if the user is zoomed in a long way, there may only be e.g. 5x5 pixels retrieved from
1203-
// the raw raster data, but rasterio will seamlessly scale the up to whatever the screen coordinats are
1204-
// e.g. a 600x800 display window (see next section below)
1205-
myRasterViewPort->clippedXMinDouble = (myRasterExtent.xMin() - adfGeoTransform[0]) / adfGeoTransform[1];
1206-
myRasterViewPort->clippedXMaxDouble = (myRasterExtent.xMax() - adfGeoTransform[0]) / adfGeoTransform[1];
1207-
myRasterViewPort->clippedYMinDouble = (myRasterExtent.yMin() - adfGeoTransform[3]) / adfGeoTransform[5];
1208-
myRasterViewPort->clippedYMaxDouble = (myRasterExtent.yMax() - adfGeoTransform[3]) / adfGeoTransform[5];
1209-
myRasterViewPort->clippedWidthInt =
1210-
abs(static_cast < int >(myRasterViewPort->clippedXMaxDouble - myRasterViewPort->clippedXMinDouble));
1211-
myRasterViewPort->clippedHeightInt =
1212-
abs(static_cast < int >(myRasterViewPort->clippedYMaxDouble - myRasterViewPort->clippedYMinDouble));
1213-
1214-
// Add one to the raster dimensions to guard against the integer truncation
1215-
// effects of static_cast<int>
1216-
// TODO: Can we get rid of this now that we are rounding at the point of the static_cast?
1217-
myRasterViewPort->clippedWidthInt++;
1218-
myRasterViewPort->clippedHeightInt++;
1219-
1220-
// make sure we don't exceed size of raster, otherwise GDAL RasterIO doesn't like it
1221-
if (myRasterViewPort->clippedWidthInt > rasterXDimInt)
1222-
{
1223-
myRasterViewPort->clippedWidthInt = rasterXDimInt;
1224-
}
1225-
if (myRasterViewPort->clippedHeightInt > rasterYDimInt)
1226-
{
1227-
myRasterViewPort->clippedHeightInt = rasterYDimInt;
1228-
}
1229-
1230-
// get dimensions of clipped raster image in device coordinate space (this is the size of the viewport)
1231-
myRasterViewPort->topLeftPoint = theQgsMapToPixel->transform(myRasterExtent.xMin(), myRasterExtent.yMax());
1232-
myRasterViewPort->bottomRightPoint = theQgsMapToPixel->transform(myRasterExtent.xMax(), myRasterExtent.yMin());
1233-
1234-
// Since GDAL's RasterIO can't handle floating point, we have to round to
1235-
// the nearest pixel. Add 0.5 to get rounding instead of truncation
1236-
// out of static_cast<int>.
1237-
myRasterViewPort->drawableAreaXDimInt =
1238-
static_cast<int>(myRasterViewPort->bottomRightPoint.x() + 0.5) -
1239-
static_cast<int>(myRasterViewPort->topLeftPoint .x() + 0.5);
1240-
1241-
myRasterViewPort->drawableAreaYDimInt =
1242-
static_cast<int>(myRasterViewPort->bottomRightPoint.y() + 0.5) -
1243-
static_cast<int>(myRasterViewPort->topLeftPoint .y() + 0.5);
1244-
12451160
#ifdef QGISDEBUG
12461161
QgsLogger::debug("QgsRasterLayer::draw: mapUnitsPerPixel", theQgsMapToPixel->mapUnitsPerPixel(), 1, __FILE__,\
12471162
__FUNCTION__, __LINE__);

0 commit comments

Comments
 (0)