Zonal statistics as table does not produce correct results

10098
9
02-06-2012 07:56 PM
AnnaUkkola
New Contributor
Hello,

I am trying to produce zonal statistics as table using a polygon shapefile and a raster as input. First I used 'extract by mask' to extract the appropriate cells from a global raster dataset and this works fine as ArcMap extracts all (and only) the cells that have their centre within the polygons. However, when I produce the zonal stats the results are not correct. Too many or too few cells are included in the count and the sum and other statistics are wrong for some (but not all) polygons. Both the shapefile and raster are in the same coordinate system (GCS WGS 1984) and I use the default settings for this tool. Does anyone have any ideas what might be causing this error? Any help appreciated!
0 Kudos
9 Replies
JeffreySwain
Esri Regular Contributor
I am not sure you will need to perform the extract by mask prior to the zonal analysis.  I would also consider if the cell size has changed when you exported the raster, be sure the cell size matches.  If you are concerned that the value is not correct, the quickest test would be to resample the raster to a finer resolution.  Eventhough the values will not change of the raster (just split into smaller cell sizes), performing the zonal statistics on this raster should yield better results if you are concerned that the cell centers are not in the proper zones.  This will make the output from the zonal statistics tool perhaps more to your liking.  

To see the zones that the polygon is surveying, I recommend converting the polygon to a raster and then you will see what the tool is actually surveying.
0 Kudos
EricRice
Esri Regular Contributor
Do you have overlapping polygons?  This usually leads one to unexpected results.

-Eric
0 Kudos
AnnaUkkola
New Contributor
Thanks so much for your replies! I managed to solve the problem simply by converting the shapefile into raster and then calculating zonal stats. I'm still confused about why the polygon shapefile doesn't work (the raster cells picked up by the 'extract by mask' tool are exactly the same in both cases) but at least I now know one way to do it that works! thanks guys 🙂
0 Kudos
AnnaKenyon
New Contributor
I have two datasets, one is thousands of overlapping polygons within unique ID numbers and the other is a raster dataset.  I want to count the number of raster cells that fall within each of the polygons, and I need to keep the unique ID so that I know which polygon the count refers to. Does anyone know how this is done?  I've tried extract by mask but this just gives a list of counts with no reference back to the polygons.  Thanks very much.
0 Kudos
EricRice
Esri Regular Contributor
Hi Anna,

You can do this with Zonal Statistics as Table.  You just need to make a model that uses the Iterate Feature Selection iterator so that each of the overlapping polygons is passed into the zonal tool individually.  You'll get an output table with 1 record for each polygon, then you run Merge to put the rows all back into one table.  Then you join back to the polygons using the Zone Field you specified in Zonal Statistics as Table.  Technically, you need two models.  One that does the iterations on Zonal and collects all the values (the tables), and one that does Merge.  You only want to execute Merge once, so this will be your main model, and the iterating model will be the sub-model.  Please review the section called, "Advanced use of model iterators", within the help topic, Integrating a model within a model.

Best Regards,
Eric
MeganSchofield
New Contributor
As stated in a few responses above, I managed to overcome this through resampling the raster to a finer resolution.

Ctrl-F > Resample > Choose the raster data from which values will be extracted per polygon > change the cell size to a much smaller number (1-5).

Then use the output from the Table of Contents in the Zonal Statistics function as before, and you should have many more of your values/unique identifiers.
0 Kudos
curtvprice
MVP Esteemed Contributor
As stated in a few responses above, I managed to overcome this through resampling the raster to a finer resolution.

Ctrl-F > Resample > Choose the raster data from which values will be extracted per polygon > change the cell size to a much smaller number (1-5).

Then use the output from the Table of Contents in the Zonal Statistics function as before, and you should have many more of your values/unique identifiers.


It's a lot more straightforward to set the appropriate geoprocessing extent, snap and cell size before running Zonal Statistics As Table.  The defaults were probably not sufficient for what you were doing.
0 Kudos
ThomasStanley
New Contributor III
Just started Eric's suggestion. It looks like it will probably work, but it's very, very slow. Is there a better way to do this?

Hi Anna,

You can do this with Zonal Statistics as Table.  You just need to make a model that uses the Iterate Feature Selection iterator so that each of the overlapping polygons is passed into the zonal tool individually.  You'll get an output table with 1 record for each polygon, then you run Merge to put the rows all back into one table.  Then you join back to the polygons using the Zone Field you specified in Zonal Statistics as Table.  Technically, you need two models.  One that does the iterations on Zonal and collects all the values (the tables), and one that does Merge.  You only want to execute Merge once, so this will be your main model, and the iterating model will be the sub-model.  Please review the section called, "Advanced use of model iterators", within the help topic, Integrating a model within a model.

Best Regards,
Eric
0 Kudos
curtvprice
MVP Esteemed Contributor

There is a tool in this toolbox that separates the polygons into non overlapping groups, minimizing the number of iterations required (not brute force one at a time like that). Worth a try I think:

Introducing the Spatial Analyst Supplemental tools | ArcGIS Blog

0 Kudos