1.先使用命令行将数据转成tif,并转换经纬度
语句:
gdalwarp -t_srs "EPSG:4326" HDF4_EOS:EOS_GRID:"MCD19A2.A2021215.h10v04.006.2021217045137.hdf"::grid1km:Optical_Depth_055 test.tif
2.然后还没有结束,你就会得到一个有6个波段的tif数据。经过查看发现,这个六个波段合成的结果就是这整个的数据
3.使用python rasterio将数据进行一个融合输出
代码:
import rasterio
import numpy as np
root = r'D:/projects/1210hdf转换/'
hdf_ds = rasterio.open(root + 'test.tif')
data = np.zeros((hdf_ds.height, hdf_ds.width))
band_count = hdf_ds.count
ds_nodata = hdf_ds.nodata
for i in range(1, band_count + 1):
temp_data = hdf_ds.read(i)
temp_data = np.where(temp_data < 0, 0, temp_data)
data += temp_data
data = np.where(data == 0, ds_nodata, data)
new_dataset = rasterio.open(
root + 'result.tif',
'w',
driver='GTiff',
height=data.shape[0],
width=data.shape[1],
count=1,
dtype=data.dtype,
crs='+proj=latlong',
nodata=hdf_ds.nodata,
transform=hdf_ds.transform
)
new_dataset.write(data, 1)
print(data)
4.最终的效果图