Select to view content in your preferred language

Returning names of rasters with maximum value

1390
11
Jump to solution
07-30-2013 11:07 AM
JeremyProville
Emerging Contributor
Hi,

I have a pile of 23 different rasters, on which I'm performing various calculations. One of them is a simple Maximization, using Cell Statistics, and one thing I'd like to see is a raster showing me which of the 23 layers contained the maximum value that was chosen. I'm finding this is pretty hard to do.

In Arc 9.3, I solved this problem using a long string of Con() and Max() statements in the raster calculator, to assign an integer index value to each raster that was selected in the maximization. This is no longer possible in Arc 10 since Max() has been removed. I tried an approach in Python using the code below, but it does not really work. What I'm looking for is a way to return a raster with either index values from 1-23, or ideally the names of each input raster. Each name would be assigned to the cell if it was chosen as a maximum value.

Hopefully this makes sense, I can elaborate if not. Any ideas here would be hugely helpful. Here's some sample code I've been playing with, but there has to be a simpler, more elegant solution - perhaps an obvious tool I'm missing?

Thanks!

opt2 = Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "blank",-9999, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "CottonLB" ,1, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "FodderLB" ,2, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "FruitsLB" ,3, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "GroundnutLB" ,4, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "JatrophaLB" ,5, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "MaizeLB" ,6, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "MilletLB" ,7, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "MiscanthusLB" ,8, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "NarcostimulantsLB" ,9, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "OilpalmLB" ,10, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "PulsesLB" ,11, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "RapeseedLB" ,12, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "RiceLB" ,13, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "RootsLB" ,14, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "SorghumLB" ,15, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "SoybeanLB" ,16, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "SugarbeetLB" ,17, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "SugarcaneLB" ,18, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "SunflowerLB" ,19, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "SwitchgrassLB" ,20, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "TubersLB" ,21, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "VegetablesLB" ,22, Con(CellStatistics(["CottonLB","FodderLB","FruitsLB","GroundnutLB","JatrophaLB","MaizeLB","MilletLB","MiscanthusLB","NarcostimulantsLB","OilpalmLB","PulsesLB","RapeseedLB","RiceLB","RootsLB","SorghumLB","SoybeanLB","SugarbeetLB","SugarcaneLB","SunflowerLB","SwitchgrassLB","TubersLB","VegetablesLB","WheatLB","blank"],"MAXIMUM","DATA") == "WheatLB" ,23,-9999))))))))))))))))))))))))
0 Kudos
11 Replies
Luke_Pinner
MVP Regular Contributor
I'm sure setting the output extent to MAXOF/union of inputs used to work in Workstation GRID/older versions of Spatial Analyst when the multiple inputs were Con(IsNull(...),...) functions.

I think what is happening is that ArcGIS is processing the raster calculator statement from inside to out - i.e it processes the Con(IsNull(...),...) statements individually and as there is only one raster in each of those, the output extent for each Con... statement is set to that of the single input raster, instead of parsing the whole statement and working out the extent for all rasters before processing the Con statements.

Workaround:

Generate a dummy raster with output extent set to MAXOF/union of inputs using something like raster1+raster2+etc...
Then set output extent = dummy raster and run HighestPosition(Con(IsNull(raster1),-999,raster1),etc...)
0 Kudos
JeremyProville
Emerging Contributor
Thanks Luke - that and a combination of the other workarounds seems to have done the trick. I ended up making a blank 'extent' raster with -9999 values in every cell, and using that to set the extent. I also had to toss in a constant (-9998) in the final raster calculator formula, for HighestPosition. I put this in last place so that I could filter out these NoData (now -9998) areas.

Appreciate everyone's help!
0 Kudos