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")
Answer
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 )
No comments:
Post a Comment