<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: iterating rasters to input into weighted overlay in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348782#M27365</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;is your indexing off?&amp;nbsp; I think you want to get the 1st character (?), if so it is index 0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; r = 's0520a'&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; r[4:]&lt;/P&gt;&lt;P&gt;'0a'&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; r[1]&lt;/P&gt;&lt;P&gt;'0'&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; r[0]&lt;/P&gt;&lt;P&gt;'s'&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Oct 2014 22:02:54 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2014-10-16T22:02:54Z</dc:date>
    <item>
      <title>iterating rasters to input into weighted overlay</title>
      <link>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348781#M27364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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)&lt;/P&gt;&lt;P&gt;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)&lt;/P&gt;&lt;P&gt;s0520a&lt;/P&gt;&lt;P&gt;v0520a&lt;/P&gt;&lt;P&gt;o0520a&lt;/P&gt;&lt;P&gt;l0520a&lt;/P&gt;&lt;P&gt;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)&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;Here is what I have so far:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

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:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print r[4:] #code isolated for iterating
&amp;nbsp;&amp;nbsp;&amp;nbsp; if r[1] == "s":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s = inrcras + r
&amp;nbsp;&amp;nbsp;&amp;nbsp; if r[1] == "v":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v = inrcras + r
&amp;nbsp;&amp;nbsp;&amp;nbsp; if r[1] == "o":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o = inrcras + r
&amp;nbsp;&amp;nbsp;&amp;nbsp; if r[1] == "l":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l = inrcras + r
&amp;nbsp;&amp;nbsp;&amp;nbsp; print s, v, o, l
&amp;nbsp;&amp;nbsp;&amp;nbsp; #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

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:24:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348781#M27364</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2021-12-11T16:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: iterating rasters to input into weighted overlay</title>
      <link>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348782#M27365</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;is your indexing off?&amp;nbsp; I think you want to get the 1st character (?), if so it is index 0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; r = 's0520a'&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; r[4:]&lt;/P&gt;&lt;P&gt;'0a'&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; r[1]&lt;/P&gt;&lt;P&gt;'0'&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; r[0]&lt;/P&gt;&lt;P&gt;'s'&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Oct 2014 22:02:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348782#M27365</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-10-16T22:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: iterating rasters to input into weighted overlay</title>
      <link>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348783#M27366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, my rasters are really named&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rsiu0520a&lt;/P&gt;&lt;P&gt;rviu0520a&lt;/P&gt;&lt;P&gt;roiu0520a&lt;/P&gt;&lt;P&gt;rliu0520a &lt;/P&gt;&lt;P&gt;i shortened them to make it easier to understand but didn't think to change the code, my bad&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Oct 2014 00:15:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348783#M27366</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2014-10-17T00:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: iterating rasters to input into weighted overlay</title>
      <link>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348784#M27367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;could you edit or restate your question so that we are now clear what you are asking&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Oct 2014 00:32:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348784#M27367</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-10-17T00:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: iterating rasters to input into weighted overlay</title>
      <link>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348785#M27368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have 4 rasters for each code that need to go in to a wieghted overlay, each wieghted 25%. The code is the last 5 characters of the raster name and the 4 rasters are distinguished by s, v, o and l&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;Code 0520a has 4 rasters&lt;/P&gt;&lt;P&gt;rsiu0520a&lt;/P&gt;&lt;P&gt;rviu0520a&lt;/P&gt;&lt;P&gt;roiu0520a&lt;/P&gt;&lt;P&gt;rliu0520a&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In 1 folder are 75 codes each with 4 rasters so i need to grab the code, then each raster for that code, load them into weighted overlay, save output as code name with a w in the name (w0520a), and move on to the next code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that makes sense&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Oct 2014 02:05:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348785#M27368</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2014-10-17T02:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: iterating rasters to input into weighted overlay</title>
      <link>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348786#M27369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Amy is this the kind of thing you are looking for?&amp;nbsp; I put in a set of fake rasters...I hope your sorting idea works since this is a bit of a cludge approach&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Consolas;"&gt; l: C:\Risk2014\TestReclass\Dliu0Test&lt;BR /&gt; o: C:\Risk2014\TestReclass\Doiu0Test&lt;BR /&gt; v: C:\Risk2014\TestReclass\Dviu0Test&lt;BR /&gt; s: C:\Risk2014\TestReclass\Dsiu0Test&lt;BR /&gt; Weighted: C:\Risk2014\TestWeighted\w0Test&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Consolas;"&gt; l: C:\Risk2014\TestReclass\rliu0520a&lt;BR /&gt; o: C:\Risk2014\TestReclass\roiu0520a&lt;BR /&gt; v: C:\Risk2014\TestReclass\rviu0520a&lt;BR /&gt; s: C:\Risk2014\TestReclass\rsiu0520a&lt;BR /&gt; Weighted: C:\Risk2014\TestWeighted\w0520a&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14135155315145299 jive_text_macro" jivemacro_uid="_14135155315145299"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;arcpy.CheckOutExtension("spatial")&lt;/P&gt;
&lt;P&gt;arcpy.overwriteOutput = True&lt;/P&gt;
&lt;P&gt;reclass_path = "C:\\Risk2014\\TestReclass\\"&lt;/P&gt;
&lt;P&gt;# change to arcpy.ListRasters() I put in a few fake ones&lt;/P&gt;
&lt;P&gt;raster_list = sorted(['rsiu0520a','rviu0520a','roiu0520a','rliu0520a',&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Dsiu0Test','Dviu0Test','Doiu0Test','Dliu0Test'])&lt;/P&gt;
&lt;P&gt;print raster_list&lt;/P&gt;
&lt;P&gt;count = 0&lt;/P&gt;
&lt;P&gt;for raster in raster_list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; code = raster[-5:]&lt;/P&gt;
&lt;P&gt;&amp;nbsp; val = raster[1]&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if val == "l":&amp;nbsp; l = reclass_path + raster&lt;/P&gt;
&lt;P&gt;&amp;nbsp; elif val == "o":&amp;nbsp; o = reclass_path + raster&lt;/P&gt;
&lt;P&gt;&amp;nbsp; elif val == "v":&amp;nbsp; v = reclass_path + raster&lt;/P&gt;
&lt;P&gt;&amp;nbsp; elif val == "s":&amp;nbsp; s = reclass_path + raster&lt;/P&gt;
&lt;P&gt;&amp;nbsp; count += 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if count &amp;gt; 3:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy weighted overlay magicmagic&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_ras ="C:\\Risk2014\\TestWeighted\\w" + code &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("\n l: {0}\n o: {1}\n v: {2}\n s: {3}\n Weighted: {4}".format(l,o,v,s,out_ras))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Oct 2014 03:14:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348786#M27369</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-10-17T03:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: iterating rasters to input into weighted overlay</title>
      <link>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348787#M27370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, That helped a lot (I still need to get the count thing down). I had to change the raster names to iu0520arc so they would sort. I would still like to find a way to select (set) for one code (and not need to sort) for times when a raster for a code might be missing but the only way I know how to do that is with a search cursor in a table and create dictionary's.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("spatial")


arcpy.overwriteOutput = True
reclass_path = "C:\\Risk2014\\TestReclass\\"
arcpy.env.workspace = "C:\\Risk2014\\TestReclass"
raster_list = sorted(arcpy.ListRasters())


#outras = "C:\\Risk2014\\TestWeighted\\w"
#for raster in raster_list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; #front, back = raster[2:], raster[:2]
&amp;nbsp;&amp;nbsp;&amp;nbsp; #print front, back
&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.Rename_management(raster, front + back)
#del raster


count = 0


for raster in raster_list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; code, val =&amp;nbsp; raster[2:7], raster[8]
&amp;nbsp;&amp;nbsp;&amp;nbsp; #print code, val
&amp;nbsp;&amp;nbsp;&amp;nbsp; if val == "s": 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s = reclass_path + raster
&amp;nbsp;&amp;nbsp;&amp;nbsp; if val == "v": 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; v = reclass_path + raster
&amp;nbsp;&amp;nbsp;&amp;nbsp; if val == "o": 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; o = reclass_path + raster
&amp;nbsp;&amp;nbsp;&amp;nbsp; if val == "l": 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; l = reclass_path + raster
&amp;nbsp;&amp;nbsp;&amp;nbsp; count += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; if count &amp;gt; 3:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_ras = "C:\\Risk2014\\TestWeighted\\w" + code
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; remap = RemapValue([[1,1], [2,2], [3,3], [4,4], [5,5], [6,6], [7,7], [8,8], [9,9], ["NODATA","NODATA"]])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mwt = WOTable([[str(s), 25, "VALUE", remap],[str(v), 25, "VALUE", remap],[str(o), 25, "VALUE", remap],[str(l), 25, "VALUE", remap]],[1,9,1])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_overlay = WeightedOverlay(mwt)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_overlay.save(out_ras)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 0
del raster, raster_list


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:24:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348787#M27370</guid>
      <dc:creator>AmyKlug</dc:creator>
      <dc:date>2021-12-11T16:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: iterating rasters to input into weighted overlay</title>
      <link>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348788#M27371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Glad it worked out Amy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Oct 2014 20:42:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/iterating-rasters-to-input-into-weighted-overlay/m-p/348788#M27371</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-10-17T20:42:39Z</dc:date>
    </item>
  </channel>
</rss>

