Skip to content

Commit

Permalink
gdal_calc.py: raise exception in case of I/O error. Fixes qgis/QGIS#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jun 1, 2020
1 parent 2a0f3ea commit fb88e3c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion gdal/swig/python/scripts/gdal_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ def doit(opts, args):
myval = gdalnumeric.BandReadAsArray(myFiles[i].GetRasterBand(myBandNo),
xoff=myX, yoff=myY,
win_xsize=nXValid, win_ysize=nYValid)
if myval is None:
raise Exception('Input block reading failed')

# fill in nodata values
if myNDV[i] is not None:
Expand Down Expand Up @@ -355,7 +357,14 @@ def doit(opts, args):

# write data block to the output file
myOutB = myOut.GetRasterBand(bandNo)
gdalnumeric.BandWriteArray(myOutB, myResult, xoff=myX, yoff=myY)
if gdalnumeric.BandWriteArray(myOutB, myResult, xoff=myX, yoff=myY) != 0:
raise Exception('Block writing failed')

gdal.ErrorReset()
myOut.FlushCache()
myOut = None
if gdal.GetLastErrorMsg() != '':
raise Exception('Dataset writing failed')

if not opts.quiet:
print("100 - Done")
Expand Down

0 comments on commit fb88e3c

Please sign in to comment.