<?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 How to reclassify multiple raster files based on band values in Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-reclassify-multiple-raster-files-based-on/m-p/130470#M10130</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to reclassify several raster files (having four bands) into 0,1 binary raster files based on raster values of each band. I would like to assign 1 into all pixels in the image that fulfil the following &lt;A href="https://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/raster-calculator.htm"&gt;Raster Calculator&lt;/A&gt; assumption:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333399;"&gt;("_21_cropped.tif - Band_1" == 170) &amp;amp; ("_21_cropped.tif - Band_2" == 255) &amp;amp; ("_21_cropped.tif - Band_3" == 170)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have found that I can do this automatically with ArcPy with &lt;A href="https://support.esri.com/en/technical-article/000022418"&gt;this code&lt;/A&gt;&amp;nbsp;(also attached below).&amp;nbsp;I should add the assumption on the penultimate line here: &amp;lt;desired_value&amp;gt; However I don't know how to implement the assumption mentioned above so that it works.&amp;nbsp;I would be grateful for any tips in this matter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Import the necessary module&lt;BR /&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;from arcpy.sa import *&lt;/P&gt;&lt;P&gt;# Specify the desired workspace&lt;BR /&gt;arcpy.env.workspace = r"L:\processing\forest.gdb"&lt;BR /&gt;arcpy.env.scratchWorkspace = r"L:\processing\forest.gdb"&lt;/P&gt;&lt;P&gt;# Print the list of available raster files in the folder&lt;BR /&gt;raster_list = arcpy.ListRasters("*")&lt;BR /&gt;print (raster_list)&lt;/P&gt;&lt;P&gt;# Check out the Spatial Analyst extension.&lt;BR /&gt;try:&lt;BR /&gt; if arcpy.CheckExtension("Spatial") == "Available":&lt;BR /&gt; arcpy.CheckOutExtension("Spatial")&lt;BR /&gt; print ("Checked out \"Spatial\" Extension")&lt;BR /&gt; else:&lt;BR /&gt; raise LicenseError&lt;BR /&gt;except LicenseError:&lt;BR /&gt; print "Spatial Analyst license is unavailable"&lt;BR /&gt;except:&lt;BR /&gt; print arcpy.GetMessages(2)&lt;/P&gt;&lt;P&gt;# Loop through all the raster files, perform the calculation, and specify the desired save folder.&lt;BR /&gt;for raster in raster_list:&lt;BR /&gt; ras = raster_file(raster)&lt;BR /&gt; outraster = ras * &amp;lt;desired_value&amp;gt; &lt;BR /&gt; outraster.save(r"L:\processing\forest.gdb" + "\\" + raster)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Sep 2020 12:10:33 GMT</pubDate>
    <dc:creator>KK2</dc:creator>
    <dc:date>2020-09-25T12:10:33Z</dc:date>
    <item>
      <title>How to reclassify multiple raster files based on band values in Python</title>
      <link>https://community.esri.com/t5/python-questions/how-to-reclassify-multiple-raster-files-based-on/m-p/130470#M10130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to reclassify several raster files (having four bands) into 0,1 binary raster files based on raster values of each band. I would like to assign 1 into all pixels in the image that fulfil the following &lt;A href="https://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/raster-calculator.htm"&gt;Raster Calculator&lt;/A&gt; assumption:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #333399;"&gt;("_21_cropped.tif - Band_1" == 170) &amp;amp; ("_21_cropped.tif - Band_2" == 255) &amp;amp; ("_21_cropped.tif - Band_3" == 170)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have found that I can do this automatically with ArcPy with &lt;A href="https://support.esri.com/en/technical-article/000022418"&gt;this code&lt;/A&gt;&amp;nbsp;(also attached below).&amp;nbsp;I should add the assumption on the penultimate line here: &amp;lt;desired_value&amp;gt; However I don't know how to implement the assumption mentioned above so that it works.&amp;nbsp;I would be grateful for any tips in this matter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Import the necessary module&lt;BR /&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;from arcpy.sa import *&lt;/P&gt;&lt;P&gt;# Specify the desired workspace&lt;BR /&gt;arcpy.env.workspace = r"L:\processing\forest.gdb"&lt;BR /&gt;arcpy.env.scratchWorkspace = r"L:\processing\forest.gdb"&lt;/P&gt;&lt;P&gt;# Print the list of available raster files in the folder&lt;BR /&gt;raster_list = arcpy.ListRasters("*")&lt;BR /&gt;print (raster_list)&lt;/P&gt;&lt;P&gt;# Check out the Spatial Analyst extension.&lt;BR /&gt;try:&lt;BR /&gt; if arcpy.CheckExtension("Spatial") == "Available":&lt;BR /&gt; arcpy.CheckOutExtension("Spatial")&lt;BR /&gt; print ("Checked out \"Spatial\" Extension")&lt;BR /&gt; else:&lt;BR /&gt; raise LicenseError&lt;BR /&gt;except LicenseError:&lt;BR /&gt; print "Spatial Analyst license is unavailable"&lt;BR /&gt;except:&lt;BR /&gt; print arcpy.GetMessages(2)&lt;/P&gt;&lt;P&gt;# Loop through all the raster files, perform the calculation, and specify the desired save folder.&lt;BR /&gt;for raster in raster_list:&lt;BR /&gt; ras = raster_file(raster)&lt;BR /&gt; outraster = ras * &amp;lt;desired_value&amp;gt; &lt;BR /&gt; outraster.save(r"L:\processing\forest.gdb" + "\\" + raster)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2020 12:10:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-reclassify-multiple-raster-files-based-on/m-p/130470#M10130</guid>
      <dc:creator>KK2</dc:creator>
      <dc:date>2020-09-25T12:10:33Z</dc:date>
    </item>
  </channel>
</rss>

