I am relatively new to the ArcGIS-Python environment and want to calculate elevation raster slope. But it says "ValueError: setting an array element with a sequence". Below code is what I have.
import arcpy, numpy, math
from numpy import *
from arcpy import env
arcpy.env.workspace = ("D:/input")
inRas = arcpy.RasterToNumPyArray('t1')
[rows,cols]=inRas.shape
slope=zeros((rows,cols), float)
desc = arcpy.Describe('t1')
cellSize = desc.meanCellHeight
extent = desc.Extent
pnt = arcpy.Point(extent.XMin,extent.YMin)
for j in range(0,rows-1):
for i in range(0,cols-1):
slope[i,j]= inRas[math.sqrt(((cols+1)-(cols-1)) ** 2 + ((rows+1)-(rows-1)) ** 2)]
print slope
myArray=arcpy.NumPyArrayToRaster('slope',pnt,cellSize,cellSize)
myArray.save("D:/output/t1")
i
andj
! (The formula simplifies toinRas[math.sqrt(8)]
.) Indeed, just what does it mean to index a raster (inRas
) by a floating point value?