Commit c235e9ca authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Bugfix

io.raster.gdal:
- get_GDAL_ds_inmem():
    - modified doxstring
    - bugfix: invalid nodata values are now properly catched

io.raster.GeoArray.GeoArray:
- save(): added automatic creation out output directory

- updated __version__
parent e331bea6
......@@ -15,7 +15,7 @@ __all__=[#'compatibility',
'similarity',
'GeoArray']
__version__ = '20161125_01'
__version__ = '20170103_01'
__author__='Daniel Scheffler'
# Validate GDAL version
......
......@@ -732,20 +732,23 @@ class GeoArray(object):
:param out_path: <str> output path
:param fmt: <str> the output format / GDAL driver code to be used for output creation, e.g. 'ENVI'
Refer to http://www.gdal.org/formats_list.html to get a full list of supported formats.
:param creationOptions: <list> GDAL creation options, e.g. ["QUALITY=80", "REVERSIBLE=YES", "WRITE_METADATA=YES"]
:return:
"""
if not self.q: print('Writing GeoArray of size %s to %s.' %(self.shape, out_path))
if not self.q:
print('Writing GeoArray of size %s to %s.' %(self.shape, out_path))
assert self.ndim in [2,3], 'Only 2D- or 3D arrays are supported.'
if not os.path.isdir(os.path.dirname(out_path)): os.makedirs(os.path.dirname(out_path))
driver = gdal.GetDriverByName(fmt)
if driver is None:
raise Exception("'%s' is not a supported GDAL driver." % fmt)
if self.is_inmem:
driver = gdal.GetDriverByName(fmt)
if driver is None:
raise Exception("'%s' is not a supported GDAL driver." %fmt)
if not os.path.isdir(os.path.dirname(out_path)):
os.makedirs(os.path.dirname(out_path))
if self.is_inmem:
ds = get_GDAL_ds_inmem(self.arr,self.geotransform, self.projection, self.nodata) # expects rows,columns,bands
# set metadata
......
......@@ -22,7 +22,7 @@ def get_GDAL_ds_inmem(array, gt=None, prj=None, nodata=None):
:param array: <numpy.ndarray> in the shape (rows, columns, bands)
:param gt:
:param prj:
:param nodata: nodata value to be set
:param nodata: <int> nodata value to be set (GDAL seems to have issues with non-int nodata values.)
:return:
"""
# FIXME does not respect different nodata values for each band
......@@ -40,10 +40,13 @@ def get_GDAL_ds_inmem(array, gt=None, prj=None, nodata=None):
raise Exception(gdal.GetLastErrorMsg())
if gt: ds.SetGeoTransform(gt)
if prj: ds.SetProjection(prj)
if nodata:
if nodata is not None:
for i in range(ds.RasterCount):
band = ds.GetRasterBand(i+1)
band.SetNoDataValue(nodata)
band = ds.GetRasterBand(i+1)
try:
band.SetNoDataValue(int(nodata))
except TypeError:
raise Exception('TypeError while trying to set NoDataValue to %s. ' %nodata)
band=None
ds.FlushCache() # Write to disk.
return ds
......
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