Select to view content in your preferred language

Zonal Statistics as Table - exclude values?

5117
6
Jump to solution
06-27-2013 02:38 PM
IsraelShpindel
Occasional Contributor
Hi,

Is there a way to exclude certain values when running the zonal statistics tool? More specifically, I need to get the sum of the raster cells in each zone, and that works fine, but I also want to calculate the number of the cells that their values are higher than zero (zero in my data is equivalent to "no data"), regardless of their value.
When I run the tool, the output table contains a "Count" column, but it counts all the cells in the zone, including the zeros, so it doesn't give me any valuable information.
I know that theoretically I can use the Raster Calculator and replace the zeros with NoData, but I have dozens of rasters, and I don't want to use this option.

Thanks,
Israel
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus
SetNull  will allow you to specify 0 as your nodata value.  If you have many grids to process consider writing a model/script to process all the rasters in a folder at once.

View solution in original post

0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus
SetNull  will allow you to specify 0 as your nodata value.  If you have many grids to process consider writing a model/script to process all the rasters in a folder at once.
0 Kudos
IsraelShpindel
Occasional Contributor
I'm aware of this option, but I was just wondering if there is any better way. I do work with python, but the problem is that this solution will take a lot of time (the grids are quite large) and I will also have to join the data into one table in the end of the process, which would make it even longer.
Ideally,the best solution would be to somehow "get into" the zonal statistcs tool through python and change its settings, but I guess that can't be done.

Thanks anyway!
0 Kudos
curtvprice
MVP Esteemed Contributor
Ideally,the best solution would be to somehow "get into" the zonal statistcs tool through python and change its settings, but I guess that can't be done.


Israel,

Tool syntax and parameter interfaces are the same in the dialog interface or from ModelBuilder. This is actually a huge strengh of 10.0 over 9.x raster tools.

However, you may want to look into this. Using Python map algebra you can set values to NoData before the tool sees them (no extra raster creation required).

Here's an example:
valras = Raster("value_grid.img")
zonras = Raster("zones.img")
outZSaT = ZonalStatisticsAsTable(zonras, "VALUE", 
    SetNull(valras == 98 or valras == 99, valras)
                                 "stats_tbl", "NODATA", "MEAN")
0 Kudos
IsraelShpindel
Occasional Contributor

However, you may want to look into this. Using Python map algebra you can set values to NoData before the tool sees them (no extra raster creation required).


SetNull doesn't create a new raster? Does it change the original raster permanently?
0 Kudos
curtvprice
MVP Esteemed Contributor
SetNull doesn't create a new raster?


Nested in map algebra it may make a "throw away" temp raster behind the scenes that is deleted when the map algebra expression is processed -- or it may be able to just do it in memory as it is processing. Depends on the combination of operators.

Does it change the original raster permanently?


Nope, the input raster is unmodified.
0 Kudos
IsraelShpindel
Occasional Contributor
Great, that is exactly what I need.
Thank you!
0 Kudos