@@ -293,8 +293,18 @@ isce3::error::ErrorCode isce3::geometry::DEMInterpolator::loadDEM(
293
293
_deltay = delta_y;
294
294
295
295
// Get DEMInterpolator width and length
296
- const long width = max_x_idx - min_x_idx;
297
- const long length = max_y_idx - min_y_idx;
296
+ long width = max_x_idx - min_x_idx;
297
+ long length = max_y_idx - min_y_idx;
298
+
299
+ // Make sure raster subset is does not extrapolate raster dimensions
300
+ if (!flag_dem_file_discontinuity && min_x_idx + width > demRaster.width ()) {
301
+ width = demRaster.width () - min_x_idx;
302
+ max_x_idx = min_x_idx + width;
303
+ }
304
+ if (!flag_dem_file_discontinuity && min_y_idx + length > demRaster.length ()) {
305
+ length = demRaster.length () - min_y_idx;
306
+ max_y_idx = min_y_idx + length;
307
+ }
298
308
299
309
// If DEM has no valid points, escape
300
310
if (width <= 0 || length <= 0 ) {
@@ -303,16 +313,18 @@ isce3::error::ErrorCode isce3::geometry::DEMInterpolator::loadDEM(
303
313
return isce3::error::ErrorCode::OutOfBoundsDem;
304
314
}
305
315
306
- // Resize DEM array and fill it with NaN values
316
+ // Resize DEM array
307
317
_dem.resize (length, width);
308
- _dem.fill (std::numeric_limits<float >::quiet_NaN ());
309
318
310
319
if (!flag_dem_file_discontinuity) {
311
320
// Read single block from DEM
312
321
demRaster.getBlock (_dem.data (), min_x_idx, min_y_idx, width, length);
313
322
314
323
} else {
315
324
325
+ // Fill DEM array with NaN values
326
+ _dem.fill (std::numeric_limits<float >::quiet_NaN ());
327
+
316
328
// Read DEM in two blocks "unrolling" the western side of the DEM around
317
329
// the DEM file discontinuity
318
330
const long width_discontinuity_left = demRaster.width () - min_x_idx;
0 commit comments