Question

Raster Zonal Statistics


Badge

Is there a way of doing the same thing as in ArcGIS Raster zonal statistics ? I have a 1 billion cell raster (whose values are comprised between 1 and 5) on which I want to overlay a 3000 polygon layer. I am looking for the number of 1, of 2, of 3 value cells, etc. in each polygon. Coercing my raster to vector (polygon or points) would produce a too big dataset so I am trying to avoid it. Any ideas ?


2 replies

Badge +22

Normally the best way to get statistic from a raster is to coerce to a point cloud and use the PointCloudStatisticsCalculator (like the RasterStatisticsCalculator on the hub does). Unfortunately, unlike the regular statisticsCalculator, the PointCloudStatisticsCalculator does not have the option to generate histograms.

 

 

That leaves two options, use the PointCloudCoercer to turn to vector points (faster than the RasterCellCoercer, but still tedious) or using the Python Raster API.

 

 

Unfortunately I cannot share my python code, but I can say that I used numpy.ma to create a masked array (masked by the NoData Value) and numpy.bincount to get the histogram values.

 

 

To turn that into zonal statistics, clip the raster by the polygon zones (that have a unique ID), create your histogram, featureMerge back onto the zonal polygons by the uniqueID.

Badge +22
Also, vote on this idea https://knowledge.safe.com/content/idea/22245/spatial-statistics-on-raster-data.html

 

and add a comment that you would also like to see a histogram.

 

 

Reply