<?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 Raster result is different for arcpy.sa CON and arcpy.gp.Con_sa in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/raster-result-is-different-for-arcpy-sa-con-and/m-p/72151#M402</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have to add two rasters, one bigger than the other, but before adding I have to set the value of NODATA of smaller raster to the value of bigger raster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So i used the following code to do it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")

arcpy.env.extent = "MAXOF"
arcpy.env.overwriteOutput = True

smallerRaster = arcpy.Raster(r"C:\Temp\smallraster.asc")
biggerRaster = arcpy.Raster(r"C:\Temp\bigraster.asc")

OutputRaster = Con(IsNull(smallerRaster), biggerRaster, smallerRaster + biggerRaster)

resultRaster = r"C:\Temp\resultRaster"
OutputRaster.save(resultRaster + "_con.tif")
arcpy.RasterToASCII_conversion(resultRaster + "_con.tif", resultRaster + "_con.asc")

arcpy.gp.Con_sa(IsNull(smallerRaster), 0, resultRaster + "_con_sa.tif", smallerRaster + biggerRaster)
arcpy.RasterToASCII_conversion(resultRaster + "_con_sa.tif", resultRaster + "_con_sa.asc")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For Con_sa, smaller raster cell value (those that are NODATA) is assigned to NODATA value (in my sample it is -9999) instead of assign with bigger raster cell value. (I tried with constant value of 0, it still assigned them with NODATA)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to use Con_sa because the script can be executed by more than one instance of application. &lt;/P&gt;&lt;P&gt;While Con result is what I needed, the output temporary result will be stored in "&amp;lt;User Folder&amp;gt;\AppData\Local\ESRI\Desktop10.3\SpatialAnalyst\&amp;lt;RASTER_RESULT&amp;gt;", when the script executed in paralel, the CON will fail due to racing condition in code execution (either throw FATAL error) or (Raster cannot be found).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So is there away to set the NODATA value to constant value when I'm using Con_sa for my scenario above?&lt;/P&gt;&lt;P&gt;I will attach the raster that I used in this example.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 22:47:40 GMT</pubDate>
    <dc:creator>HenriLim</dc:creator>
    <dc:date>2021-12-10T22:47:40Z</dc:date>
    <item>
      <title>Raster result is different for arcpy.sa CON and arcpy.gp.Con_sa</title>
      <link>https://community.esri.com/t5/developers-questions/raster-result-is-different-for-arcpy-sa-con-and/m-p/72151#M402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have to add two rasters, one bigger than the other, but before adding I have to set the value of NODATA of smaller raster to the value of bigger raster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So i used the following code to do it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")

arcpy.env.extent = "MAXOF"
arcpy.env.overwriteOutput = True

smallerRaster = arcpy.Raster(r"C:\Temp\smallraster.asc")
biggerRaster = arcpy.Raster(r"C:\Temp\bigraster.asc")

OutputRaster = Con(IsNull(smallerRaster), biggerRaster, smallerRaster + biggerRaster)

resultRaster = r"C:\Temp\resultRaster"
OutputRaster.save(resultRaster + "_con.tif")
arcpy.RasterToASCII_conversion(resultRaster + "_con.tif", resultRaster + "_con.asc")

arcpy.gp.Con_sa(IsNull(smallerRaster), 0, resultRaster + "_con_sa.tif", smallerRaster + biggerRaster)
arcpy.RasterToASCII_conversion(resultRaster + "_con_sa.tif", resultRaster + "_con_sa.asc")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For Con_sa, smaller raster cell value (those that are NODATA) is assigned to NODATA value (in my sample it is -9999) instead of assign with bigger raster cell value. (I tried with constant value of 0, it still assigned them with NODATA)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to use Con_sa because the script can be executed by more than one instance of application. &lt;/P&gt;&lt;P&gt;While Con result is what I needed, the output temporary result will be stored in "&amp;lt;User Folder&amp;gt;\AppData\Local\ESRI\Desktop10.3\SpatialAnalyst\&amp;lt;RASTER_RESULT&amp;gt;", when the script executed in paralel, the CON will fail due to racing condition in code execution (either throw FATAL error) or (Raster cannot be found).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So is there away to set the NODATA value to constant value when I'm using Con_sa for my scenario above?&lt;/P&gt;&lt;P&gt;I will attach the raster that I used in this example.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:47:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/raster-result-is-different-for-arcpy-sa-con-and/m-p/72151#M402</guid>
      <dc:creator>HenriLim</dc:creator>
      <dc:date>2021-12-10T22:47:40Z</dc:date>
    </item>
  </channel>
</rss>

