我正在研究开源哨兵 2 数据...我使用以下 github 代码生成了 12 个波段的 geotif 文件.. https://colab.research.google.com/drive/14N8rRkQVxH8Et1c1e4vQS1FX9A1qLCsu?usp=sharing
def merge_bands(path):
search = '*B*.tif' # 12 Band files end with B01,B02....
files_batch = glob.glob(os.path.join(path,search)) #search all tif band files
print(files_batch)
print(len(files_batch))
# Read metadata of first file
with rasterio.open(files_batch[0]) as src0: #open first files out of batch of 12 files
meta = src0.meta
# Update meta to reflect the number of layers in merged output geotiff file
meta.update(count = len(files_batch)) #change output meta files as it will have 12 bands rather than 1 as in source files
# Read each layer and write it to stack
with rasterio.open('/content/drive/MyDrive/Big/stack.tif', 'w', **meta) as dst: #output/destination(dst) file opened in write mode with an extra "meta" arbitrary keyword argument
print(dst)
for id, layer in enumerate(files_batch, start=1): # create list of 12 tuples
print(id,layer)
with rasterio.open(layer) as src1:
dst.write_band(id, src1.read(1)) #read 1 band at a time and write it to stack.tif
stacked_data = rasterio.open('/content/drive/MyDrive/Big/stack.tif')
print('Output geotiff number of bands',stacked_data.count)
show(stacked_data)
print(stacked_data.meta)
请建议像 folium 这样的最佳方式将其投影到底图上,例如 openstreetmaps。
谢谢