<?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: Raster calculator python script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/raster-calculator-python-script/m-p/106939#M8272</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How are the unique values derived fro each raster? Are they a function of the raster itself (like the mean pixel value) or is it just some arbitrary number?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If it's the latter, here's one (untested) possible solution:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;rasterValDict = {"raster1": 11.2, "raster2": 14.9, ..., "raster_37": 9.4}
rasterDirPath = r"C:\temp\where_my_rasters_are"
outputDirPath = r"C:\temp\output_dir"
arcpy.env.workspace = rasterDirPath
rasterList = arcpy.ListRasters()
for raster in rasterList:
&amp;nbsp;&amp;nbsp; rasterObj = arcpy.Raster(raster)
&amp;nbsp;&amp;nbsp; if raster in rasterValDict: 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newRaster = rasterObj / rasterValDict[raster] * 100
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newRaster.save(outputDirPath + "\\" + raster)
&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "ERROR: No matching entry in raster value look up dictionary!"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:29:30 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2021-12-11T06:29:30Z</dc:date>
    <item>
      <title>Raster calculator python script</title>
      <link>https://community.esri.com/t5/python-questions/raster-calculator-python-script/m-p/106938#M8271</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi ArcGIS Users,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good Day!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am processing raster data and would want to use raster calculator to compute values for my rasters. Basically, what I want to do is -- I have a set of raster data in one folder and I want to divide each raster with a unique value. Example is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;( Raster 1 / 9.2 ) * 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;( Raster 2 / 15.2 ) * 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;( Raster 37 / 12.5 ) * 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been searching for an appropriate method on how to do this in python. Could you point me in the right direction (i.e., blog or website) or can somebody from the forum help me how to get started.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance for your help,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Leo&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 May 2014 09:58:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raster-calculator-python-script/m-p/106938#M8271</guid>
      <dc:creator>Leo_KrisPalao</dc:creator>
      <dc:date>2014-05-22T09:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: Raster calculator python script</title>
      <link>https://community.esri.com/t5/python-questions/raster-calculator-python-script/m-p/106939#M8272</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How are the unique values derived fro each raster? Are they a function of the raster itself (like the mean pixel value) or is it just some arbitrary number?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If it's the latter, here's one (untested) possible solution:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;rasterValDict = {"raster1": 11.2, "raster2": 14.9, ..., "raster_37": 9.4}
rasterDirPath = r"C:\temp\where_my_rasters_are"
outputDirPath = r"C:\temp\output_dir"
arcpy.env.workspace = rasterDirPath
rasterList = arcpy.ListRasters()
for raster in rasterList:
&amp;nbsp;&amp;nbsp; rasterObj = arcpy.Raster(raster)
&amp;nbsp;&amp;nbsp; if raster in rasterValDict: 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newRaster = rasterObj / rasterValDict[raster] * 100
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newRaster.save(outputDirPath + "\\" + raster)
&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "ERROR: No matching entry in raster value look up dictionary!"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:29:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raster-calculator-python-script/m-p/106939#M8272</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T06:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: Raster calculator python script</title>
      <link>https://community.esri.com/t5/python-questions/raster-calculator-python-script/m-p/106940#M8273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Chris,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I already ran the code that you shared with me. I tested the code with only five rasters. When I ran the code it says:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; ERROR: No matching entry in raster value look up dictionary!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR: No matching entry in raster value look up dictionary!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR: No matching entry in raster value look up dictionary!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR: No matching entry in raster value look up dictionary!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR: No matching entry in raster value look up dictionary!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I checked each variable in code and it is okay, except for newRaster. When I enter the command &amp;gt;&amp;gt;&amp;gt; print newRaster it says NameError: name 'newRaster' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Below is the code that you gave me. Sorry for this, I am still learning how to write python codes. And it is a steep learning curve for me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Leo&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
rasterValDict = {"raster1": 11.2, "raster2": 14.9, "raster3": 9.4, "raster4": 9.4, "raster5": 9.4}
rasterDirPath = r'E:\Test\Criteria'
outputDirPath = r'E:\Test\rastercalc'
arcpy.env.workspace = rasterDirPath
rasterList = arcpy.ListRasters()
for raster in rasterList:
&amp;nbsp;&amp;nbsp; rasterObj = arcpy.Raster(raster)
&amp;nbsp;&amp;nbsp; if raster in rasterValDict: 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newRaster = rasterObj / rasterValDict[raster] * 100
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newRaster.save(outputDirPath + "\\" + raster)
&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "ERROR: No matching entry in raster value look up dictionary!"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:29:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/raster-calculator-python-script/m-p/106940#M8273</guid>
      <dc:creator>Leo_KrisPalao</dc:creator>
      <dc:date>2021-12-11T06:29:33Z</dc:date>
    </item>
  </channel>
</rss>

