Python批量解压zip文件并利用arcpy进行栅格批量拼接操作

前言:在“NASADEM-中国”文件夹中有很多子文件夹:

 而在这些子文件夹中又有很多zip压缩文件:

 现在先想要把这些压缩文件解压到一个文件夹“ALL”中:

import os
import shutil
import zipfile

parent_path=r'G:DEMNASADEM-中国' #父文件夹路径
directory_to_extract_to=r"G:DEMALL" #解压目标文件夹路径
for root, dirs, files in os.walk(parent_path):
      # 读取文件名
    for name in files:
        print(name)
        path_to_zip_file=root+'\'+name
        print(path_to_zip_file)
        with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref:
            zip_ref.extractall(directory_to_extract_to)

等待其运行完。

接下来可以再ArcGIS中进行DEM的拼接操作:

 参考:https://blog.csdn.net/gisboygogogo/article/details/75195760

###批量拼接tiff的DEM ------------------------------    
import arcpy
from arcpy import env
from arcpy.sa import *
import sys 
reload(sys)                      # reload 才能调用 setdefaultencoding 方法  
sys.setdefaultencoding('utf-8')  # 设置 'utf-8' 
arcpy.CheckOutExtension('Spatial')
arcpy.env.workspace = "G:/DEM/NASADEM-中国/ALL"

#提取待拼接影像的文件名,且中间以;隔开,例如:a.tif;b.tif;c.tif
rasters = []
for ras in arcpy.ListRasters("*.hgt"):
    print(ras)
    rasters.append(ras) 
ras_list = ";".join(rasters) 
print(ras_list)

base = "n18e108.hgt"
#以下一段代码是为执行拼接做参数准备
out_coor_system = arcpy.Describe(base).spatialReference #获取坐标系统
dataType = arcpy.Describe(base).DataType 
piexl_type = arcpy.Describe(base).pixelType 
cellwidth = arcpy.Describe(base).meanCellWidth #获取栅格单元的的宽度
bandcount = arcpy.Describe(base).bandCount #获取bandCount
#输出与拼接
outFolder = r"G:DEMNASADEM-中国"
arcpy.MosaicToNewRaster_management(ras_list,outFolder,"China__dem_data.tif", out_coor_system, "16_BIT_SIGNED", cellwidth, bandcount, "LAST", "FIRST")

对应的ArcGIS中使用工具为:

可惜由于数据量实在过大,最后拼接出来的一张影像可能有十几个G大小,在ArcGIS中也不怎么打得开,综合考虑到处理大数据量的时候也是分块处理,因此针对所要研究的对象进行分开式处理,进行掩膜提取之类

例如,先拼接N38-N58的数据,再进行掩膜提取

原文地址:https://www.cnblogs.com/icydengyw/p/13765324.html