I have a numpy array saved to disk ( the numpy array is a depth image from a Kinect 360) and I want to convert that numpy array to an ESRI GRID. I have the simple code below to accomplish that task but I get the following error:

Traceback (most recent call last): 
File "C:\gTemp\Text-1.py", line 4, in myRaster = arcpy.NumPyArrayToRaster(myarray,(0.0,0.0),1.0, 1.0, -99999.0 )

File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy__init__.py", line 2299, in NumPyArrayToRaster return _NumPyArrayToRaster(*args, **kwargs) ValueError: Argument in_array: A two or three dimensional NumPy array is required.

I am new to numpy and do not understand why I am getting this error. I am using ArcGIS 10.4

import arcpy
import numpy
myarray = r"E:\depthtester2.npy"
myRaster = arcpy.NumPyArrayToRaster(myarray,(0.0,0.0),1.0, 1.0, -99999.0 )
  • myarray is a string, it needs to be converted (loaded) into a NumPy array to be used in this function. What is in the file E:\depthtester2.npy? Aug 17 '16 at 22:40

Assuming r"E:\depthtester2.npy" is a saved array, use numpy.load to avoid the ValueError, and as noted in the comments, you need to pass a point object to NumPyArrayToRaster or you'll get a TypeError.

myarray = numpy.load(r"E:\depthtester2.npy")
myRaster = arcpy.NumPyArrayToRaster(myarray,arcpy.Point(0.0,0.0),1.0, 1.0, -99999.0 )
  • Also, looking at the docs resources.arcgis.com/en/help/main/10.2/index.html#/… parameter 2 should be an arcpy.Point object, making the line look like myRaster = arcpy.NumPyArrayToRaster(myarray,arcpy.Point(0.0,0.0),1.0, 1.0, -99999.0 ) otherwise you'll get another ValueError. Aug 18 '16 at 1:25
  • @MichaelMiles-Stimson, actually, you'll get a TypeError, but noted and I've updated my answer.
    – user2856
    Aug 18 '16 at 2:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.