3

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")
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 17, 2016 at 21:40
1
  • 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? Commented Aug 17, 2016 at 22:40

1 Answer 1

5

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 )
answered Aug 17, 2016 at 23:16
2
  • 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. Commented Aug 18, 2016 at 1:25
  • @MichaelMiles-Stimson, actually, you'll get a TypeError, but noted and I've updated my answer. Commented Aug 18, 2016 at 2:50

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.