I work with geographic data and have large raster files I import into python with gdal
. To process them, I convert them to numpy
arrays.
I create an empty array that gets filled with data in a loop. However, I need the NaN values to be at the same location as in my imported rater file.
data = ds.GetRasterBand(1).GetNoDataValue()
data = np.array(ds.GetRasterBand(1).ReadAsArray())
data[data==-9999] = np.nan # set all -9999 as no data value
cols, rows = data.shape
dataOut = np.zeros([ds.RasterYSize, ds.RasterXSize]) # create empty array with zeros
for c in range(cols):
for r in range(rows):
dataOut[c][r] = np.nan if isinstance(data[c][r], np.ndarray) else dataOut[c][r]
So I want my NaN values from my data array to be transferred to my dataOut array. None of those solutions suggested here wored for me...the dataOut array still holds only zeros.