AnsweredAssumed Answered

iterating rasters to input into weighted overlay

Question asked by aimong on Oct 16, 2014
Latest reply on Oct 17, 2014 by Dan_Patterson

I am preforming a weighted overlay. All of my raster's are in 1 folder. There are 4 different rasters that will be used in the weighted model (s,v,o,l)

1 run through will use 4 raster's with 0520a as the example code (I have 75 or so codes of rasters in 1 folder)

s0520a

v0520a

o0520a

l0520a

I need to find a way to select a code and loop through each 5 digit code code and add the s,v,o,l to the model then move on to the next code. If this was using a search cursor I would just set for r[0] but I'm not sure how to do that for looping through rasters. Also not sure how to create the output raster (send the code variable to the output name I suppose)

Thanks in advance!

Here is what I have so far:

import arcpy
arcpy.CheckOutExtension("spatial")
arcpy.overwriteOutput = True
inrcras = "C:\\Risk2014\\TestReclass\\"
arcpy.env.workspace = "C:\\Risk2014\\TestReclass"
rcras = sorted(arcpy.ListRasters())
outras = "C:\\Risk2014\\TestWeighted\\w"
for r in rcras:
    print r[4:] #code isolated for iterating
    if r[1] == "s":
        s = inrcras + r
    if r[1] == "v":
        v = inrcras + r
    if r[1] == "o":
        o = inrcras + r
    if r[1] == "l":
        l = inrcras + r
    print s, v, o, l
    #arcpy.gp.WeightedOverlay_sa("(s 25 VALUE (1 1; 2 2; 3 3; 4 4; 5 5; 6 6; 7 7; 8 8; 9 9; NODATA NODATA); v 25 VALUE (1 1; 2 2; 3 3; 4 4; 5 5; 6 6; 7 7; 8 8; 9 9; NODATA NODATA); o 25 VALUE (1 1; 2 2; 3 3; 4 4; 5 5; 6 6; 7 7; 8 8; 9 9; NODATA NODATA); l 25 VALUE (1 1; 2 2; 3 3; 4 4; 5 5; 6 6; 7 7; 8 8; 9 9; NODATA NODATA));1 9 1", outras + ?)
del r, rcras

Outcomes