Friday, 30 September 2016

landsat - Add bands' name and description to the Metadata when stacking using rasterio


I'm using this code, of @Loïc Dutrieux, to stack 8 Landsat bands.


with rasterio.open(final_list[0]) as src0:
meta = src0.meta

with rasterio.open('stack.tif', 'w', **meta) as dst:
for id, layer in enumerate(final_list):
with rasterio.open(layer) as src1:

#the .astype(rasterio.int16) forces dtype to int16

dst.write_band(id + 1, src1.read(1).astype(rasterio.int16))

When I open the stack.tif with gdalinfo I'm not getting bands' description in the Metadata:


...
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
...
Band 1 Block=3596x1 Type=Int16, ColorInterp=Gray
NoData Value=-9999

Band 2 Block=3596x1 Type=Int16, ColorInterp=Undefined
NoData Value=-9999
...

I would like something similar to this:


...
Metadata:
Band_1=Band 1 Reflectance
Band_2=Band 2 Reflectance
Band_3=Band 3 Reflectance

Band_4=Band 4 Reflectance
Band_5=Band 5 Reflectance
Band_6=Band 7 Reflectance
Band_7=Band 6 Temperature
Band_8=Fmask
Image Structure Metadata:
...
Band 1 Block=300x1 Type=Int16, ColorInterp=Undefined
NoData Value=-9999
Band 2 Block=300x1 Type=Int16, ColorInterp=Undefined

NoData Value=-9999
...


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...