Skip to content

Instantly share code, notes, and snippets.

@mrpgraae
Last active January 18, 2019 09:56
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 mrpgraae/6074a2fea4e50ae79433b260028d6202 to your computer and use it in GitHub Desktop.
Save mrpgraae/6074a2fea4e50ae79433b260028d6202 to your computer and use it in GitHub Desktop.
Split multi-band raster into 1 file per band
import rasterio
IN_RASTER = 'raster_file.tif'
OUT_RASTER = 'raster_file_band{}.tif'
with rasterio.open(IN_RASTER) as src:
profile = src.profile.copy()
img = src.read()
profile['count'] = 1
for i in range(img.shape[0]):
out_file = OUT_RASTER.format(i + 1)
with rasterio.open(out_file, 'w', **profile) as dst:
dst.write(img[i], 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment