Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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)

thanks a lot

share|improve this question
1  
You have described the Highest Position operation. –  whuber Dec 26 '12 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...) –  Snorfalorpagus Dec 29 '12 at 22:44

1 Answer 1

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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