Rasterio: Accept file objects as well as URLs and connection strings in rasterio.open()?

Created on 25 Jan 2017  路  1Comment  路  Source: mapbox/rasterio

See https://github.com/Toblerity/Fiona/issues/409 and https://github.com/mapbox/rasterio/issues/839.

I guess I'm sorta coming around to the idea that rasterio.open() could accept a file-like object and hide the MemoryFile details from users, removing some boilerplate from their programs. I've written a couple of new tests to help this discussion.

Most helpful comment

https://github.com/mapbox/rasterio/commit/f948aeba09e96d0a36eff11a0ac4b29a2b0942a0#diff-d3388b510bd97235e4741b8417cc41e9R123 is what a user must do now:

with MemoryFile(file_object.read()) as memfile:
    with memfile.open() as src:
        # Use the dataset object `src`.

Future usage might be like https://github.com/mapbox/rasterio/commit/f948aeba09e96d0a36eff11a0ac4b29a2b0942a0#diff-d3388b510bd97235e4741b8417cc41e9R135

with rasterio.open(file_object) as src:
    # Use the dataset object `src`.

We can't pass a Python file object to GDAL, so the byes of the file object must be read and then used to initialize a MemoryFile within rasterio.open(). How that MemoryFile would be managed isn't clear to me at the moment.

>All comments

https://github.com/mapbox/rasterio/commit/f948aeba09e96d0a36eff11a0ac4b29a2b0942a0#diff-d3388b510bd97235e4741b8417cc41e9R123 is what a user must do now:

with MemoryFile(file_object.read()) as memfile:
    with memfile.open() as src:
        # Use the dataset object `src`.

Future usage might be like https://github.com/mapbox/rasterio/commit/f948aeba09e96d0a36eff11a0ac4b29a2b0942a0#diff-d3388b510bd97235e4741b8417cc41e9R135

with rasterio.open(file_object) as src:
    # Use the dataset object `src`.

We can't pass a Python file object to GDAL, so the byes of the file object must be read and then used to initialize a MemoryFile within rasterio.open(). How that MemoryFile would be managed isn't clear to me at the moment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sgillies picture sgillies  路  3Comments

vincentsarago picture vincentsarago  路  4Comments

sgillies picture sgillies  路  3Comments

gfairchild picture gfairchild  路  5Comments

valpesendorfer picture valpesendorfer  路  3Comments