1

I have 2 raster images; ras1 (an image with max value) and ras2 (an image with 5 bands). Basically. ras1 image extracted from ras2 images.

I'd like to find bands from ras2 in which max value occur and recode them 1 to 5. For example, ras2 has band1, b2, b3, b4, b5. if max value of ras1 occur in band 3, 3 return to output, if max of ras1 occur in band 4, 4 return to output etc.

Could you give me suggestion what tool in Arcgis has ability to do this?

I used inlist tool, but it gave me the values (not the number 1-5).

2
  • 1
    You have described the Highest Position operation.
    – whuber
    Commented Dec 26, 2012 at 16:18
  • @whuber I wasn't aware of the Highest Position function when I posted my answer. I guess it's a more ArcGIS-y solution. It should be noted that it requires Spatial Analyst, whereas the numpy solution does not - this may or may not be an issue (we have to fight for an SA licence from the network pool at my workplace...) Commented Dec 29, 2012 at 22:44

1 Answer 1

3

You can achieve this using the numpy.argmax() function. Enter the following into the Python console (adjust to taste):

import arcpy
import numpy

# convert the raster to a 3-dimensional numpy array (x, y, band)
values = arcpy.RasterToNumPyArray("ras2")

# calculate the index of the maximum value along the band axis

#(1-based, rather than the default 0-based)
indices = numpy.argmax(values, axis=2) + 1

# write the output to a new raster
raster = arcpy.NumPyArrayToRaster(indices)
raster.save('C:/ArcGIS/maximum.tif')

Not tested, as I don't have ArcGIS to hand...

Relevant documentation:

http://docs.scipy.org/doc/numpy/reference/generated/numpy.argmax.html http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000012z000000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.