Some Zonal Statistics (Raster) outputs do not match Zonal statistics table values and are negative?

3669
12
07-20-2017 12:26 PM
KateBallard
New Contributor II

I have a county shapefile that I am using as the "zones" and a raster dataset of landcover types. I extracted each type of landcover, making it so that each one had an individual raster (so water raster, Deciduous forest raster etc). Then I performed the Zonal Statistic as Table tool and summed up the number of pixels of a certain type in each county. It seems to have worked correctly. Now I am trying to use the Zonal Statistics tool to give me an output raster that represents those same SUM values, but it seems that some of the outputs for certain zones are wrong. There are some zones (counties) that match their SUM values in the original Zonal table, and then some that are negative and do not match their value in the table.

For example, when I use the Identify tool and click on the county (zone) #27071 it tells me that the value for the SUM generated by the Zonal Statistics tool was -739109312.0. I checked to see what the Zonal Statistics as TABLE tool assigned as the SUM value for county #27071 and it was 1770032 (completely different). This number should not be negative to begin with, and I checked to make sure the original raster didn't have a value like -999 assigned to it for "No Data" cells, and it did not (it actually had nothing assigned for No Data). In addition, I told the tool to ignore No Data cells. This happened for multiple counties. 

However, some of the counties did match the original Zonal Table SUM values, so it seems like the tool is doing something weird for only some of the zones? 

Does anyone have any idea what could be going on? 

Thank you very much for your help, 

Kate 

12 Replies
XanderBakker
Esri Esteemed Contributor

It think it would be necessary to see the data to be able to investigate what is happening or to try and reproduce the errors. Just wondering... if yo already have the tables with the correct output, why don't you simply join those results to the zones?

KateBallard
New Contributor II

I actually figured this one out, what happened was: on a clip I created of my study area, I believe I let it set the nodata values as 255 (the ArcGIS default). Although for some reason this did not show up under properties when I looked afterwards. When I redid the clip and told it to assign 0 to nodata values, redid the extract by attributes tool creating a new raster for each landcover type (from this new clip), then redid the zonal statistics tool, it came out correctly with no negative values. So, what was happening was, since numbers were assigned for each landcover type (for ex: water =11) the sum was calculated by 11+11+11+11... and so on.   However, with nodata pixels set to 255, cells that were not water were calculated as 255. So the tool was doing 11-255+11-255... By redoing all those steps and changing the nodata pixels to 0 in the original clip, the tool calculated sum by doing 11-0+11-0 .... I still don't know why it only did the 11-255+11-255 thing for some zones and not others, but my fix seems to have worked for all zones. 

Also, to answer your question, I wanted to see if I could make this tool work rather than performing a join with the vector layer because it allows me to show which pixels (that appear split by a county line) were counted in which county zone. Also keeping it in raster rather than vector will become helpful later in my analysis I believe. 

 

HOWEVER, now I am running into a different issue. After I fixed the problem above, I started running the zonal statistics tool on each extracted landcover type raster (so one for the water raster, one for the deciduous forest raster and etc). It worked perfectly on the first 4 landcover types. Then, without changing anything, when I was on the 5th landcover type, the zonal statistics tool crashed and gave me the generic 999999 Error. It also gave me an error that said "no current record", and I am not sure what that means exactly. I am particularly confused because I changed nothing between when it worked and when it crashed. I was just sitting next to the computer taking notes on paper, then each time the tool finished I would just set it up and press go for the next landcover type. 

 

So, to troubleshoot I tried it on a landcover raster that the tool had previously worked on moments before (exact same input raster, zones and everything) and the tool crashed and gave me the same errors. So I am completely confused why the tool worked one moment and crashed the next, even when I tried to re-run it on an input raster that worked less than an hour before. Do you have any idea why this would happen? 

 

Thank you for all your help, I really appreciate it. 

0 Kudos
JamesZack1
New Contributor II

@kate_ballard @xander_bakker

I've seen the same behavior in my integer raster datasets containing values in the range 128 (2^7) through 255 (2^8 - 1), inclusive, using ArcGIS 10.5.1.7333.
 

You can easily reproduce this error by creating a feature class with a simple two vertex line, a constant-value rasterof the same extent with VALUE == 127, and another constant-value raster with VALUE == 128. Run the Zonal Statistics tool to determine the Maximum value for the line using each raster as input. The result for the VALUE == 127 raster is 127. The result for the VALUE == 128 raster is -128. I first became aware when I ran the Zonal Statistics tool against a raster with values 0->139. The output raster had zonal maxima of -117 (256-139). I thought something was fishy. Workarounds might be to add 256 to all negative results, or to convert integer rasters with any values in the range of 128->255, inclusive, to floating point rasters before running Zonal Statistics.

XanderBakker
Esri Esteemed Contributor

Hi James Zack ,

Did you report this to Esri? I would strongly suggest that, since if this is reproducible it is definitely a bug. If I have some time I will see if I can reproduce this with ArcMap 10.5.1 and ArcGIS Pro 2.0.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi James Zack ,

Just did a test with ArcMap 10.5.1 using points, lines, a straight line and a polygon versus a constant raster with value 127 and a constant raster with value 128 and none of the Zonal Statistics as Table contained any negative values. 

Results of straight line (only start and end point)

My advise is contact Esri Support a have them revise what might be the problem in your case. 

0 Kudos
JamesZack1
New Contributor II

Xander Bakker

Thanks for testing out Zonal Statistics as Table. I have always had the "correct" answers from that tool. Could you try Zonal Statistics tool (which outputs a raster with the value of the statistic of choice for each zone) with the StraighLine feature class against ras127 and ras128? I'm curious to see if you can reproduce my results.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Will do...

0 Kudos
XanderBakker
Esri Esteemed Contributor

Nope, no negative values:

and

resulting in:

  

0 Kudos
JamesZack1
New Contributor II

Xander Bakker

Please specify "Maximum" as Statistic Type parameter, not "Sum". I want the output to be an Integer raster.
"Sum" statistic forced the output to be a 32-bit floating point raster. I suspect that the output Integer raster is being cast as a Signed 8-bit grid (values of -127 ->  +128) when it should be cast as an Unsigned 8-bit grid (values of 0 -> +255).

0 Kudos