首先,我們來先明確一下本文的具體需求。現有一個儲存有大量.tif
格式遙感影像的資料夾,其中每個遙感影像的檔案名稱中都包含有該影像的成像時間,如下圖所示。
我們希望,對於同一天成像的遙感影像進行拼接——例如,上圖中具有2001
年第185
天成像的遙感影像10
幅,每一幅都是這一天在不同空間位置的成像;同時有2001
年第193
天成像的遙感影像10
振幅。我們希望先將第185
天成像的10
幅遙感影像加以拼接,接著對第193
天成像的10
##。遙感影像加以拼接,以此類推。在遙感影像整體數量較少時,我們或許還可以逐一手動拼接;而當影像數量很多時,就需要藉助程式碼來實現了。
# -*- coding: utf-8 -*- """ Created on Fri Apr 15 13:21:55 2022 @author: fkxxgis """ import os import arcpy tif_file_path="E:/LST/Data/NDVI/02_TIFF/" out_file_path="E:/LST/Data/NDVI/03_Mosaic/" arcpy.env.workspace=tif_file_path tif_file_name=arcpy.ListRasters("*","tif") tif_file_date=tif_file_name[0][1:8] one_day_tif_list=[] tif_file_example_path=tif_file_path+tif_file_name[0] cell_size_x=arcpy.GetRasterProperties_management(tif_file_example_path,"CELLSIZEX") cell_size=cell_size_x.getOutput(0) value_type=arcpy.GetRasterProperties_management(tif_file_example_path,"VALUETYPE") describe=arcpy.Describe(tif_file_example_path) spatial_reference=describe.spatialReference for tif_file in tif_file_name: if tif_file[1:8]==tif_file_date: one_day_tif_list.append(tif_file) tif_file_temp=tif_file if tif_file==tif_file_name[len(tif_file_name)-1]: out_file_name=tif_file[1:8]+".tif" arcpy.CreateRasterDataset_management(out_file_path,out_file_name, cell_size,"16_BIT_SIGNED",spatial_reference,"1") out_file=out_file_path+out_file_name for tif_file_new in one_day_tif_list: arcpy.Mosaic_management([tif_file_path+tif_file_new],out_file) else: out_file_name=tif_file_temp[1:8]+".tif" arcpy.CreateRasterDataset_management(out_file_path,out_file_name, cell_size,"16_BIT_SIGNED",spatial_reference,"1") out_file=out_file_path+out_file_name for tif_file_new in one_day_tif_list: arcpy.Mosaic_management([tif_file_path+tif_file_new],out_file) one_day_tif_list=[] one_day_tif_list.append(tif_file) tif_file_date=tif_file[1:8]
以上是Python ArcPy如何實現批次拼接長時間序列柵格影像的詳細內容。更多資訊請關注PHP中文網其他相關文章!