网站建设xiduyun,顺德移动端网站建设,wordpress分享有图片,网站怎么做看起来好看Python遥感开发之批量镶嵌 0.ArcGis镶嵌1.Arcpy实现镶嵌1.1 Arcpy实现单个镶嵌1.2 Arcpy实现批量镶嵌 2.GDAL实现镶嵌 前言#xff1a;主要介绍了遥感数据的镶嵌#xff0c;其中包括使用ArcGis如何完成镶嵌#xff0c;如何使用Arcpy和GDAL完成镶嵌。 0.ArcGis镶嵌
是ArcGis… Python遥感开发之批量镶嵌 0.ArcGis镶嵌1.Arcpy实现镶嵌1.1 Arcpy实现单个镶嵌1.2 Arcpy实现批量镶嵌 2.GDAL实现镶嵌 前言主要介绍了遥感数据的镶嵌其中包括使用ArcGis如何完成镶嵌如何使用Arcpy和GDAL完成镶嵌。 0.ArcGis镶嵌
是ArcGis中的非常重要的一个功能具体Arcgis中的使用可以参考以下博客。 《Arcgis使用教程五ARCGIS空间数据处理之影像镶嵌拼接与裁剪_arcgis镶嵌工具在哪里-CSDN博客》
1.Arcpy实现镶嵌
1.1 Arcpy实现单个镶嵌
其中32_BIT_FLOAT表示浮点型16_BIT_UNSIGNED表示整型MAXIMUM表示最大值合成MEAN表示均值合成。
# encoding:utf-8
import os
from arcpy.management import MosaicToNewRasterif __name__ __main__:file unicode(rE:\AAWORK\work\b1\20220816, utf-8)out unicode(rE:\AAWORK\work\202208合成\bb16arcpy, utf-8)os.chdir(file)names os.listdir(file)list1 []for name in names:list1.append(file\\name)print list1# mosaic MosaicToNewRaster(list1, out, 202208_b20.tif, pixel_type32_BIT_FLOAT,number_of_bands1, mosaic_methodMAXIMUM)# mosaic MosaicToNewRaster(list1, out, 20220816_b4.tif, pixel_type16_BIT_UNSIGNED,number_of_bands1, mosaic_methodMAXIMUM)mosaic MosaicToNewRaster(list1, out, 20220816_mean_b1.tif, pixel_type16_BIT_UNSIGNED,number_of_bands1, mosaic_methodMEAN)
1.2 Arcpy实现批量镶嵌
在1.1的基础上增加了一个for遍历实现批量处理
# encoding:utf-8
import os
from arcpy.management import MosaicToNewRasterif __name__ __main__:name_time 202108list_band_name [b1,b2,b3,b4,b6,b7,b19]out rE:\AAWORK\work\{0}合成\bb31mean.format(name_time)out unicode(out, utf-8)for band_name in list_band_name:file rE:\AAWORK\work\{0}\{1}.format(band_name,name_time)file unicode(file, utf-8)os.chdir(file)names os.listdir(file)list1 []for name in names:list1.append(file\\name)file_name {0}_mean_{1}.tif.format(name_time,band_name)mosaic MosaicToNewRaster(list1, out, file_name, pixel_type16_BIT_UNSIGNED,number_of_bands1, mosaic_methodMEAN)# mosaic MosaicToNewRaster(list1, out, file_name, pixel_type32_BIT_FLOAT,number_of_bands1, mosaic_methodMEAN)print file_name2.GDAL实现镶嵌
借助GDAL中的ReprojectImage方法实现镶嵌
import os
from osgeo import gdal
from osgeo import gdalconstdef get_data_list(file_path, out):list1 [] # 文件的完整路径if os.path.isdir(file_path):fileList os.listdir(file_path)if out ! :for f in fileList:out_data out \\ fout_data out_data.replace(.HDF, _ndvi.tif)list1.append(out_data)else:for f in fileList:pre_data file_path \\ f # 文件的完整路径list1.append(pre_data)return list1if __name__ __main__:inputfile_path rE:\AAWORK\work\b19\202208output_tif rE:\AAWORK\work\202208合成\bb16\20220801-16_b19.tifinput_tiffs get_data_list(inputfile_path)# 打开第一个TIFF文件以获取参考信息ref_ds gdal.Open(input_tiffs[0], gdalconst.GA_ReadOnly)driver gdal.GetDriverByName(GTiff)# 创建输出TIFF文件output_ds driver.Create(output_tif, ref_ds.RasterXSize, ref_ds.RasterYSize, 1, gdalconst.GDT_Int32)output_ds.SetProjection(ref_ds.GetProjection())output_ds.SetGeoTransform(ref_ds.GetGeoTransform())# 逐一读取和镶嵌TIFF文件for input_tiff in input_tiffs:input_ds gdal.Open(input_tiff, gdalconst.GA_ReadOnly)band input_ds.GetRasterBand(1)# 镶嵌到输出文件并采用最大值法gdal.ReprojectImage(input_ds, output_ds, None, None, gdalconst.GRA_Max)# 释放内存input_ds None# 关闭输出文件output_ds Noneprint(TIFF文件已镶嵌到 %s采用最大值法。 % output_tif)