Commit 932008c2 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Improved error handling within GeoArray.from_path().

parent 7fd740e0
......@@ -819,26 +819,27 @@ class GeoArray(object):
# read subset area from disk
if bL == list(range(0, B)):
tempArr = gdalnumeric.LoadFile(path, cS, rS, cE - cS + 1, rE - rS + 1)
if tempArr is None:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
out_arr = np.swapaxes(np.swapaxes(tempArr, 0, 2), 0, 1) if B > 1 else tempArr
if out_arr is None:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
else:
ds = gdal.Open(path)
if len(bL) == 1:
band = ds.GetRasterBand(bL[0] + 1)
out_arr= band.ReadAsArray(cS, rS, cE - cS + 1, rE - rS + 1)
band = None
if out_arr is None:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
del band
else:
out_arr = np.empty((rE - rS + 1, cE - cS + 1, len(bL)))
for i, bIdx in enumerate(bL):
band = ds.GetRasterBand(bIdx + 1)
out_arr[:, :, i] = band.ReadAsArray(cS, rS, cE - cS + 1, rE - rS + 1)
band = None
if out_arr is None:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
del band
ds = None
if out_arr is None:
raise Exception('Error reading file: ' + gdal.GetLastErrorMsg())
del ds
# only set self.arr if the whole cube has been read (in order to avoid sudden shape changes)
if out_arr.shape==self.shape:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment