1

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?

menes
1,4272 gold badges8 silver badges25 bronze badges
asked Nov 11, 2018 at 0:03
3
  • there is a nodata parameter in RasterToNumpy, discussed here: gis.stackexchange.com/q/217775/46073 Commented 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. Commented Nov 13, 2018 at 22:59
  • @Hornbydd Would you please take a look at this question? Commented Nov 13, 2018 at 23:36

1 Answer 1

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.

answered May 10, 2021 at 21:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.