@@ -1132,14 +1132,6 @@ __FUNCTION__, __LINE__);
1132
1132
myRasterViewPort->clippedHeightInt =
1133
1133
abs (static_cast < int >(myRasterViewPort->clippedYMaxDouble - myRasterViewPort->clippedYMinDouble )) + 2 ;
1134
1134
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
-
1143
1135
// but make sure the intended SE corner extent doesn't exceed the SE corner
1144
1136
// of the source raster, otherwise GDAL's RasterIO gives an error and returns nothing.
1145
1137
// The SE corner = NW origin + dimensions of the image itself.
@@ -1156,92 +1148,15 @@ __FUNCTION__, __LINE__);
1156
1148
rasterYDimInt - myRasterViewPort->rectYOffsetInt ;
1157
1149
}
1158
1150
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
-
1170
1151
// get dimensions of clipped raster image in device coordinate space (this is the size of the viewport)
1171
1152
myRasterViewPort->topLeftPoint = theQgsMapToPixel->transform (myRasterExtent.xMin (), myRasterExtent.yMax ());
1172
1153
myRasterViewPort->bottomRightPoint = theQgsMapToPixel->transform (myRasterExtent.xMax (), myRasterExtent.yMin ());
1173
1154
1174
- // Try a different method - round up to the nearest whole source pixel.
1175
1155
myRasterViewPort->drawableAreaXDimInt =
1176
1156
abs (static_cast <int > (myRasterViewPort->clippedWidthInt / theQgsMapToPixel->mapUnitsPerPixel () * adfGeoTransform[1 ]));
1177
1157
myRasterViewPort->drawableAreaYDimInt =
1178
1158
abs (static_cast <int > (myRasterViewPort->clippedHeightInt / theQgsMapToPixel->mapUnitsPerPixel () * adfGeoTransform[5 ]));
1179
1159
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
-
1245
1160
#ifdef QGISDEBUG
1246
1161
QgsLogger::debug (" QgsRasterLayer::draw: mapUnitsPerPixel" , theQgsMapToPixel->mapUnitsPerPixel (), 1 , __FILE__,\
1247
1162
__FUNCTION__, __LINE__);
0 commit comments