14 votes

Using GeoPandas with rasterstats for zonal statistic gives error

For anyone else that stumbles upon this you can do: To get just one stat: gdf['mean'] = pd.DataFrame( zonal_stats( vectors=gdf['geometry'], raster='raster.tif', stats='...
jwilson8767's user avatar
11 votes
Accepted

COUNT vs. SUM field of zonal statistics as table output table

What you are looking for is COUNT, which is the frequency of the cells that you processed through Zonal Statistics. Sum, on the other hand, is the sum of cell values covered by your polygon. Overly ...
fatih_dur's user avatar
  • 4,933
10 votes
Accepted

Zonal maximum at a specific location

From Esri's support site : HowTo: Create points representing the highest or lowest elevations within polygon features Just replace the elevation raster by the Flow Accumulation raster. ...
Nahas's user avatar
  • 983
10 votes
Accepted

Major bug in ArcGIS Zonal statistics?

There is a bug that seems to correspond to what you're experiencing - it's registered as BUG-000084883 - The 'Ignore NoData in calculations' option in Zonal Statistics as Table tool {and Zonal ...
GISGe's user avatar
  • 9,664
10 votes
Accepted

How does QGIS Zonal Statistics handle partially overlapping pixels?

QGIS first makes an initial pass, checking to see if the center of each raster cell is within the polygon. If fewer than two cell centers are within the polygon, it performs a vector-based ...
dbaston's user avatar
  • 12.9k
9 votes

Major bug in ArcGIS Zonal statistics?

It is a bug. Something terribly wrong with cell count. Correct mean (9.0452380952381) times correct number of non-empty cells (420) divided by 297 (that is a cell count reported by tool) results in ...
FelixIP's user avatar
  • 22.5k
9 votes
Accepted

Calculating statistics per area for categorical raster using R?

In R, you can extract the raster data for each polygon and then summarize it. First, lets create some data (FYI, you can read in a shapefile using raster::shapefile or rgdal::readOGR and a raster ...
Jeffrey Evans's user avatar
8 votes

Using ZonalStats in QGIS 3.0.2

If you wrote zonal in the Processing toolbox search, you will find many: The zonal Statistics is the second one from the top.
ahmadhanb's user avatar
  • 40.2k
7 votes
Accepted

What is (if there's any) difference between MAUP and Edge Effect

The Modifiable Aerial Unit Problem (MAUP) is a change of support issue associated with arbitrary aggregate units. Two classic examples are census tracks and wildlife game units. These have been found ...
Jeffrey Evans's user avatar
7 votes

Robust Zonal stats in R and QGIS

QGIS and R's raster package use different methods to estimate zonal statistics. Briefly: QGIS compares the centroid of each raster cell to the polygon boundary, initially considering cells to be ...
dbaston's user avatar
  • 12.9k
7 votes
Accepted

Getting zonal statistics of polygons not touching center raster cells in PostGIS?

When pixels are large comparing with polygons you better go "vector way". i.e. vectorize the raster tiles and then procede to a vector/vector intersection/computation. If you use the PostGIS Addons, ...
Pierre Racine's user avatar
7 votes
Accepted

"Zonal" Statistics Using Line Features

For calculating stats from raster cells intersected by line, you can use GRASS v.rast.stats directly from QGIS processing toolbox. It can calculate 13 different stats.
Oto Kaláb's user avatar
  • 6,765
7 votes
Accepted

R zonal statistics for classes

You can get the frequency of a single class by passing a custom summary function to exact_extract. For example, to get the fraction of pixels that have a value of 1, you could run: exact_extract(rast, ...
dbaston's user avatar
  • 12.9k
7 votes
Accepted

QGIS zonal statistics only non zero values

Convert raster pixels with value 0 to nodata cells using Raster Calculator. Divide the raster's value by itself: a division by 0 will return nodata. For all other pixels, to keep the value as it is, ...
Babel's user avatar
  • 63.1k
6 votes

Zonal statistics of polygon overlays in PostGIS

1) I'm surprised you do not "cut" the raster with ST_Clip(rast, geom) or ST_Intersection(rast, geom) before computing their stats. What you want are the stats on the pixels values intersecting the ...
Pierre Racine's user avatar
6 votes

Extract raster value into polygon

Before using Zonal Statistics make sure that you have same projections for both raster data and vector (shapefile) data. Sometimes different projection produce empty results. In the following example, ...
ahmadhanb's user avatar
  • 40.2k
6 votes

Zonal Statistics of a polygon and assigning mean value to the polygon

There is a zonal statistics example in the Python GDAL/OGR Cookbook 1.0 documentation. This recipe calculates statistics on values of a raster within the zones of a vector dataset. It returns ...
Aaron's user avatar
  • 51.4k
6 votes
Accepted

Alternatives to Zonal Statistics which include partial pixels (QGIS)

I think you hit on your best option, which is to convert the raster to a vector and then intersect the result with your polygon layer. As a way of explanation regarding the frustration you're ...
rumski20's user avatar
  • 464
6 votes
Accepted

How to use zonal statistics in R with shapefile

As recommended raster::extract will accomplish what you are after. However, from a computational speed and modernization standpoint, I would recommend using the terra package, which is a replacement ...
Jeffrey Evans's user avatar
5 votes
Accepted

How does ArcGIS calculate zonal statistics with multi-band rasters?

With a multi-band raster input, ArcGIS will only process the first band: Multiband raster data When a multiband raster is used as input, most Spatial Analyst tools operate only on the first ...
user2856's user avatar
  • 63.8k
5 votes
Accepted

Too many zones for Zonal Histogram?

If your tif files store integer values you might try tabulate area tool (zones-polygon ids), thus transposing the table. It'll have 4000 rows instead of 4000 columns. If value grids store floating ...
FelixIP's user avatar
  • 22.5k
5 votes
Accepted

Robust Zonal stats in R and QGIS

A Robust Zonal stats in QGIS can be implemented with PyQGIS. Following code was run with your layers by using a filter to select only ID_sub.pat between 19 and 27 (showed in your image). import ...
xunilk's user avatar
  • 29.4k
5 votes

Some zones disappear when running Zonal Statistics as Table in ArcGIS

The Zonal Statistics as Table documentation states the following: If the areas of single features are similar to or smaller than the area of single cells in the value raster, in the feature-to-...
Aaron's user avatar
  • 51.4k
5 votes
Accepted

Zonal stats percentile values using R?

Here are two ways to do this. The raster extract function is the common approach. However, the zonal.stats function uses velox under the hood, which speeds things up considerably. You will not see ...
Jeffrey Evans's user avatar
5 votes
Accepted

QGIS zonal stats for vectors

You can use the 'Join attributes by location (summary)' tool in the processing toolbox. I would recommend using a projected CRS for both layers. You will need a field in your blue polygon layer ...
Ben W's user avatar
  • 20.1k
5 votes
Accepted

Zonal Histogram - Python

rasterstats zonal_stats with categorical=True. For example with pandas so you can manipulate the data as you like: import geopandas as gpd import pandas as pd from rasterstats import zonal_stats lots ...
BERA's user avatar
  • 67k
5 votes
Accepted

Reading values from file Geodatabase table and assigning those values to variable

Use da.SearchCursor(): import arcpy zonetable = r'C:\folder\data.gdb\zonstats' #Change fieldnames = ['field90', 'field75','field50'] #Change PER_90, PER_75, PER_50 = [row for row in arcpy.da....
BERA's user avatar
  • 67k
5 votes
Accepted

Unable to perform zonal stats in python because of Attribute Error

You probably have a null geometry, try filtering them out. import geopandas as gpd import pandas as pd from rasterstats import zonal_stats shp = 'vector.shp' ras = 'raster.tif' gdf = gpd.read_file(...
user2856's user avatar
  • 63.8k
5 votes

Zonal Statistics not executing in arcpy

You still have logical errors in your code. You list the feature classes and do nothing with the data. shapefiles = arcpy.ListFeatureClasses() You initialize an empty list and then try to iterate. ...
Mark Bryant's user avatar
  • 1,417
4 votes

Zonal statistics of polygon overlays in PostGIS

That could be the case of when you imported the Landsat raster to your database, you hopefully set a parameter -t 300x300, which splits the image in tiles of 300x300 pixels. So, imagine that you have ...
Deninhos's user avatar
  • 207

Only top scored, non community-wiki answers of a minimum length are eligible