[GIS] Raster to Numpy Array – No data values

arcgis-desktoparcpynodatanumpy

I have several single band, 32 bit float raster datasets (fgdbr) that i want to use to build a raster stack (depth) in numpy by doing something like this dv = np.dstack((d_array, v_array))

With reference to the code snippet below,

import arcpy
d = r'P:\Sample.gdb\D_0100yr_Max'
dr  = arcpy.Raster(d)
dr.minimum # returns  0.000562695786356926
dr.maximum # returns 2.8690600395202637
dr.noDataValue # prints nothing
dr.pixelType # returns F32

d_array = arcpy.RasterToNumPyArray(dr.catalogPath, "#", "#", "#", dr.noDataValue)

d_array.max() # returns 2.86906
d_array.min() # returns -3.4028231e+38

If dr.noDataValue prints nothing, where does the RasterToNumpyArray function read the no data value from such that d_array.min() returns -3.4028231e+38 ?

enter image description here

Best Answer

this is a sample code I found in ESRI Documents. as you see in code, defined a constant value for "NoData"

import arcpy
import numpy

# Get input Raster properties
inRas = arcpy.Raster('C:/data/inRaster')
lowerLeft = arcpy.Point(inRas.extent.XMin,inRas.extent.YMin)
cellSize = ras.meanCellWidth

# Convert Raster to numpy array
arr = arcpy.RasterToNumPyArray(inRas,nodata_to_value=0)

# Calculate percentage of the row for each cell value
arrSum = arr.sum(1)
arrSum.shape = (arr.shape[0],1)
arrPerc = (arr)/arrSum

#Convert Array to raster (keep the origin and cellsize the same as the input)
newRaster = arcpy.NumPyArrayToRaster(arrPerc,lowerLeft,cellSize,
                                     value_to_nodata=0)
newRaster.save("C:/output/fgdb.gdb/PercentRaster")

you can find more information in detail here "RasterToNumPyArray"