<?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: Arcpy Condition on Green Band of Raster Dataset - Incorrect Results in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-condition-on-green-band-of-raster-dataset/m-p/1613598#M74171</link>
    <description>&lt;P&gt;Are there brackets missing in the con statemant?&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Con&lt;/SPAN&gt;&lt;SPAN class=""&gt;(((&lt;/SPAN&gt;&lt;SPAN class=""&gt;inRaster1&lt;/SPAN&gt; &lt;SPAN class=""&gt;==&lt;/SPAN&gt; &lt;SPAN class=""&gt;1&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;amp;&lt;/SPAN&gt; &lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;inRaster2&lt;/SPAN&gt; &lt;SPAN class=""&gt;==&lt;/SPAN&gt; &lt;SPAN class=""&gt;5&lt;/SPAN&gt;&lt;SPAN class=""&gt;)),&lt;/SPAN&gt; &lt;SPAN class=""&gt;inRaster1&lt;/SPAN&gt; &lt;SPAN class=""&gt;+&lt;/SPAN&gt; &lt;SPAN class=""&gt;inRaster2&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt; &lt;SPAN class=""&gt;99&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;A href="https://desktop.arcgis.com/de/arcmap/latest/tools/spatial-analyst-toolbox/con-.htm" target="_blank" rel="noopener"&gt;https://desktop.arcgis.com/de/arcmap/latest/tools/spatial-analyst-toolbox/con-.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 12 May 2025 11:45:27 GMT</pubDate>
    <dc:creator>JohannesBierer</dc:creator>
    <dc:date>2025-05-12T11:45:27Z</dc:date>
    <item>
      <title>Arcpy Condition on Green Band of Raster Dataset - Incorrect Results</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-condition-on-green-band-of-raster-dataset/m-p/1611021#M74114</link>
      <description>&lt;P&gt;There is a multi-band raster dataset, IN_RASTER, split into four bands of RGB and an alpha band. A script tool is written to pull out the green band of IN_RASTER, and run Conditional on it to return a raster of 0 for all cells where the input is outside of a given range. A range of values for the green band is given, with Con returning 0 for any values outside of this range:&lt;/P&gt;&lt;P&gt;&lt;FONT face="batang,apple gothic"&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; from arcpy.ia import ExtractBand&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="batang,apple gothic"&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; from arcpy.sa import Con&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="batang,apple gothic"&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; IN_RASTER = "C:/Users/mallard/mallards_input_colour_raster.tif"&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="batang,apple gothic"&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; GREEN_RANGE = [100, 200]&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="batang,apple gothic"&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; green_band = ExtractBand(raster=IN_RASTER, band_names=["green"])&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="batang,apple gothic"&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; s = GREEN_RANGE[0]&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="batang,apple gothic"&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; e = GREEN_RANGE[1]&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="batang,apple gothic"&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; green_filtered = Con((green_band &amp;gt;= s) &amp;amp; (green_band &amp;lt;= e), green_band, 0)&lt;/EM&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="batang,apple gothic"&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; green_filtered.save()&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;The output, green_filtered, is compared to the input raster using ArcGIS Pro. See screenshot, showing the input raster, zoomed in to show four whole cells:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="input_four_cells.png" style="width: 753px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/131342iCF6BABC259731450/image-size/large?v=v2&amp;amp;px=999" role="button" title="input_four_cells.png" alt="input_four_cells.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Identify is run on the top-right cell:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="input_tr_cell_indentify.png" style="width: 890px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/131343iC17459E51BA6E28D/image-size/large?v=v2&amp;amp;px=999" role="button" title="input_tr_cell_indentify.png" alt="input_tr_cell_indentify.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This shows a value of 125 for the green band. This is within the range GREEN_RANGE used in the Con tool. As such, this cell's value of 125 should be returned in the green_filtered output raster. However, inspecting this same cell in the output raster, its value is zero:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="output-raster-tr-cell-identify.png" style="width: 921px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/131344i0AA2E113EA8DA243/image-size/large?v=v2&amp;amp;px=999" role="button" title="output-raster-tr-cell-identify.png" alt="output-raster-tr-cell-identify.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;What is the error in the code or the approach?&lt;/P&gt;</description>
      <pubDate>Fri, 02 May 2025 08:22:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-condition-on-green-band-of-raster-dataset/m-p/1611021#M74114</guid>
      <dc:creator>NickCollis1</dc:creator>
      <dc:date>2025-05-02T08:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Condition on Green Band of Raster Dataset - Incorrect Results</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-condition-on-green-band-of-raster-dataset/m-p/1613598#M74171</link>
      <description>&lt;P&gt;Are there brackets missing in the con statemant?&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Con&lt;/SPAN&gt;&lt;SPAN class=""&gt;(((&lt;/SPAN&gt;&lt;SPAN class=""&gt;inRaster1&lt;/SPAN&gt; &lt;SPAN class=""&gt;==&lt;/SPAN&gt; &lt;SPAN class=""&gt;1&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt; &lt;SPAN class=""&gt;&amp;amp;&lt;/SPAN&gt; &lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;inRaster2&lt;/SPAN&gt; &lt;SPAN class=""&gt;==&lt;/SPAN&gt; &lt;SPAN class=""&gt;5&lt;/SPAN&gt;&lt;SPAN class=""&gt;)),&lt;/SPAN&gt; &lt;SPAN class=""&gt;inRaster1&lt;/SPAN&gt; &lt;SPAN class=""&gt;+&lt;/SPAN&gt; &lt;SPAN class=""&gt;inRaster2&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt; &lt;SPAN class=""&gt;99&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;A href="https://desktop.arcgis.com/de/arcmap/latest/tools/spatial-analyst-toolbox/con-.htm" target="_blank" rel="noopener"&gt;https://desktop.arcgis.com/de/arcmap/latest/tools/spatial-analyst-toolbox/con-.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 May 2025 11:45:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-condition-on-green-band-of-raster-dataset/m-p/1613598#M74171</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2025-05-12T11:45:27Z</dc:date>
    </item>
  </channel>
</rss>

