Skip to main content

Questions tagged [rasterstats]

A Python module for summarizing geospatial raster datasets based on vector geometries

Filter by
Sorted by
Tagged with
0 votes
1 answer
56 views

How to reference many raster layers in the lapp function of {terra} in R

I am attempting to create rasters with estimates of extraterrestrial radiation as outlined by the FAO Irrigation and Drainage paper 56. It only depends on julian day and latitude, and its calculation ...
thiagoveloso's user avatar
2 votes
1 answer
85 views

How to properly perform zonal statistics with overlapping geometries

I am using python 3.9. I have a shapefile with overlapping polygons and a raster dataset. I would like to summarize some statistics on my polygons. However, as I mentioned, my polygons are overlapping....
OgeiD's user avatar
  • 618
0 votes
1 answer
143 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 '...
Samuel T's user avatar
1 vote
1 answer
252 views

weighted mean of the pixels that touch the shape in rasterstats

I am using the rasterstats python package for calculating the zonal statistics of vector geometries with a raster layer like this: stats = zonal_stats('tests/data/polygons.shp', 'tests/data/slope.tif',...
Dinesh Neupane's user avatar
2 votes
1 answer
291 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....
ReutKeller's user avatar
  • 2,169
0 votes
1 answer
317 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 ...
Isa's user avatar
  • 193
0 votes
1 answer
45 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....
Daniele Mosso's user avatar
1 vote
1 answer
205 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 ...
user2031's user avatar
  • 221
1 vote
1 answer
182 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....
Binx's user avatar
  • 1,380
0 votes
1 answer
27 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("...
Koda's user avatar
  • 25
4 votes
1 answer
681 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 ...
emmahaggerty's user avatar
2 votes
1 answer
278 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'...
sarakota's user avatar
1 vote
0 answers
89 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 ...
Hrushi's user avatar
  • 191
1 vote
2 answers
6k 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....
Ryan's user avatar
  • 13
0 votes
1 answer
480 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 ...
Danny's user avatar
  • 35
3 votes
1 answer
294 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&...
debugger4life's user avatar
0 votes
2 answers
523 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 ...
TheRealJimShady's user avatar
0 votes
1 answer
74 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). ...
erchugo's user avatar
3 votes
1 answer
1k 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 ...
nburner's user avatar
  • 61
0 votes
0 answers
311 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 ...
Tú Patern's user avatar
1 vote
1 answer
484 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 ...
Karthik Eswar's user avatar
3 votes
1 answer
2k 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 ...
LostinSpatialAnalysis's user avatar
1 vote
1 answer
877 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 ...
dncardenasg's user avatar
0 votes
1 answer
686 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 ...
Heavy Hammer's user avatar
1 vote
1 answer
63 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.
Sean Jarrett's user avatar
2 votes
0 answers
578 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" ...
GoldenTomato's user avatar
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 ...
Shiraz's user avatar
  • 312
1 vote
0 answers
198 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 = ...
relima's user avatar
  • 2,810
0 votes
1 answer
328 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 ...
GoldenTomato's user avatar
0 votes
0 answers
622 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 ...
eigenvector's user avatar
0 votes
1 answer
163 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 (...
Antonello's user avatar
  • 207
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 ...
grg's user avatar
  • 73
1 vote
1 answer
926 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 ...
emil's user avatar
  • 91
5 votes
1 answer
3k 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 ...
dorakiara's user avatar
  • 403
4 votes
1 answer
391 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 (...
kowalski's user avatar
  • 361
1 vote
0 answers
363 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 ...
Sebastian H's user avatar
0 votes
1 answer
185 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 ...
psavary's user avatar
0 votes
1 answer
198 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 ...
Felix's user avatar
  • 165
2 votes
0 answers
920 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 ...
statBeginner's user avatar
1 vote
1 answer
713 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)...
PPR's user avatar
  • 521
5 votes
1 answer
2k 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....
Aaron's user avatar
  • 51.7k
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 ...
Ana Paola Siri's user avatar
1 vote
0 answers
68 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 ...
Giulio's user avatar
  • 141
3 votes
0 answers
2k 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 ...
topcat's user avatar
  • 327
0 votes
0 answers
28 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 ...
Jessica Archote's user avatar
1 vote
1 answer
47 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 ...
Cracker08's user avatar
3 votes
0 answers
653 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 ...
Vindicare's user avatar
2 votes
0 answers
729 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: ...
Sophie Crommelinck's user avatar
3 votes
0 answers
134 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. ...
tda's user avatar
  • 531
0 votes
1 answer
37 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 ...
dirtdude's user avatar