Skip to content

Instantly share code, notes, and snippets.

@j08lue
Created May 1, 2017 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j08lue/933de87b59effaa0fc2c0188062a7a58 to your computer and use it in GitHub Desktop.
Save j08lue/933de87b59effaa0fc2c0188062a7a58 to your computer and use it in GitHub Desktop.
Stack band files with rasterio
def stack_band_files(infiles, outfile, creation_options={}):
"""Stack single-band files into one
Parameters
----------
infiles : list of str
paths to input files
outfile : str
path to output file
creation_options : dict
destination file creation options
"""
with rasterio.open(infiles[0]) as src:
profile = src.profile.copy()
profile.update(count=len(infiles))
profile.update(creation_options)
with rasterio.open(outfile, 'w', **profile) as dst:
for i, infile in enumerate(infiles):
dst.write_band(i+1, rasterio.band(src, 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment