Last active
January 18, 2019 09:56
-
-
Save mrpgraae/6074a2fea4e50ae79433b260028d6202 to your computer and use it in GitHub Desktop.
Split multi-band raster into 1 file per band
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
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