>>> import os
>>> import arcpy
... root_dir = "C:\\Users\\HP\\Desktop\\data\\"
... output_dir_tif = "C:\\Users\\HP\\Desktop\\tif\\"
... output_dir_mosaic = "C:\\Users\\HP\\Desktop\\mosaic\\"
... output_dir_repro = "C:\\Users\\HP\\Desktop\\repro\\"
... #格式转换
>>> def ConvertFormat(file,output):
... LST_Day = arcpy.ExtractSubDataset_management(file, output,"LST_Day_1km") #LST_Day_1km是子数据集名称
>>> # 投影变化
... def RePro(inputdata,outputdata):
... outputdata = output_dir_repro+"\\"+str(month)+"\\"+outputdata
... # 输出投影坐标系
... out_coor_system = r"C:\Users\HP\Desktop\Coord\WGS 1984 World Mercator.prj"
... # 输入地理坐标系
... in_coor_system = r"C:\Users\HP\Desktop\Coord\Unknown_datum_based_upon_the_custom_spheroid_Sinusoidal.prj"
... # 输出栅格路径
... print(outputdata+"has finished")
... arcpy.ProjectRaster_management(inputdata, outputdata, out_coor_system, "NEAREST", "1000", "#", "#", in_coor_system)
...
>>> #镶嵌栅格
... def mosaic(inputpath,outputpath,outputname):
... Raster_list_1 = os.listdir(inputpath)
... Raster_list = []
... for raster in Raster_list_1:
... if str(raster).split(".")[-1]=="tif":
... Raster_list.append(raster)
... now_mosaic = arcpy.MosaicToNewRaster_management(Raster_list,outputpath,outputname,"","","","1","","")
... RePro(now_mosaic,outputname)
...
>>> #遍历文件
... month_list = os.listdir(root_dir)
... for month in month_list:
... os.makedirs(output_dir_tif+str(month))
... os.makedirs(output_dir_mosaic+str(month))
... os.makedirs(output_dir_repro+str(month))
... date_list = os.listdir(root_dir+str(month)+"\\")
... for date in date_list:
... datepath = output_dir_tif+str(month)+"\\"+str(date)
... os.makedirs(datepath)
... hdfs = os.listdir(root_dir+str(month)+"\\"+str(date)+"\\")
... for hdf in hdfs:
... now_hdf = root_dir+str(month)+"\\"+str(date)+"\\"+str(hdf)
... splited = str(hdf).split(".")
... output_tiff = output_dir_tif+str(month)+"\\"+str(date)+"\\"+splited[0]+"_"+splited[1]+"_"+splited[2]+"_"+splited[3]+"_"+splited[4]+".tif"
... ConvertFormat(now_hdf,output_tiff)
... outputpath = output_dir_mosaic+str(month)
... mosaic(datepath,outputpath,str(date)+".tif")
...
C:\Users\HP\Desktop\repro\\二月\2.18.tifhas finished
>>>
代码训练—python实现hdf文件mrt批处理
最新推荐文章于 2024-05-01 22:06:13 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)