I'm using the rasterstats zonal_stats function (pip installed), and running it on a .vrt file.

Everything runs perfectly in my Ipython notebook, but when I try to run it in my regular python environment I get the following error:

RasterStatsError: Cannot open '.../africa_merged.vrt' as GDAL raster

The error points to the following lines of the rasterstats source code:

rds = gdal.Open(raster, GA_ReadOnly)
if not rds:
    raise RasterStatsError("Cannot open %r as GDAL raster" % raster)

However I when I run this outside of the rasterstats zonal_stats function, it can open the .vrt file, and doesn't throw an error.

Has anyone else had this problem?

UPDATE: this is happening with regular GeoTiff files as well. So the problem isn't because of the .vrt file type.

Some version info:

Python: sys.version_info(major=2, minor=7, micro=9, releaselevel='final', serial=0)
Osgeo:  osgeo.gdal.VersionInfo(): 1110000 
  • Is the file's directory actually ...? It's likely you just have the incorrect path.
    – perrygeo
    Oct 7, 2015 at 19:53


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.