<?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 arcpy.gp.Con_sa works with multiband raster but not arcpy.sa.Con in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcpy-gp-con-sa-works-with-multiband-raster-but/m-p/811431#M2457</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to run Con on a specific band of a multiband geotif.&amp;nbsp; It works fine when I use arcpy.gp.Con_sa but it does nothing when I use arcpy.sa.Con.&amp;nbsp; And when I say nothing I mean no errors, no results, nothing i.e. it's a NoOp.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Anyway here's my code&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;import arcpy&lt;BR /&gt;from arcpy.sa import *&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# set my workspace to a multiband tif.&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;arcpy.env.workspace = "D:/lf_composite.tif"&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# now run arcpy.gp.Con_sa on one band (DEM) of the tif&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;arcpy.gp.Con_sa("DEM", "400", "d:/test1.tif", "1")&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# Now I have test1.tif with all pixel values of 400 - as expected.&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# Now run arcpy.sa.Con on same band.&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;new_raster = Con("DEM", 400, 1)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;print type(new_raster)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# Also tried this&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;new_raster = Con(arcpy.Raster("DEM"), 400, 1)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;print type(new_raster)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# Con runs with no errors but type of new_raster doesn't print i.e. it doesn't have a type.&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# I expect it to be &amp;lt;type 'Raster'&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I make arcpy.sa.Con work with a mutiband tif?&amp;nbsp; I want to use arcpy.sa.Con because I'll be stringing together muliple cons in sequence and don't want to have to deal with intermediate files that arcpy.gp.Con_sa produces.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for you help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Oct 2020 20:00:52 GMT</pubDate>
    <dc:creator>todddoerr</dc:creator>
    <dc:date>2020-10-29T20:00:52Z</dc:date>
    <item>
      <title>arcpy.gp.Con_sa works with multiband raster but not arcpy.sa.Con</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/arcpy-gp-con-sa-works-with-multiband-raster-but/m-p/811431#M2457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to run Con on a specific band of a multiband geotif.&amp;nbsp; It works fine when I use arcpy.gp.Con_sa but it does nothing when I use arcpy.sa.Con.&amp;nbsp; And when I say nothing I mean no errors, no results, nothing i.e. it's a NoOp.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Anyway here's my code&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;import arcpy&lt;BR /&gt;from arcpy.sa import *&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# set my workspace to a multiband tif.&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;arcpy.env.workspace = "D:/lf_composite.tif"&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# now run arcpy.gp.Con_sa on one band (DEM) of the tif&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;arcpy.gp.Con_sa("DEM", "400", "d:/test1.tif", "1")&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# Now I have test1.tif with all pixel values of 400 - as expected.&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# Now run arcpy.sa.Con on same band.&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;new_raster = Con("DEM", 400, 1)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;print type(new_raster)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# Also tried this&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;new_raster = Con(arcpy.Raster("DEM"), 400, 1)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;print type(new_raster)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# Con runs with no errors but type of new_raster doesn't print i.e. it doesn't have a type.&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;# I expect it to be &amp;lt;type 'Raster'&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I make arcpy.sa.Con work with a mutiband tif?&amp;nbsp; I want to use arcpy.sa.Con because I'll be stringing together muliple cons in sequence and don't want to have to deal with intermediate files that arcpy.gp.Con_sa produces.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for you help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 20:00:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/arcpy-gp-con-sa-works-with-multiband-raster-but/m-p/811431#M2457</guid>
      <dc:creator>todddoerr</dc:creator>
      <dc:date>2020-10-29T20:00:52Z</dc:date>
    </item>
  </channel>
</rss>

