2015-05-29 06:14:49 8 Comments

I'm computing some zonal statistics, and was comparing the results obtained using the GDAL cookbook example code here with the rasterstats zonal_stats function.

I want to compute the mean value per polygon, as well as the number of raster pixels that contributed to that calculation. I *think* rasterstats gives you the number of contributing pixels with their 'count' statistic.

I'm not sure how to get that with the GDAL code, though. I first thought that's what their 'numpoints' variable was counting, but their numpoints corresponds to the number of points within a ring, and I *think* that means the number of vertices of the ring (please correct me if I'm wrong).

Can anyone explain how to compute the number of raster pixels contributing to the GDAL cookbook calculation? Counting the number of pixels of their 'zoneraster' array variable doesn't come close to agreeing with the rasterstats count, either.

### Related Questions

#### Sponsored Content

#### 0 Answered Questions

### R process: Zonal Stat Raster has No Data Values vs Arc output

**2019-02-15 17:38:52****als****47**View**1**Score**0**Answer- Tags: python r zonal-statistics large-datasets rpy2

#### 3 Answered Questions

### [SOLVED] Iterate through multiple Raster files and compute statistics using Zonal Statistics

**2013-11-29 14:30:03****FlyingMGET****6916**View**4**Score**3**Answer- Tags: arcgis-desktop raster statistics zonal-statistics

#### 1 Answered Questions

### [SOLVED] Losing information using Zonal Statistics?

**2018-05-19 13:58:25****JJ_FGIS****67**View**1**Score**1**Answer- Tags: arcgis-desktop spatial-analyst zonal-statistics

#### 0 Answered Questions

### Unexpected results when reclassifying raster using GDAL/numpy

**2018-03-21 19:37:14****David****38**View**1**Score**0**Answer- Tags: python raster gdal numpy reclassify

#### 0 Answered Questions

### Using zonal statistics code from Python GDAL Cookbook?

**2018-02-28 16:33:42****Thibauld Croonenborghs****288**View**2**Score**0**Answer- Tags: python gdal ogr zonal-statistics

#### 1 Answered Questions

### [SOLVED] Missing 0 values of a Rasterlayer prevent correct calculation with Zonal Statistics tool in Qgis

**2018-01-22 15:02:51****Okoto****62**View**3**Score**1**Answer- Tags: qgis statistics zonal-statistics

#### 1 Answered Questions

### [SOLVED] Changing processing extent with each iteration using ArcGIS10 ModelBuilder

**2015-12-01 18:37:14****David****563**View**0**Score**1**Answer- Tags: arcgis-desktop modelbuilder arcgis-10.3 zonal-statistics serious-application-error

#### 1 Answered Questions

### [SOLVED] How to compute zonal statistics fast?

**2016-01-14 15:51:30****RutgerH****449**View**3**Score**1**Answer- Tags: arcpy performance software-recommendations zonal-statistics rasterstats

#### 3 Answered Questions

#### 0 Answered Questions

### Zonal Statistics using Gdal and Python

**2014-02-04 01:52:04****Jason****1245**View**2**Score**0**Answer- Tags: python gdal zonal-statistics

## 0 comments