Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly support multiple inputs and outputs #14

Closed
RutgerK opened this issue Dec 13, 2013 · 1 comment
Closed

Directly support multiple inputs and outputs #14

RutgerK opened this issue Dec 13, 2013 · 1 comment

Comments

@RutgerK
Copy link

RutgerK commented Dec 13, 2013

By lack of a mailing-list or anything i'm just going to write an idea here as an issue, i hope that's alright.

The issue (https://github.com/sgillies/rasterio/issues/6) by AsgerPeterson about iterating over the blocks provides a nice example of how to open and write block for block.

Would it be within the scope of RasterIO to extent this to support multiple input and output datasets with a similar interface? It introduces a lot of potential problems like projection differences, performance hits if the blocks aren't the same etc.

A really simple implementation i made a year ago demonstrates this idea, see for example:
http://nbviewer.ipython.org/gist/RutgerK/7941518

My implementation is full of assumptions of the datasets being identical in terms of properties, making it just a very simple wrapper to eliminate the gdal.Open() overhead.

So to modify Asger's example a bit:

with rasterio.open('source1.tif',
                   'source2.tif') as src:

    kwargs = src.meta
    with rasterio.open(('destination1.tif', 'w', **kwargs),
                       ('destination2.tif', 'w', **kwargs),
                       ('destination3.tif', 'w', **kwargs)) as dst:

        for window in src.get_chunks( 1 ):
            data = src.read_band( 1, window)
            dst['destination1'].write_band( 1, data['source1'] + data['source2'], window)
            etc.

In some cases you could achieve a similar effect by combining inputs in a VRT, but this doesn't work for outputs for example.

@sgillies
Copy link
Member

@RutgerK: it's an interesting idea, but I think it complicates rasterio and is better left out of the library. I suspect it would be less code to extend rasterio yourself with a new function that took a list of filenames and made itself into a context manager for all those files, closing them on exit, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants