<?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: Nested statements with Con Error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/nested-statements-with-con-error/m-p/1051600#M60914</link>
    <description>&lt;P&gt;Are you using the Con tool in arctoolbox or trying it in code? (use the toolbox)&lt;/P&gt;&lt;P&gt;It also looks like you would be probably be better off reclassing the flow direction values that equal (1, 4, 16, 64) to 1 and everything else as 1.41421....)&lt;/P&gt;</description>
    <pubDate>Tue, 27 Apr 2021 01:46:56 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-04-27T01:46:56Z</dc:date>
    <item>
      <title>Nested statements with Con Error</title>
      <link>https://community.esri.com/t5/python-questions/nested-statements-with-con-error/m-p/1051573#M60911</link>
      <description>&lt;P&gt;I'm trying to get this short con statement to work. In the comments was the previous author's code, but that didn't work for me so I changed it, and am getting an error (below). Any help is appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 32, in &amp;lt;module&amp;gt;&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\Functions.py", line 1631, in Con&lt;BR /&gt;where_clause)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\Utils.py", line 53, in swapper&lt;BR /&gt;result = wrapper(*args, **kwargs)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\Functions.py", line 1615, in Wrapper&lt;BR /&gt;["IfThen", in_conditional_raster, in_true_raster_or_constant])&lt;BR /&gt;RuntimeError: The parameter is incorrect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;outcon = Con((Newflowdir ==1,1, Con(Newflowdir == 64,1, Con(Newflowdir ==16,1, Con(Newflowdir ==4,1)))),1.41421356237)
outcon.save(r'E:\NC Lidar NEW 03052021\SARP_NCGS_Data_Share_cms20210305\LiDar\knickpoints\dxraster.tif')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 00:03:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/nested-statements-with-con-error/m-p/1051573#M60911</guid>
      <dc:creator>KathleenHoenke</dc:creator>
      <dc:date>2021-04-27T00:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Nested statements with Con Error</title>
      <link>https://community.esri.com/t5/python-questions/nested-statements-with-con-error/m-p/1051583#M60912</link>
      <description>&lt;P&gt;Quick look&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Newflowdir == A
Con( A == 1, 1, Con(A == 64, 1, Con(A ==16, 1, Con(A == 4, 1.41421356237))))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Too many brackets... Were you just adding them until syntax errors vanished?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 00:53:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/nested-statements-with-con-error/m-p/1051583#M60912</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-27T00:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: Nested statements with Con Error</title>
      <link>https://community.esri.com/t5/python-questions/nested-statements-with-con-error/m-p/1051588#M60913</link>
      <description>&lt;P&gt;Lol maybe I was..... my hangup is that I need the 1.41 to be the false value for all of them. So then when I do this, I get another error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;outcon = Con(Newflowdir ==1,1,1.41421356237, Con(Newflowdir == 64,1,1.41421356237, Con(Newflowdir ==16,1,1.41421356237, Con(Newflowdir ==4,1,1.41421356237))))
outcon.save(r'E:\NC Lidar NEW 03052021\SARP_NCGS_Data_Share_cms20210305\LiDar\knickpoints\dxraster.tif')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\Functions.py", line 1631, in Con&lt;BR /&gt;where_clause)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\Utils.py", line 53, in swapper&lt;BR /&gt;result = wrapper(*args, **kwargs)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\Functions.py", line 1618, in Wrapper&lt;BR /&gt;["IfThenElse", in_conditional_raster, in_true_raster_or_constant, in_false_raster_or_constant])&lt;BR /&gt;RuntimeError: The parameter is incorrect.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 01:06:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/nested-statements-with-con-error/m-p/1051588#M60913</guid>
      <dc:creator>KathleenHoenke</dc:creator>
      <dc:date>2021-04-27T01:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Nested statements with Con Error</title>
      <link>https://community.esri.com/t5/python-questions/nested-statements-with-con-error/m-p/1051600#M60914</link>
      <description>&lt;P&gt;Are you using the Con tool in arctoolbox or trying it in code? (use the toolbox)&lt;/P&gt;&lt;P&gt;It also looks like you would be probably be better off reclassing the flow direction values that equal (1, 4, 16, 64) to 1 and everything else as 1.41421....)&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 01:46:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/nested-statements-with-con-error/m-p/1051600#M60914</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-27T01:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: Nested statements with Con Error</title>
      <link>https://community.esri.com/t5/python-questions/nested-statements-with-con-error/m-p/1051623#M60915</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I&amp;nbsp; can suggest different approach to your question, but firstly, one error is comming from that you are trying to assign float (1.43...) and your raster might accept only integer...&lt;/P&gt;&lt;P&gt;as, your con expresion is quite complex, how about using &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/analysis/spatial-analyst/raster-cell-iterator/a-quick-tour-of-using-the-raster-cell-iterator.htm" target="_self"&gt;'raster-cell-iterator'&lt;/A&gt;&amp;nbsp; and &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/rasterinfo-class.htm" target="_self"&gt;raster_info.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;For example sth like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcpy.sa import *

myRas = Raster(r"C:\Temp\flow_direction_raster")
#get raster information
rasInfo = myRas.getRasterInfo()
#get pixel type
print(rasInfo.getPixelType())

#in rasinfo object change one parameter - pixel type
rasInfo.setPixelType("F32")
# now create new, empty raster, but with defined extent, pixel type...
new_raster = Raster(rasInfo)

#run calculation to update values to new raster
with RasterCellIterator({'rasters':[myRas, new_raster]}) as rci:
    for i,j in rci:
        if myRas[i,j] in [1, 64, 16, 4]:
            new_raster[i,j] = 1
        else:
            new_raster[i,j] = 1.41421356237

# save new raster to your disk
new_raster.save(r'C:\Temp\test')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 00:06:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/nested-statements-with-con-error/m-p/1051623#M60915</guid>
      <dc:creator>Tomasz_Tarchalski</dc:creator>
      <dc:date>2021-05-04T00:06:05Z</dc:date>
    </item>
  </channel>
</rss>

