13 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='...
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 ...
user avatar
  • 4,836
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. ...
user avatar
  • 985
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 ...
user avatar
  • 9,567
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 ...
user avatar
  • 12.3k
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 ...
user avatar
  • 21.4k
8 votes

Issue Trying to create Zonal Statistics using Gdal and Python.

With multiprocessing, for fastness! Has a little different output-formatting. #!/usr/bin/python import gdal, ogr, osr, numpy, sys from multiprocessing import Pool # Raster dataset input_value_raster ...
user avatar
8 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 ...
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.
user avatar
  • 36.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 ...
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 ...
user avatar
  • 12.3k
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, ...
user avatar
6 votes
Accepted

Overwrite option on a standalone ZonalStatisticsAsTable using ArcPy

Use arcpy.env.overwriteOutput. arcpy.env.overwriteOutput = True # Execute ZonalStatisticsAsTable outZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster, ...
user avatar
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 ...
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, ...
user avatar
  • 36.2k
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 ...
user avatar
  • 440
6 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.
user avatar
  • 6,427
6 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, ...
user avatar
  • 12.3k
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 ...
user avatar
  • 25.8k
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-...
user avatar
  • 50.2k
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 ...
user avatar
  • 51.2k
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....
user avatar
  • 51.2k
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(...
user avatar
  • 51.7k
5 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 ...
user avatar
4 votes
Accepted

Looping qgis:zonalstatistics using PyQGIS?

1) string formatting: It is a not a problem of QGIS or processing but a simple problem of string formatting in Python, look at Python String Format, for example. print "Var_{}".format(3) Var_3 # or ...
user avatar
  • 50.7k
4 votes
Accepted

Getting Zonal Statistics of Overlapping Circles?

Begin with the elevation raster (the DSM). Compute focal minima and maxima using 2m radial neighborhoods, producing two new rasters. Subtract the original raster from these focal rasters. Take the ...
user avatar
  • 67.5k
4 votes
Accepted

How to create graph out of two layers using ArcGIS 10.1 for Desktop?

I would use a zonal statistics analysis to investigate the relationship between crime rate and land price. Use Zonal Statistics as Table (Spatial Analyst) tool with these settings: in_zone_data = ...
user avatar
  • 6,039
4 votes
Accepted

Determining whether raster pixels in or out of zone

Unfortunately, because ArcGIS's source code is not publicaly available, we cannot know for certain how ESRI treats boundary locations when you provide a vector zone layer input. However, as DanC ...
user avatar
  • 10.8k
4 votes

Finding local maxima with variable window search using ArcGIS Desktop?

The Focal Statistics tool in Spatial Analyst can take care of the local maxima. Unfortunately, the size and shape of the neighborhood around the focal cell is fixed for the entire run. Thus, you will ...
user avatar
  • 11.8k
4 votes
Accepted

Monthly weather averages using NCEP/NCAR Reanalysis data

We have one of these files on hand: ## dp is the root to our local data repository f <- file.path(dp, "data", "ftp.cdc.noaa.gov/Datasets/ncep.reanalysis2.derived/pressure/air.mon.mean.nc") ...
user avatar
  • 7,859

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