I am attempting to import a GeoTiff mask in which pixels of interest have the value 1, and off-target pixels are Nan using Rasterio. When viewed in QGIS and with plt.show()
, off target pixels are shown correctly as "nodata" in QGIS and []
when viewed in plt.show()
. However, when I read the band of the dataset, nan values within the boundaries of the image are converted to zeroes, whereas the added border pixels remain as nodata (shown as white in image below). Is there a way to retain the nan values when converted to an np.array
?
file = r'[GeoTiff Path]'
# Convert file to raster
exg = rasterio.open(file, mode = 'r')
# Plotting raster and shapefile
fig, ax = plt.subplots(1, 1)
show(exg, ax = ax)
plots.plot(ax = ax, facecolor = 'None', edgecolor = 'red')
plt.show()
# Assign raster values to numpy nd array
exg_array = exg.read(1)
show(exg_array)
dtype
of your raster?