Skip to content

Commit

Permalink
fixes usage of raster datasets with NoData = None
Browse files Browse the repository at this point in the history
  • Loading branch information
Torizin committed Sep 21, 2022
1 parent 9f9c1f4 commit 9e91fdc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 7 additions & 4 deletions core/widgets/ImportData/importData_importRaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@ def _checkNoDataCount(self, raster, mask) -> bool:
"""
rasterarray = raster.getArrayFromBand()
# "nan" breaks the comparison so we temporarily convert it to -9999
if np.isnan(raster.nodata):
np.nan_to_num(rasterarray, copy=False, nan=-9999)
rasterNoData = np.where(rasterarray == -9999)
if raster.nodata:
if np.isnan(raster.nodata):
np.nan_to_num(rasterarray, copy=False, nan=-9999)
rasterNoData = np.where(rasterarray == -9999)
else:
rasterNoData = np.where(rasterarray == raster.nodata)
else:
rasterNoData = np.where(rasterarray == raster.nodata)
rasterNoData = ((),()) # tuple of two empty tuples to indicate absence of NoData
maskarray = mask.getArrayFromBand()
maskNoData = np.where(maskarray == mask.nodata)
if len(rasterNoData[0]) == len(maskNoData[0]):
Expand Down
15 changes: 9 additions & 6 deletions core/widgets/ProjectManager/ProjectManagement_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,16 @@ def createRaster(self, pathRegionRaster: str) -> None:
self.raster.geoTrans[4],
-cellsize)
array = self.raster.getArrayFromBand().astype(np.float32)
if np.isnan(self.raster.nodata):
np.nan_to_num(array, copy=False, nan=-9999)
rasterNoData = -9999
if self.raster.nodata:
if np.isnan(self.raster.nodata):
np.nan_to_num(array, copy=False, nan=-9999)
rasterNoData = -9999
else:
rasterNoData = self.raster.nodata
array[array != rasterNoData] = 1
array[array == rasterNoData] = -9999
else:
rasterNoData = self.raster.nodata
array[array != rasterNoData] = 1
array[array == rasterNoData] = -9999
array = np.ones_like(array)
# Project coordinates by hand
else:
geoTransform = (left, cellsize, 0.0, top, 0.0, -cellsize)
Expand Down

0 comments on commit 9e91fdc

Please sign in to comment.