55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
![]() |
from osgeo import gdal
|
|||
|
import zipfile
|
|||
|
import os
|
|||
|
from xml.dom.minidom import parseString
|
|||
|
import shutil
|
|||
|
|
|||
|
|
|||
|
# 搜索所有硬盘里所有.zip文件
|
|||
|
def get_all_zipfiles(root):
|
|||
|
zip_lt = []
|
|||
|
for root2, dirs, files in os.walk(root):
|
|||
|
for file in files:
|
|||
|
if file[-4:] == '.zip':
|
|||
|
zip_lt.append(os.path.join(root2, file))
|
|||
|
return zip_lt
|
|||
|
|
|||
|
# 定位并读取.zip文件
|
|||
|
# zip_dir = 'F:/2101-2400/' # 只处理某一个文件夹
|
|||
|
# zip_files_list = os.listdir(zip_dir)
|
|||
|
|
|||
|
|
|||
|
zip_dir = 'F:\\'
|
|||
|
zip_files_list = get_all_zipfiles(zip_dir)
|
|||
|
|
|||
|
# 读取.xml文件
|
|||
|
for file_name in zip_files_list:
|
|||
|
# print(file_name)
|
|||
|
try:
|
|||
|
file = zipfile.ZipFile(file_name, "r")
|
|||
|
except:
|
|||
|
continue
|
|||
|
info_list = file.infolist()
|
|||
|
for info in info_list:
|
|||
|
if info.filename[-4:] == ".xml":
|
|||
|
xml_file = file.read(info.filename)
|
|||
|
|
|||
|
# 解析.xml文件
|
|||
|
domTree = parseString(xml_file)
|
|||
|
rootNode = domTree.documentElement
|
|||
|
infos = rootNode.getElementsByTagName("ProductInfo")[0]
|
|||
|
|
|||
|
# 筛选西北地区影像
|
|||
|
CenterLatitude = eval(infos.getElementsByTagName(
|
|||
|
"CenterLatitude")[0].childNodes[0].data)
|
|||
|
CenterLongitude = eval(infos.getElementsByTagName(
|
|||
|
"CenterLongitude")[0].childNodes[0].data)
|
|||
|
|
|||
|
# 西北地区四个边界信息: 最高纬度:50 ;最低维度:37 ;最高经度:123 ;最低经度:73 ;
|
|||
|
if 37 < CenterLatitude < 44:
|
|||
|
if 76 < CenterLongitude < 78:
|
|||
|
print(file)
|
|||
|
|
|||
|
# 将文件拷贝至新的文件夹中
|
|||
|
shutil.copy(file_name,'E:/wlk_test/')
|