diff --git a/CHANGELOG.md b/CHANGELOG.md index 654bdaf20442684515010c7e98a14d0fb2653e0b..48847ebddc548feb0bf7e3c9a55e0491a4923ce8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ release. --> ## [Unreleased] +### Fixed +- Fixed a bug where scale and offset were not being read or applied to GeoDataset objects. ## [1.5.5]() ### Fixed diff --git a/plio/io/io_gdal.py b/plio/io/io_gdal.py index 749fa405ad5f2d7d7d2f4286053cc7ee61046d0e..f67ca5bdc76f84f588c4280c34c5d9be7ae86d3e 100644 --- a/plio/io/io_gdal.py +++ b/plio/io/io_gdal.py @@ -506,14 +506,18 @@ class GeoDataset(object): """ band = self.dataset.GetRasterBand(band) - + offset = band.GetOffset() + offset = 0 if offset is None else offset + scale = band.GetScale() + scale = 1 if scale is None else scale + if dtype is None: dtype = GDAL2NP_CONVERSION[band.DataType] dtype = getattr(np, dtype) if not pixels: - array = band.ReadAsArray().astype(dtype) + array = (band.ReadAsArray().astype(dtype) + offset) * scale #if self.north_up == False: # array = np.flipud(array) else: @@ -534,7 +538,7 @@ class GeoDataset(object): if ystart + ycount > ymax: ycount = ymax - ystart - array = band.ReadAsArray(xstart, ystart, xcount, ycount).astype(dtype) + array = (band.ReadAsArray(xstart, ystart, xcount, ycount).astype(dtype) + offset) * scale return array