Questions tagged [rasterstats]
A Python module for summarizing geospatial raster datasets based on vector geometries
60
questions
0
votes
1
answer
54
views
rasterstats zonal_statistics returns values that aren't present in passed array
I'm truly stumped on why I'm getting incorrect results with zonal_statistics. I'm passing a geometry and the raster in the normal fashion that's worked for me before, with 'data' as the raster and '...
1
vote
1
answer
67
views
weighted mean of the pixels that touch the shape in rasterstats
I am using rasterstats python package for calculating the zonal statistics of a raster and a vectr geometry like this:
stats = zonal_stats('tests/data/polygons.shp', 'tests/data/slope.tif',stats="...
2
votes
1
answer
114
views
Get zonal statistics given polygon from 3-bands raster using Rasterstats
I have a 3-bands raster and a set of 30 polygons. I would like to get the median value of all pixels inside each polygon (zonal statistics). For that I'm using rasterstats package for zonal statistics....
0
votes
1
answer
166
views
Problem with NaN values in a zonal_statistic Python script
I want to create a script to extract zonal statistics from all bands of tif files in a directory using each feature contained in a shapefile.
I use the nodata value of the image to avoid using those ...
0
votes
1
answer
35
views
Calculate solar irradiance inside a geometry trough rasterstats
I am using the rasterstats python module zonal_stats to calculate the mean solar irradiance value (taken from a raster) inside each land particle (contained in a shapefile).
If I run print(irradiance....
1
vote
1
answer
98
views
Calculating raster variance within an area of interest in Python
The zonal statistics tool within QGIS is able to calculate the average raster variance within an area of interest. I am now trying to automate this in Python.
I typically use zonal_stats from the ...
1
vote
1
answer
88
views
rasterstats zonal_stats - return cell position
I've been using the rasterstats zonal_stats method to return the min pixel value (elevation) within a buffered polygon. To return the pixel's position I thought I could used the raster_out=True option....
0
votes
1
answer
22
views
Successfully mosaicking rasters in R, but the analysis is not showing values
I am mosaicking three rasters together. The raster are mosaicking together successfully and will plot but any analysis of the rasters returns NA. Here is the code:
import <- raster("...
4
votes
1
answer
419
views
Rasterstats zonal_stats function on raster returns None values
I am trying to run simple stats on a shapefile using the rasterstats's zonal_stats function. However, when I run the stats, the function only returns "none" for every feature and every ...
2
votes
1
answer
160
views
Add result from for loop rasterstats zonal_stats to gpd shapefile attributes as new columns
I am trying to use a for loop which would produce the zonal statistics of multiple rasters at shapefile points and then add each raster stat to the shapefile.
I've gotten it to add a column, but I don'...
1
vote
0
answers
74
views
Area of zonal statistics more than area of polygon
I have a polygon and a raster (0.5m resolution). The area of polygon is 6249 sq.m (This is obtained from QGIS Identify features option - Ellipsoidal area, Cartesian area is 0.0 sq.deg, please check ...
1
vote
2
answers
4k
views
Computing zonal statistics with Rasterstats in Python
I have a satellite imagery .tif file, and a corresponding .shp file with polygons over buildings. For each band (3 bands total) in the image, I'd like to calculate zonal statistics within each polygon....
0
votes
1
answer
324
views
How to get all unique raster values of intersecting vector in Python?
I have a tif-file containing categorical numerical land cover values and a gdf-file containing roads as linestrings. I'd like to create a new column to the road gdf that contains all unique ...
3
votes
1
answer
222
views
Total pixels with rasterstats
I am using rasterstats to compute zonal statistics within many polygons (provided with a .shp file) for a series of images (.tiff files). A standard statistic computed for each polygon is "count&...
0
votes
2
answers
404
views
How to treat NAs using a custom function in the lapp function of {terra} in R
I am using the {terra} package of R-Stats. I have some quite complicated conditional maths to run on a set of rasters; a different formula depending on the value in the cell. I have tried to make a ...
0
votes
1
answer
52
views
Find the distribution of nlcd categories within polygons
I am new to QGIS. I am trying to find out the distribution of NLCD bins within the buffered areas. The buffered areas is a vector layer, while the other is the NLCD raster (downloaded from MLRC). ...
3
votes
1
answer
933
views
How to solve rasterstats nodata warning
I am using the zonal_stats function in the rasterstats package to calculate summary statistics from GeoTiffs containing vegetative index values. The summary statistics come out fine, however with each ...
0
votes
0
answers
269
views
Rasterstats not working on raster
I am trying to analyze a GeoTiff file with some geojson regions and rasterstats. But rasterstats doesn't seem to work.
I suspect that is something related with the GeoTiff file, since I am using a new ...
1
vote
1
answer
442
views
Find mean zonal stats using a geoseries or GeoJSON object - Python
I have a TIFF file with imperviousness levels and a Geoseries object containing the boundary coordinates of circles around 9 points. I want to find the mean value using zonal_stats but I don't know ...
3
votes
1
answer
1k
views
Unable to perform zonal stats in python because of Attribute Error
I am trying to carry out a simple zonal statistics task in python, and am having trouble getting this to work.
I have a raster layer (in black/grayscale) and a roads polygons layer (in green, actually ...
1
vote
1
answer
754
views
"ValueError: negative dimensions are not allowed" when using raster created from points in CSV
My problem is similar to "ValueError: negative dimensions are not allowed" when using raster created from NetCDF
I am working on a raster that I generated from the interpolation of some ...
0
votes
1
answer
618
views
Error when I try to import rasterstats
I am getting the following error when importing rasterstats package.
I searched the internet and found no solution. Does anyone know what this is about?
The only command I gave was import rasterstats
...
0
votes
1
answer
47
views
QGIS Raster Statistics For Values Intersecting A Line Feature Vector Layer
Using QGIS 3.16.10 I want to obtain statistics for values in a raster layer that intersect with a line feature shapefile. I have tried using v.rast.stats but generate only 0 values.
2
votes
0
answers
519
views
Pixel value extraction with rasterio retrieves different value than QGIS
I am extracting the pixel values from a raster using two different methods:
one is extracting the values to points (centroids of polygon grids)
folder = (...)
S2_green = "band_green.tif"
...
0
votes
1
answer
1k
views
Looping through multiple rasters using Rasterio to calculate mean [closed]
I have a folder with a set of three rasters, before, after, and the difference image for each point of observation as shown below. The before and after dates vary for each observation point and ...
1
vote
0
answers
179
views
NetCDF with negative dimensions
I am trying to read a NetCDF file with rasterio (Python), however, the resulting affine is showing negative numbers.
The .nc4 file comes from NOAA. How can I correct these negative dimensions?
nc_fo = ...
0
votes
1
answer
290
views
How Rasterstats function works
I would like to know how the zonal_stats() function from the library rasterstats works, as I am calculating the mean values of a raster within a polygon. If a raster cell touches partially the polygon ...
0
votes
0
answers
501
views
QGIS Zonal statistics and Python Rasterstats yield different results
I have one polygon shapefile and one raster file (both EPSG: 4326) and I am calculating the minimum, maximum and average raster value in all polygons using two methods:
QGIS 3.16.10, Zonal statistics ...
0
votes
1
answer
147
views
How to select classes from a GeoTIFF world map and compute the area by regions defined in a shapefile
I have two files:
fileLUse.tif defines land cover classes in GeoTiff format (from https://www.esa-landcover-cci.org/?q=node/164)
fileRegions.shp defines administrative borders and it is a shapefile (...
2
votes
1
answer
1k
views
Zonal statistics with rasterstats: "Invalid out_shape, must be 2D" (Python)
I'm trying to produce zonal statistics (summing pixel values representing population estimates by polygons), roughly following GeoDelta Labs (19:20 onwards. A ValueError "Invalid out_shape, must ...
1
vote
1
answer
834
views
Array memory error when reading rasters
I'm attempting to make a spatio-temporal statistics analysis on a few chunks of data using rasterstats, rasterio and pandas/geopandas on Python.
# create dataframes for areas of interest and specify ...
5
votes
1
answer
2k
views
rasterstats zonal statistics does not ignore nodata
I am trying to write a script to perform some zonal statistics with rasterestats, but I am really struggling with nodata values. I noticed a different behaviour 1) when running zonal_stats with numpy ...
4
votes
1
answer
309
views
Calculating zonal entropy index for raster using rasterstats
I have an elevation raster and a grid shapefile:
What I want to do is calculate zonal statistics of the raster based on the grid features. The "statistic" I want is the entropy index (...
1
vote
0
answers
316
views
Width and value problems with rasterstats
I am trying to extract data from a raster with a gpkg file as a vector.
The issue is that, the data can't be extracted because the internal Bounding Box is negative. There I am not sure, whether this ...
0
votes
1
answer
164
views
Creating raster with cell value counts from another raster in buffer around each cell using PostGIS
Main objective
My main objective is to compute 1) the proportion of a given type of land cover around every raster cell in a radius of 500 m at the scale of an island (e.g.: there is 40 % of ...
0
votes
1
answer
185
views
Rasterstats in Python with .IMG files
I am currently trying to use zonal_stats of the rasterstats package to get zonal statistics of processed satellite images.
The data is stored as .img-format and i have a shapefile containing 1 ...
1
vote
0
answers
795
views
Raster Zonal Statistics for large files
I have a shapefile that consists of 375m x 375m cells from the State of California, consisting of a total of 3,022,037 cells. The raster file covers the same geographical area, but consists of smaller ...
1
vote
1
answer
628
views
How to extract max elevation values for each road links in a shapefile using Python libraries?
I want to extract values from a raster DEM file for each feature (polyline) in a shapefile. For each feature in a road shapefile, I want to extract the max and min elevation within a buffer (say 10 ft)...
5
votes
1
answer
1k
views
Which affine format to use in Rasterstats zonal_stats?
I am working with the Rasterstats package to run zonal statistics on two raster datasets. The documentation calls for the following:
import rasterio
from rasterstats import zonal_stats
with rasterio....
2
votes
1
answer
2k
views
Generating zonal stats for multiple rasters using rasterstats
I'm trying to generate the zonal stats for multiple rasters without using ArcPy.
I've successfully obtained results using rasterstats for one image and one polygon. I would like to use the same ...
1
vote
0
answers
64
views
Raster statistic
i'm try to use QGIS processing modeler but I've a problem.
I need to use the Mean value and the standard deviation in raster calculator algorithm. I've calculated it in raster statistics, how can I do ...
2
votes
0
answers
1k
views
Faster zonal stats for equal rasters with Python
I'm trying to extract data out of many raster images with different bounding boxes. Using the great rasterstats.zonal_stats it's a good approach, but it takes a considerable amount of time, especially ...
0
votes
0
answers
27
views
Automate exporting raster XMLs
I edit my raster catalogs to get a specific symbology and then I have to manually export the XML. I then load the XML into the mosaic dataset. I can't seem to find a way to automate the process of ...
1
vote
1
answer
46
views
How do I build a new raster based on raster stats in QGIS?
I want to create a new raster that uses the mean value of the original raster as the base class of the image and then uses a +- 1 and 2 standard deviations as the other four classes of the image. Is ...
3
votes
0
answers
614
views
Memory errors when doing Zonal Statistics on a multi polygon shapefile in Python [closed]
I want to calculate the mean NDVI with the EthNdvi.tif file for each zone (there are around 650 admin zones) in the the woreda shapefile. I'm having some issues with running the following lines of ...
2
votes
0
answers
675
views
How to open memory data with ogr in rasterstats function?
I would like to reuse vector data created in memory in another function called rasterstats (source code, documentation):
I have a function that creates vector data:
def createPolygons:
...
3
votes
0
answers
128
views
On-the-fly zonal statistics in QGIS
I would like to know if there is a plugin/method in QGIS to calculate zonal statistics (mean, median, range, max, min etc.) of a raster file, corresponding to a polygon that I draw/highlight in QGIS.
...
0
votes
1
answer
36
views
Using modeled surfaces together to make predictions?
My question is about stacking multiple rasters of predicted surfaces, that have some of the same predictors.
For example, if I make a predicted surface using all the terrain attributes as ...
6
votes
1
answer
2k
views
Calculating average pixel value for each band across multiple raster layers?
I have a set of raster files that are essentially data sets of precipitation across a region. I have multiple raster files that are the outputs of different climate models. Each pixel in the raster ...
1
vote
1
answer
986
views
Calculating Zonal Stacks on imagery with missing pixels
I'm trying to calculate zonal statistics on some imagery that has a bunch of pixels that come out as 0s. This is affecting the mean value for the area, or at least seems to be.
I'm using the ...