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:

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:

enter image description here

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?

| improve this question | | | | |
  • there is a nodata parameter in RasterToNumpy, discussed here: gis.stackexchange.com/q/217775/46073 – Andreas Müller Nov 12 '18 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. – sMartines Nov 13 '18 at 22:59
  • @Hornbydd Would you please take a look at this question? – sMartines Nov 13 '18 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.