Select to view content in your preferred language

Replace no data with zeros

15635
8
Jump to solution
02-13-2012 10:53 AM
DiannProsser
Emerging Contributor
Hi all,

I have multiple rasters of varying extents. The data within are binary (0 or 1 values). I want to do a very simple raster calculation where I sum the number of rasters having a "1" in each pixel.

1) I first did a quick calculation on each to set the extent (Map Algebra>Raster Calculator> inraster * 1, while setting the Environment Stettings>Output Coordinates to one that matches my desired extent) - this worked successfully to reset the extent.

2) Next I want to replace No Data with 0's so that I can perform the sum calculation across all pixels within the extent (if No Data exists in the stack of rasters, no calculation is performed). What is the most efficient way of doing this? Is there an entire different approach I should be taking to tackle this problem?

Thanks in advance for your help.
1 Solution

Accepted Solutions
EricRice
Esri Regular Contributor
Greetings,

You can do this by embedding an IsNull statement within a Con statement.

Con(IsNull("raster"),0, "raster")

You may find these resources useful.

Best Regards,
Eric

View solution in original post

0 Kudos
8 Replies
PrasantaBhattarai
Esri Contributor
From the help documentation:
Using the Is Null in conjunction with the Con tool, you can change NoData values on a raster to any desired value while retaining the original non-NoData values for the remaining cells.
---
To change NoData value to 0, you can simply use the raster calculator with following statement:
Con(IsNull(raster), 0, raster).
[ATTACH=CONFIG]11938[/ATTACH]
0 Kudos
EricRice
Esri Regular Contributor
Greetings,

You can do this by embedding an IsNull statement within a Con statement.

Con(IsNull("raster"),0, "raster")

You may find these resources useful.

Best Regards,
Eric
0 Kudos
DiannProsser
Emerging Contributor
Thank you both very much. Success!
The links were helpful also.
0 Kudos
DiannProsser
Emerging Contributor
A follow-up issue:

Eric, related to the link you sent (Raster Extents + Calculator Problems), when I try to set the Environment Settings then Copy Raster, the output does not encompass the entire extent. Can you see where I'm going wrong in my python script? Or should I post this on the Python page? Thank you!

outWorkspace = "D:/GIS_Watf/Output_PrepAnalysis/"
inRaster = "D:/GIS_Watf/Output_wi/d074bhgo_wi"
outRaster = outWorkspace + "e074bhgo"

#extent is xmin ymin xmax ymax
arcpy.env.extent = arcpy.Extent(-2638000, 1870000, 2210000, 5923000)

# Process: Copy Raster
arcpy.CopyRaster_management(inRaster, outRaster, "", "", "", "NONE", "NONE", "")
0 Kudos
EricRice
Esri Regular Contributor
Hi Diann,

How are you confirming the output is not the extent you specified? A visual check perhaps?  Are you increasing the extent of the raster? Have you turned on NoData to display as some color so you can visually see where the extent really ends?

I would also advise you to set a snap raster so all raster pixels align.

Eric
0 Kudos
DiannProsser
Emerging Contributor
Thank you, Eric. Adding the snap raster fixed it... It's still a little confusing to me why setting the extent alone doesn't do it, but at least it works now! Thank you very much, again!!

To answer your questions,
-I was confirming the ouptut by visual inspection - using the identity tool over various parts of my desired extent and could see that nothing was showing up (not even No Data). I could also see from the properties that I didn't have the correct number of cells.
-Yes, I was increasing the extent, not reducing it.
0 Kudos
EricPalm
New Contributor
Hello. 

I am having the same problem that Diann had in the 'Copy Raster' tool.  I am trying to increase the extent of a raster.  I have changed the environment settings to make sure that my output extent is the same as a larger raster (that encompasses my entire study area) and I have also snapped to this same larger raster.  However, the output does not encompass the entire extent, but just remains the same.  I have turned on NoData to display as a color so I can visually see where the extent really ends, and looking at the raster properties of the output file, I still have the same number of rows and columns of the input file.

Is there another step that I might be missing?


Thanks in advance for any help.


Eric
0 Kudos
ludovicofrate
Emerging Contributor
From the help documentation:
Using the Is Null in conjunction with the Con tool, you can change NoData values on a raster to any desired value while retaining the original non-NoData values for the remaining cells.
---
To change NoData value to 0, you can simply use the raster calculator with following statement:
Con(IsNull(raster), 0, raster).
[ATTACH=CONFIG]11938[/ATTACH]


Hi! I've a similar problem. I want to replace in a grid map, all the values over a threshold with a new value. I cant'use reclassify because my grid is a continuous raster! How can I do it? Thanks 🙂
0 Kudos