I'm storing some large rasters in the ASCII grid format. They compress very well, so I'm storing them gzipped. I'd like to just be able to read them directly without unpacking them, but rasterio.open doesn't seem to handle a file handler created using Python's gzip module.
Expected behavior: I should be able to pass a gzip file handler to rasterio.open to read gzipped files directly.
Actual behavior: When I run the script below, I get the following error:
Traceback (most recent call last):
File "code.py", line 6, in <module>
with rasterio.open(gzip_infile) as raster_infile:
File "[path]/env/lib/python3.6/site-packages/rasterio/__init__.py", line 152, in open
raise TypeError("invalid path: {0!r}".format(path))
TypeError: invalid path: <gzip _io.BufferedReader name='sample_ascii_grid.txt.gz' 0x104ef95c0>
Use this sample dataset: sample_ascii_grid.txt.gz
Run this:
import gzip
import rasterio
with gzip.open('sample_ascii_grid.txt.gz') as gzip_infile:
with rasterio.open(gzip_infile) as raster_infile:
raster = raster_infile.read(1)
affine = raster_infile.affine
nodata = raster_infile.nodata
print(raster)
print(affine)
print(nodata)
I'm running macOS 10.12.6.
馃憢 Dear @gfairchild,
Just tried with rasterio 1.0a9 and it worked great!
https://gist.github.com/vincentsarago/8cc9939f19043d38cb9ccfb0b0cb5beb
Please check https://mapbox.github.io/rasterio/topics/migrating-to-v1.html and update your Rasterio version to 1.0a9
pip install rasterio==1.0a9
Hope it help.
@vincentsarago thanks for checking!
@gfairchild I appreciate the complete report. Thank you for filling out the template! We're not fixing any bugs in 0.36, all the work is going on in the 1.0 pre-releases.
I haven't tried using rasterio with gzip files before. Thanks for the new use case.
Oh, wonderful! Thanks for the information. I'll give it a shot.
This did indeed work! Thanks.
thanks for confirming @gfairchild :-)
Most helpful comment
@vincentsarago thanks for checking!
@gfairchild I appreciate the complete report. Thank you for filling out the template! We're not fixing any bugs in 0.36, all the work is going on in the 1.0 pre-releases.
I haven't tried using rasterio with gzip files before. Thanks for the new use case.