Created
May 1, 2017 12:36
-
-
Save j08lue/933de87b59effaa0fc2c0188062a7a58 to your computer and use it in GitHub Desktop.
Stack band files with rasterio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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