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, ...
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
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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="...
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. ...
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 ...
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 ...
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 ...
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 ...
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 ...
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(...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
zonal-statistics × 543arcgis-desktop × 165
raster × 143
qgis × 134
spatial-analyst × 100
python × 69
arcpy × 47
arcmap × 41
google-earth-engine × 37
r × 29
statistics × 28
rasterstats × 28
pyqgis × 27
arcgis-10.2 × 23
modelbuilder × 23
polygon × 21
gdal × 18
arcgis-pro × 18
arcgis-10.0 × 15
raster-calculator × 14
spatial-statistics × 14
vector × 13
qgis-3 × 11
arcgis-10.1 × 11
arcgis-10.3 × 11