Select to view content in your preferred language

SingleOutputMapAlgebra to v10.0 syntax - lookup() function in a loop?

608
3
09-20-2012 01:57 PM
ChrisSnyder
Honored Contributor
I am trying to rewrite some v9.3 SingleOutputMapAlgebra Python code in v10.0. Basically I have a bunch of rasters called "nst_*" (example: nst_lp_1, nst_lp2, nst_lp_3, ...) that have an integer field in their attribute tables called "NST", and I am wanting to produce a single output raster that represents the maximum "NST" value of all the input rasters. In v9.3 this was easy using dot notation and string SOMA string construction... But now in v10 I am running into some issues with the confounded Lookup() tool and how to best do this in an efficient manner. My v9.3 code:

#Process: Produce a grid that is the max nesting habitat value from all scenarios and all decades
maxString = ""
gp.workspace = root
gridList = gp.listrasters("nst_*")
for grid in gridList:
    maxString = maxString + grid + ".NST" + ","
somaExp = "max(" + maxString[:-1] + ")"
maxNestingScoreGrd = root + "\\max_nesting"
gp.SingleOutputMapAlgebra_sa(somaExp, maxNestingScoreGrd, "")


BTW: I know I have to replace good ole' max() with CellStatistics()... max() is no longer with us.

Basically, I'm looking for an clean way to incorporate the lookup() function in a loop inside another function... Any one have ideas how to do this elegantly in v10.0 synax?
Tags (2)
0 Kudos
3 Replies
ChrisSnyder
Honored Contributor
I guess this works, but it's not as pretty and takes longer making all the lookup scratch files.

gridList = arcpy.ListRasters("nst_*")
i = 0
for grid in gridList:
    i = i + 1
    tmpGrd = arcpy.sa.Lookup(grid, "NST")
    tmpGrd.save("tmp_" + str(i))
gridList = arcpy.ListRasters("tmp_*")
nstMaxGrd = arcpy.sa.CellStatistics(gridList, "MAXIMUM")
nstMaxGrd.save("max_nesting")
for grid in gridList:
    arcpy.Delete_management(grid)
0 Kudos
JayanKarunasinghe
Emerging Contributor
I am trying to rewrite some v9.3 SingleOutputMapAlgebra Python code in v10.0. Basically I have a bunch of rasters called "nst_*" (example: nst_lp_1, nst_lp2, nst_lp_3, ...) that have an integer field in their attribute tables called "NST", and I am wanting to produce a single output raster that represents the maximum "NST" value of all the input rasters. In v9.3 this was easy using dot notation and string SOMA string construction... But now in v10 I am running into some issues with the confounded Lookup() tool and how to best do this in an efficient manner. My v9.3 code:

#Process: Produce a grid that is the max nesting habitat value from all scenarios and all decades
maxString = ""
gp.workspace = root
gridList = gp.listrasters("nst_*")
for grid in gridList:
    maxString = maxString + grid + ".NST" + ","
somaExp = "max(" + maxString[:-1] + ")"
maxNestingScoreGrd = root + "\\max_nesting"
gp.SingleOutputMapAlgebra_sa(somaExp, maxNestingScoreGrd, "")


BTW: I know I have to replace good ole' max() with CellStatistics()... max() is no longer with us.

Basically, I'm looking for an clean way to incorporate the lookup() function in a loop inside another function... Any one have ideas how to do this elegantly in v10.0 synax?


Hi How are you
If I am sending this to as  a mistake please transfer to right forum.

I am new to spatial analyst and I need to create maps using regression in GIS
would you able to help me
Thanks

Jayan
Jayank30@gmail.com
0 Kudos
ChrisSnyder
Honored Contributor
"I am new to spatial analyst and I need to create maps using regression in GIS
would you able to help me"


That is a pretty tall order there... but here's something to get you started: http://resources.arcgis.com/en/help/main/10.1/index.html#//005p00000023000000

You might want to check out these forums instead:
http://forums.arcgis.com/forums/110-Spatial-Statistics
http://forums.arcgis.com/forums/107-Spatial-Analyst
http://forums.arcgis.com/forums/100-Geostatistical-Analyst
0 Kudos