QGIS提升速度

This commit is contained in:
wzy-warehouse
2026-06-21 13:29:19 +08:00
parent fe3ccd005d
commit 5169ed2f33
28 changed files with 444 additions and 394 deletions
+42
View File
@@ -0,0 +1,42 @@
"""提取模板 .qgs 中所有图层名称、类型、数据源"""
import zipfile, re, os, sys
template_dir = r"F:\project\xian\xian_algorithm_new\app\data\template\rainfall"
for fname in sorted(os.listdir(template_dir)):
if not fname.endswith('.qgz') or fname.startswith('tmp'):
continue
path = os.path.join(template_dir, fname)
z = zipfile.ZipFile(path)
# 找到 .qgs 文件
qgs_name = [n for n in z.namelist() if n.endswith('.qgs')][0]
content = z.read(qgs_name).decode('utf-8')
# 提取 maplayer 块
maplayer_re = re.compile(r'<maplayer[^>]*>(.*?)</maplayer>', re.DOTALL)
layers = []
for m in maplayer_re.finditer(content):
block = m.group(1)
# 图层名
name_m = re.search(r'<layername>([^<]+)</layername>', block)
# provider
provider_m = re.search(r'<provider[^>]*>(\w+)</provider>', block)
# datasource (截取前120字符)
ds_m = re.search(r'<datasource>(.*?)</datasource>', block, re.DOTALL)
name = name_m.group(1) if name_m else '?'
provider = provider_m.group(1) if provider_m else '?'
ds = ds_m.group(1).strip()[:120] if ds_m else '?'
layers.append((name, provider, ds))
print(f"\n{'='*60}")
print(f"模板: {fname}")
print(f"{'='*60}")
for name, provider, ds in layers:
print(f" [{provider:10s}] {name}")
if ds:
print(f" ds: {ds}")
# 只分析第一个模板(所有 rainfall 模板结构相同)
if fname == '暴雨内涝潜在隐患点及人口分布图.qgz':
break