Files
xian_algorithm_new/tools/check_layer_order.py
T
2026-06-20 15:50:24 +08:00

55 lines
2.2 KiB
Python

"""检查模板中所有图层的渲染顺序(z-order)"""
import zipfile, re, os
TEMPLATE_DIR = r"F:\project\xian\xian_algorithm_new\app\data\template\rainfall"
fname = "暴雨内涝潜在隐患点及人口分布图.qgz"
path = os.path.join(TEMPLATE_DIR, fname)
z = zipfile.ZipFile(path)
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)
print(f"模板: {fname}")
print(f"{'#':>3s} {'图层名':20s} {'类型':10s} {'可见':4s} {'表名'}")
print("-" * 80)
for i, m in enumerate(maplayer_re.finditer(content)):
block = m.group(1)
# 图层名
name_m = re.search(r'<layername>([^<]+)</layername>', block)
name = name_m.group(1) if name_m else '?'
# provider
provider_m = re.search(r'<provider[^>]*>(\w+)</provider>', block)
provider = provider_m.group(1) if provider_m else '?'
# datasource table
ds_m = re.search(r'<datasource>(.*?)</datasource>', block, re.DOTALL)
ds = ds_m.group(1).strip() if ds_m else ''
table_m = re.search(r'table="(\w+)"\."(\w+)"', ds)
table = f"{table_m.group(1)}.{table_m.group(2)}" if table_m else '?'
# 可见性
visible = 'Y' if 'visible="1"' in m.group(0) or 'visible="1"' in block else 'N'
# 判断图层类型
is_static = table in [
'base.rivers', 'base.river', 'base.sx', 'base.sx_capital',
'base.sx_street', 'base.sx_xa_county', 'base.sx_xa_county_boundary',
'base.sx_zb_county_boundary', 'base.sx_zb_city', 'base.sx_zb_county',
'base.active_fault', 'base.traffic_expressway', 'base.traffic_provincial',
'base.traffic_railway', 'base.traffic_township', 'base.traffic_trunk_line',
]
layer_type = "底图" if is_static else "动态"
marker = " <<<" if not is_static and provider == 'postgres' else ""
print(f"{i+1:>3d} {name:20s} {provider:10s} {visible:4s} {table:35s} [{layer_type}]{marker}")
print()
print("提示: 图层按从上到下的顺序渲染(序号小的在底层,序号大的在顶层)")
print("动态图层如果在底图下方,会被底图完全遮盖")