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='...
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 ...
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.
...
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 ...
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 ...
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 ...
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 ...
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.
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 ...
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 ...
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, ...
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.
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, ...
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, ...
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 ...
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, ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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-...
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 ...
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 ...
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 ...
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....
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(...
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. ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
zonal-statistics × 535arcgis-desktop × 165
raster × 142
qgis × 130
spatial-analyst × 99
python × 69
arcpy × 47
arcmap × 40
google-earth-engine × 35
pyqgis × 28
r × 28
rasterstats × 27
statistics × 26
arcgis-10.2 × 23
modelbuilder × 23
polygon × 20
gdal × 18
arcgis-pro × 18
arcgis-10.0 × 15
vector × 13
raster-calculator × 13
spatial-statistics × 13
qgis-3 × 11
arcgis-10.1 × 11
arcgis-10.3 × 11