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 statistic. The raster is one I created using rasterio and pulling data from a NetCDF.
My code looks like this right now:
from rasterstats import zonal_stats
shapefile = "RGdS_AdUnits_for_pop.shp"
rasterfile = "GDD245_2020_tobacco.tif"
stats = zonal_stats(shapefile, rasterfile, all_touched=True)
stats
which returns something like this:
[{'count': 0, 'min': None, 'max': None, 'mean': None},
{'count': 0, 'min': None, 'max': None, 'mean': None},
{'count': 0, 'min': None, 'max': None, 'mean': None},
{'count': 0, 'min': None, 'max': None, 'mean': None},
{'count': 0, 'min': None, 'max': None, 'mean': None},
{'count': 0, 'min': None, 'max': None, 'mean': None},]
I've seen a couple of solutions for questions about the same problem suggest that a mismatching CRS could be the issue but both the shapefile and TIFF here are in EPSG:4326.
I'm not sure if this is an issue with my raster file here but I'm able to open the raster in ArcGIS Pro and run summary stats as table just fine. I'd use that instead but I need the all_touched=True
parameter here since I have some pretty small features. Here's a zipfile of the raster and shapefile I'm using if anyone wants to look:
Data.zip