<?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 Simple Map Algebra Looped Through Rasters in a Directory in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/simple-map-algebra-looped-through-rasters-in-a/m-p/344697#M27027</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think I must be missing something pretty basic here because this isn't a complex operation. That said, I've always had difficulty with Map Algebra in scripts. I'd like to apply a constant multiplier to all of the rasters in a directory. They are in . tif format. When I run the separately in Python I get this error:&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="color:#ff0000;"&gt;Traceback (most recent call last):&lt;BR /&gt;&amp;nbsp; File "C:\Users\Derek\Desktop\multiply rasters.py", line 15, in &amp;lt;module&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for raster_image in raster_list:&lt;BR /&gt;TypeError: 'NoneType' object is not iterable&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;&lt;BR /&gt;When I run in it piecemeal in the Python window I get this error:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color:#ff0000;"&gt;Runtime error &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color:#ff0000;"&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color:#ff0000;"&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color:#ff0000;"&gt;TypeError: can't multiply sequence by non-int of type 'float'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't think that the raster is being recognized as an input during the multiplication. I also don't know what else to try. Here is the code: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy,os,sys,string&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy.sa import *&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CheckOutExtension("Spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;input_folder = r'C:\Users\Derek\Desktop\ToJordan\ToJordan\landsat'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.worspace = input_folder&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Set reflectance constant&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;const = 0.0001&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get raster list, loop through and multiply be constant&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;raster_list = arcpy.ListRasters()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for raster_image in raster_list:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print raster_image&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rast_mult = Raster(raster_image) * const &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raster_mult_out = input_folder + os.sep + raster_image + "_reflect.img"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rast_mult.save(raster_mult_out)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print raster_image + " Finished"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope someone can help.&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 17 Feb 2013 12:12:20 GMT</pubDate>
    <dc:creator>DerekAzar</dc:creator>
    <dc:date>2013-02-17T12:12:20Z</dc:date>
    <item>
      <title>Simple Map Algebra Looped Through Rasters in a Directory</title>
      <link>https://community.esri.com/t5/python-questions/simple-map-algebra-looped-through-rasters-in-a/m-p/344697#M27027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think I must be missing something pretty basic here because this isn't a complex operation. That said, I've always had difficulty with Map Algebra in scripts. I'd like to apply a constant multiplier to all of the rasters in a directory. They are in . tif format. When I run the separately in Python I get this error:&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="color:#ff0000;"&gt;Traceback (most recent call last):&lt;BR /&gt;&amp;nbsp; File "C:\Users\Derek\Desktop\multiply rasters.py", line 15, in &amp;lt;module&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for raster_image in raster_list:&lt;BR /&gt;TypeError: 'NoneType' object is not iterable&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color:#000000;"&gt;&lt;BR /&gt;When I run in it piecemeal in the Python window I get this error:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color:#ff0000;"&gt;Runtime error &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color:#ff0000;"&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color:#ff0000;"&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color:#ff0000;"&gt;TypeError: can't multiply sequence by non-int of type 'float'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't think that the raster is being recognized as an input during the multiplication. I also don't know what else to try. Here is the code: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy,os,sys,string&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy.sa import *&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CheckOutExtension("Spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;input_folder = r'C:\Users\Derek\Desktop\ToJordan\ToJordan\landsat'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.worspace = input_folder&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Set reflectance constant&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;const = 0.0001&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Get raster list, loop through and multiply be constant&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;raster_list = arcpy.ListRasters()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for raster_image in raster_list:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print raster_image&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rast_mult = Raster(raster_image) * const &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raster_mult_out = input_folder + os.sep + raster_image + "_reflect.img"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rast_mult.save(raster_mult_out)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print raster_image + " Finished"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope someone can help.&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Feb 2013 12:12:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-map-algebra-looped-through-rasters-in-a/m-p/344697#M27027</guid>
      <dc:creator>DerekAzar</dc:creator>
      <dc:date>2013-02-17T12:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Map Algebra Looped Through Rasters in a Directory</title>
      <link>https://community.esri.com/t5/python-questions/simple-map-algebra-looped-through-rasters-in-a/m-p/344698#M27028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hehe sneaky little error.&amp;nbsp; you've probably caught it by now, but ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.worspace = input_folder&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;should be &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = input_folder&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This means that when your script ran, arcpy.env.workspace was actually just the default value (empty string)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When you run ListRasters with the workspace set to empty string it returns None.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Meaning raster_list == None&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then you tried to iterate on None. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is a really good example of why debuggers are essential.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Mar 2013 01:35:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-map-algebra-looped-through-rasters-in-a/m-p/344698#M27028</guid>
      <dc:creator>LT</dc:creator>
      <dc:date>2013-03-09T01:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Simple Map Algebra Looped Through Rasters in a Directory</title>
      <link>https://community.esri.com/t5/python-questions/simple-map-algebra-looped-through-rasters-in-a/m-p/344699#M27029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I did catch that soon after I posted, thanks though!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 16:56:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-map-algebra-looped-through-rasters-in-a/m-p/344699#M27029</guid>
      <dc:creator>DerekAzar</dc:creator>
      <dc:date>2013-09-12T16:56:42Z</dc:date>
    </item>
  </channel>
</rss>

