Questions tagged [rasterstats]

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

Filter by
Sorted by
Tagged with
1 vote
2 answers
23 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....
  • 13
0 votes
1 answer
40 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 ...
  • 35
0 votes
0 answers
12 views

MATLAB index out of matrix Dimension error when using matlab for raster calculations [duplicate]

I am trying to use Triple Collocation's method to calculate the relative error of 4 sets of satellite products. These 4 sets of satellite products have been sampled to the same resolution and ranks. ...
1 vote
1 answer
82 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
102 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
23 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). ...
2 votes
1 answer
254 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 ...
  • 71
0 votes
0 answers
86 views

Unexpected values for 'SUM' and 'COUNT' in Zonal Statistics

I am using the zonal_stats function in the rasterstats package to evaluate the pixels within each polygon in a shapefile. The raster used is a binary mask layer (object exg) in which pixels ...
  • 71
0 votes
0 answers
128 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
162 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 ...
2 votes
1 answer
398 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
326 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
392 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
25 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
259 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
563 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 ...
  • 162
1 vote
0 answers
79 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 = ...
  • 2,812
0 votes
1 answer
101 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
195 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
50 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 (...
  • 207
2 votes
1 answer
550 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 ...
  • 53
1 vote
1 answer
452 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 ...
  • 81
3 votes
1 answer
1k 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 ...
  • 353
4 votes
1 answer
172 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 (...
  • 343
0 votes
0 answers
161 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
116 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
131 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 ...
  • 157
1 vote
0 answers
542 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
286 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)...
  • 395
4 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....
  • 50.5k
2 votes
1 answer
1k 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
58 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 ...
  • 121
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 ...
  • 318
0 votes
0 answers
24 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
42 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
481 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
514 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
98 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. ...
  • 521
0 votes
1 answer
35 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
918 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 ...
  • 163
3 votes
1 answer
191 views

No data pixels in raster file

I have a TIFF file and I'm trying to use rasterstats to get statistics of different geometries defined in a shapefile or a TopoJSON file. But I'm getting the count as 0 for all the geometries. My ...
5 votes
3 answers
5k views

How to calculate raster statistics for each values in a band?

I have one raster scene that contains one band with multiple pixel values (0-14). Each values represent deforestation in certain year (0=no tree cover loss, 1=loss in 2001, 2=loss in 2002, and so on) ...
1 vote
0 answers
228 views

Qgis not computing raster stats in layer properties - metadata?

I used to check the sum of all values of a raster (to get some volume information) from the layer properties - Metadata - properties tab, where I had directly the figure I was looking for. However, ...
  • 1,851
8 votes
2 answers
663 views

Is there an open-source equivalent of ArcGIS "Zonal Statistics as Table" tool?

With ArcGIS zonal statistics as a table I can easily calculate the mean value from a raster contained within a polygon from a shapefile. I now have a Mac, and therefore I cannot access ArcGIS anymore. ...
1 vote
0 answers
1k views

How to resolve "'NoneType' object is not callable" TypeError when calling rasterstats.zonal_stats from ArcPy script?

I'm attempting to workaround the apparent zonal statistics bug in ArcGIS 10.4 by using rasterstats.zonal_stats. stats = zonal_stats(shapefile_full_path, rast_full_path,0,1,None,None,{'mean','min','...
  • 14.5k
2 votes
1 answer
1k views

Writing geoJson from rasterstats

How would I write a proper geoJson, readable by a GIS, from the results of the rasterstats package? stats = zonal_stats("somePolygons.shp", "someTif.tif", ...
  • 3,135
3 votes
1 answer
551 views

Using zonal_stats with python in QGIS to calculate statistics for each image

I work with Python in QGIS, I want to calculate statistics for each image that I have with a specify shapefile and save result after, I tried to do like this: from rasterstats import zonal_stats ...
  • 91
10 votes
2 answers
4k views

Using GeoPandas with rasterstats for zonal statistic gives error

I'm trying to use GeoPandas and zonal statistic from rasterstats together. I run this code import geopandas as gpd from rasterstats import zonal_stats geodf = gpd.read_file("SHP/shape.shp&...
4 votes
1 answer
998 views

How to compute zonal statistics fast?

I have 12000 circles with a radius of 50 miles on a raster with 0.05 degree resolution. Global analysis. The raster is 32 bit float and I have to calculate zonal statistics for 20 different rasters. ...
  • 2,995