@@ -1133,16 +1133,21 @@ __FUNCTION__, __LINE__);
1133
1133
myRasterViewPort->clippedYMinDouble = (myRasterExtent.yMin () - adfGeoTransform[3 ]) / adfGeoTransform[5 ];
1134
1134
myRasterViewPort->clippedYMaxDouble = (myRasterExtent.yMax () - adfGeoTransform[3 ]) / adfGeoTransform[5 ];
1135
1135
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 ));
1146
1151
1147
1152
// but make sure the intended SE corner extent doesn't exceed the SE corner
1148
1153
// of the source raster, otherwise GDAL's RasterIO gives an error and returns nothing.
0 commit comments