I am currently working with two rasters in ArcGIS Pro: a masked raster (cloud_masked) where clouds and shadows have been removed, resulting in NoData values (holes), and an unmasked stacking raster (original_stack). Both rasters have the same size and resolution. I want to fill the NoData values in the cloud_masked raster with the corresponding values from the original_stack raster.
Here is what I have tried so far: Using Raster Calculator with the Con Function
Con(IsNull("cloud_masked"), "original_stack", "cloud_masked")
When I used this method, the resulting raster turned out black instead of filling the NoData values correctly.
import arcpy from arcpy.sa import *
arcpy.env.workspace = "C:/path_to_workspace"
arcpy.env.overwriteOutput = True
cloud_masked_path = "C:/path_to_workspace/cloud_masked.tif"
original_stack_path = "C:/path_to_workspace/original_stack.tif"
output_raster_path = "C:/path_to_workspace/filled_cloud_masked.tif"
cloud_masked_raster = Raster(cloud_masked_path)
original_stack_raster = Raster(original_stack_path)
filled_raster = Con(IsNull(cloud_masked_raster), original_stack_raster, cloud_masked_raster)
filled_raster.save(output_raster_path)
print(f"Filled raster saved to {output_raster_path}")
Things I have checked:
- The NoData value settings for cloud_masked
- Ensuring both rasters have matching data types
How can I properly fill the NoData values without the resulting raster turning black?
Additionally, is there a better approach to handle the NoData values correctly?
original_STACK.tif
suggests to me that this a multi-band raster, i.e. a stack of bands. Not sure if CON() applies your logic to each band within the raster stack, you will need to check that. My experience with CON() is typically on a 1-band raster such as a DEM."original_stack.tif
has multiple bands, you need to apply theCon(IsNull())
functions to each band separately and then composite the output bands.