I am trying a convert a raster dataset [a simple 4 x 4] into a numpy array using RasterToNumPyArray
. Here is my sample raster dataset:
RasterToNumPyArray
however, returns zero for Null
values:
inRaster = "Slope_NULL"
# Create a Raster Object and get its lowerleft
aRObject = arcpy.Raster(inRaster)
lowerLeft = aRObject.extent.lowerLeft
print aRObject.noDataValue
# Create a numpy array of the Raster Object
anArray = arcpy.RasterToNumPyArray(aRObject)
print anArray
and I get:
I am wondering if there is a way that I could get None
or NaN
instead of zero in my array?
I know I can change the Nodata to a value using nodata_to_value
, however, RasterToNumPyArray
syntax is explaining that the default value is None
, and it is important for me to have None
and not zeros in my array.
How can I have None
or NaN
[I am not sure which one is better supported in numpy] in my array?
-
there is a nodata parameter in RasterToNumpy, discussed here: gis.stackexchange.com/q/217775/46073Andreas Müller– Andreas Müller2018年11月12日 21:07:17 +00:00Commented Nov 12, 2018 at 21:07
-
@AndreasMüller Yes, it has a parameter "nodata_to_value" which convert nodata to a value. If it is not set it converts nodata to zero as I showed in my example.sBoroushaki– sBoroushaki2018年11月13日 22:59:11 +00:00Commented Nov 13, 2018 at 22:59
-
@Hornbydd Would you please take a look at this question?sBoroushaki– sBoroushaki2018年11月13日 23:36:57 +00:00Commented Nov 13, 2018 at 23:36
1 Answer 1
I think what you are looking for is NAN in Numpy module:
import numpy as np
arcpy.RasterToNumPyArray(inRaster, nodata_to_value= np.NAN)
Also see for here for other constants defined in Numpy.