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
  • 67.3k
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,437
4 votes
Accepted

Rasterstats zonal_stats function on raster returns None values

Your raster is georeferenced from 0 to 360 instead of -180 to 180. So zonal_stats thinks your vector data doesn't overlap the raster. You need to warp the raster to -180 to 180 gdalwarp ...
user2856's user avatar
  • 64.9k
3 votes
Accepted

How to calculate the average elevation within a certain radius around a grid cell and apply the average to the grid cell in QGIS?

If I understand the question correctly, here's one approach that should work. Convert the raster to points using Raster pixels to points Buffer the points by 15km using Buffer Calculate zonal ...
Tom Brennan's user avatar
  • 3,860
3 votes

How can I use the Zonal statistics "append to layer" functionality?

I've had the same issue as you exactly - have been struggling with this a lot with 8 new temporary geo packages created in the intermittent steps (I have version 3.32.1). The zonal stats in place ...
IdaG's user avatar
  • 41
3 votes

Writing raster statistics in Python as fast as ArcGIS

Below is my solution using only pandas and numpy based on the suggestion from @FelixIP. The shape of the arrays are (5525, 6563) with 150,000 zones. Runtime is < 2 seconds to calculate 6 stats at ...
Jacob Mardian's user avatar
2 votes

Writing raster statistics in Python as fast as ArcGIS

I'm not sure if it is mandatory for your case that the input zones are in raster format, but I recently did some tests with calculating zonal stats on a polygon layer vs. a raster file. Up to now, the ...
Pieter's user avatar
  • 631
2 votes
Accepted

Zonal statistics based on different categories

We can do this by selecting the building by category and then running join attributes by location (summary) For each cateogory type in the input building layer, we will have a resulting summarized ...
Cushen's user avatar
  • 2,873
2 votes
Accepted

Get zonal statistics given polygon from 3-bands raster using Rasterstats

Found a way to do this, using the "band_num" variable, and running once per bands: stats1=zonal_stats(gdf, url,stats="median",band_num=1) stats2=zonal_stats(gdf, url,stats="...
ReutKeller's user avatar
  • 2,047
2 votes

weighted mean of the pixels that touch the shape in rasterstats

I don't think rasterstats supports partially overlapping polygons (it works with a rasterisation strategy). Most competing zonal statistics tools don't consider partial overlap, or do so very slowly. ...
alphabetasoup's user avatar
2 votes
Accepted

Splitting a single raster layer into multiple layers based on raster values in QGIS

You dont need to split your raster. Zonal Histogram will create a column for each pixel value with the pixel count. Appends fields representing counts of each unique value from a raster layer ...
BERA's user avatar
  • 68.9k
2 votes

How to calculate the average elevation within a certain radius around a grid cell and apply the average to the grid cell in QGIS?

An approach that can be done in a single step - though it requires some initial setup - would be to use the UserDefinedWeightsFilter in Whitebox Tools. You will need to install Whitebox Tools Core, as ...
Tom Brennan's user avatar
  • 3,860
2 votes
Accepted

Calculating raster variance within an area of interest in Python

I figured it out- instead of using rasterstats, you can use rasterio and numpy together to calculate raster variance. Below is the code I ended up using. import numpy as np import rasterio def ...
user2031's user avatar
  • 221
1 vote
Accepted

Create a point that represents the maximum raster value (elevation) within a polygon: Google Earth Engine

Add a latitude and longitude band to the elevation image. Use a max reducer with numInputs=3 so it will find the max elevation but also return the corresponding lat/lon. Map over the results to turn ...
Noel Gorelick's user avatar
1 vote
Accepted

Memory error: unable to allocate using zonal statistics

rasterstats MemoryError issues are typically because of projection differences and in this case there is definitely a projection difference. profile.update(driver='GTiff', crs=wcea_crs) By doing the ...
user2856's user avatar
  • 64.9k
1 vote

Getting the median pixel value for a raster/polygon intersection in PostGIS

For each polygon: Clip the raster Convert the pixels to points Extract the raster values from all points Then calculate mean value per polygon id with percentile_cont: SELECT polyid, PERCENTILE_CONT(...
BERA's user avatar
  • 68.9k
1 vote

QGIS Multiraster Zonal statistics for one vector

One option is to use the batch mode of zonal statistics. To activate it, click on the Run as batch process button at the bottom-left corner of the zonal statistics window. There you can either ...
pan's user avatar
  • 537
1 vote

Calculating the majority value pixel in a polygon and the percentage of this value within the polygon. QGIS

You dont need batch: 1 Zonal statistics to find the majority value for each polygon: 2 Zonal histogram with the zonal statistics as input to count the number of pixels of each raster class, for each ...
BERA's user avatar
  • 68.9k
1 vote

Calculate statistics from croppped WMS in OpenLayers

Currently the only way to access pixel values in bulk is in a layer's postrender event where you could use event.context.getImageData(), or via an ol/source/Raster (which would need threads: 0 to ...
Mike's user avatar
  • 12.3k
1 vote

Can't select vector layer QGIS Zonal Statistics

This means that the list of vectors you have in your "Layers" does not satisfy the geometry type condition. If the algorithm requires polygons and all of your layers are of point and lines ...
GforGIS's user avatar
  • 2,668
1 vote
Accepted

Warning using zonal_stats: RuntimeWarning: overflow encountered in reduce return

The source nodata value (nan in this case) needs to be defined or supplied as an arg to rasterio.mask.mask(), so in addition to masking out the geometry it also masks out the nodata value and doesn't ...
mikewatt's user avatar
  • 4,973
1 vote

Calculating percentage of small grids in coarse grid (fill ratio)

Here's how you can calculate the percent of high resolution cells with some value contained within each low resolution cell. For this example I took an elevation DEM at 1 arcsecond resolution (about ...
Micha's user avatar
  • 15.5k

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