AnsweredAssumed Answered

Raster result is different for CON and

Question asked by henri_indon on Jun 3, 2016

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.


So i used the following code to do it:


import arcpy
from import *

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" + "_con.tif")
arcpy.RasterToASCII_conversion(resultRaster + "_con.tif", resultRaster + "_con.asc"), 0, resultRaster + "_con_sa.tif", smallerRaster + biggerRaster)
arcpy.RasterToASCII_conversion(resultRaster + "_con_sa.tif", resultRaster + "_con_sa.asc")


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)


I need to use Con_sa because the script can be executed by more than one instance of application.

While Con result is what I needed, the output temporary result will be stored in "<User Folder>\AppData\Local\ESRI\Desktop10.3\SpatialAnalyst\<RASTER_RESULT>", 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).


So is there away to set the NODATA value to constant value when I'm using Con_sa for my scenario above?

I will attach the raster that I used in this example.