Skip to content

Commit a8673c3

Browse files
author
g_j_m
committed
Merged r6372 from 0.8 release branch to head
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6373 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 7ae236e commit a8673c3

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/raster/qgsrasterlayer.cpp

+15-10
Original file line numberDiff line numberDiff line change
@@ -1133,16 +1133,21 @@ __FUNCTION__, __LINE__);
11331133
myRasterViewPort->clippedYMinDouble = (myRasterExtent.yMin() - adfGeoTransform[3]) / adfGeoTransform[5];
11341134
myRasterViewPort->clippedYMaxDouble = (myRasterExtent.yMax() - adfGeoTransform[3]) / adfGeoTransform[5];
11351135

1136-
// We do a "+2" for each of the 2 assignments below because:
1137-
// + 1 to simulate a ceil() out of static_cast<int> which otherwise is just a truncation.
1138-
// + 1 to allow for the fact that the left hand source pixel may be mostly scrolled out of view
1139-
// and therefore a fraction of a pixel would "leak" in the right hand side.
1140-
// (we could test for this case more explicitly if we wanted to be pedantic, but
1141-
// it's easier to just add one pixel "just in case")
1142-
myRasterViewPort->clippedWidthInt =
1143-
abs(static_cast < int >(myRasterViewPort->clippedXMaxDouble - myRasterViewPort->clippedXMinDouble)) + 2;
1144-
myRasterViewPort->clippedHeightInt =
1145-
abs(static_cast < int >(myRasterViewPort->clippedYMaxDouble - myRasterViewPort->clippedYMinDouble)) + 2;
1136+
// Sometimes the Ymin/Ymax are reversed.
1137+
if (myRasterViewPort->clippedYMinDouble > myRasterViewPort->clippedYMaxDouble)
1138+
{
1139+
double t = myRasterViewPort->clippedYMinDouble;
1140+
myRasterViewPort->clippedYMinDouble = myRasterViewPort->clippedYMaxDouble;
1141+
myRasterViewPort->clippedYMaxDouble = t;
1142+
}
1143+
1144+
// Set the clipped width and height to encompass all of the source pixels
1145+
// that could end up being displayed.
1146+
myRasterViewPort->clippedWidthInt =
1147+
static_cast<int>(ceil(myRasterViewPort->clippedXMaxDouble) - floor(myRasterViewPort->clippedXMinDouble));
1148+
1149+
myRasterViewPort->clippedHeightInt =
1150+
static_cast<int>(ceil(myRasterViewPort->clippedYMaxDouble) - floor(myRasterViewPort->clippedYMinDouble));
11461151

11471152
// but make sure the intended SE corner extent doesn't exceed the SE corner
11481153
// of the source raster, otherwise GDAL's RasterIO gives an error and returns nothing.

0 commit comments

Comments
 (0)