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 )
myRaster.save("E:\deptht")
-
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?Michael Stimson– Michael Stimson2016年08月17日 22:40:59 +00:00Commented Aug 17, 2016 at 22:40
1 Answer 1
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.Michael Stimson– Michael Stimson2016年08月18日 01:25:23 +00:00Commented Aug 18, 2016 at 1:25
-
@MichaelMiles-Stimson, actually, you'll get a TypeError, but noted and I've updated my answer.user2856– user28562016年08月18日 02:50:27 +00:00Commented Aug 18, 2016 at 2:50