Raster to Numpy

Discussion created by gnewburyiv on Sep 26, 2013
Latest reply on Apr 7, 2014 by tom_adair
The raster to numpy tripped me up for a bit until I realized that there while you may specify the lower left for the raster to numpy array function, the actual positions within the array will be from the upper left of that selection box. Hope this helps someone else out there.

```import numpy
inputDem = r"inputFileHere"
# Convert Raster to Array, Default using LowerLeft as Origin
rasArray = arcpy.RasterToNumPyArray(inputDem)
maxVal = rasArray.max() #Max Elevation
minVal = rasArray.min() #Min Elevation

maxValpos = numpy.unravel_index(rasArray.argmax(),rasArray.shape) #Max Elevation Position in Array
minValpos = numpy.unravel_index(rasArray.argmin(),rasArray.shape) #Min Elevatino Position in Array

desc = arcpy.Describe(inputDem)

# What an initual guess would be for the actual max position
#  typically think first value '[0]' is associated with 'X' and second value '[1]' is associated with 'Y'
utmX = desc.extent.lowerLeft.X + maxValpos[0]
utmY = desc.extent.lowerLeft.Y + maxValpos[1]

# But the actual result that is correct would be:
utmX = desc.extent.upperLeft.X + maxValpos[1]
utmY = desc.extent.upperLeft.Y - maxValpos[0]

# So while you may specify the lower left corner, that is for defining the origin for your table, but the actual
# table dimension references are from the upper left. With the coordinates within the table being (Y,X) i.e. (row,column)```