Files
xian_algorithm_new/app/config/qgis_mappings.py
T
2026-06-20 15:50:24 +08:00

109 lines
4.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
QGIS 图层映射配置。
所有模板→目标库的表名/图层映射集中管理,避免散落在业务代码中。
"""
from pathlib import Path
import os
# ============================================================
# 静态底图映射:模板中 PostgreSQL 图层 → 本地 GPKG 文件
# key: 模板图层名(用于匹配 maplayer/layername
# table: 原始数据源表名(schema.table 格式,用于匹配 datasource 替换)
# gpkg: 本地 GPKG 文件名(相对于 GPKG 目录)
# ============================================================
STATIC_LAYERS = {
"水库": {"table": "base.rivers", "gpkg": "rivers.gpkg"},
"市州驻地": {"table": "base.sx_capital", "gpkg": "sx_capital.gpkg"},
"河流": {"table": "base.river", "gpkg": "river.gpkg"},
"active_fault": {"table": "base.active_fault", "gpkg": "active_fault.gpkg"},
"陕西省": {"table": "base.sx", "gpkg": "sx.gpkg"},
"乡镇驻地": {"table": "base.sx_street", "gpkg": "sx_street.gpkg"},
"区县驻地": {"table": "base.sx_xa_county", "gpkg": "sx_xa_county.gpkg"},
"县界": {"table": "base.sx_xa_county_boundary", "gpkg": "sx_xa_county_boundary.gpkg"},
"周边区县": {"table": "base.sx_zb_county_boundary", "gpkg": "sx_zb_county_boundary.gpkg"},
"周边市州": {"table": "base.sx_zb_city", "gpkg": "sx_zb_city.gpkg"},
"周边县区": {"table": "base.sx_zb_county", "gpkg": "sx_zb_county.gpkg"},
"traffic_expressway": {"table": "base.traffic_expressway", "gpkg": "traffic_expressway.gpkg"},
"traffic_provincial": {"table": "base.traffic_provincial", "gpkg": "traffic_provincial.gpkg"},
"traffic_railway": {"table": "base.traffic_railway", "gpkg": "traffic_railway.gpkg"},
"traffic_township": {"table": "base.traffic_township", "gpkg": "traffic_township.gpkg"},
"traffic_trunk_line": {"table": "base.traffic_trunk_line", "gpkg": "traffic_trunk_line.gpkg"},
}
# ============================================================
# OGR 本地图层 → PostgreSQL 转换
# 设计师用本地 JSON/shp 文件制作模板,数据已迁移到 qgis schema
# key: layername(模板 datasource 中 |layername=xxx 的值)
# value: qgis schema 中的目标表名
# ============================================================
OGR_TO_POSTGRES = {
"公园": "shelter_park",
"学校": "shelter_school",
"文化馆": "shelter_cultural",
"人防设施": "shelter_defence",
"体育馆": "shelter_gymnasium",
"广场": "shelter_square",
"住宿": "shelter_stay",
}
# ============================================================
# 表名映射:模板中引用的表名 → 目标库中实际表名
# (模板由多个源库的表拼合,迁移后表名可能不同)
# ============================================================
TABLE_RENAMES = {
"hazard_waterlogging": "hazard_hydrops", # 积水点
}
# ============================================================
# Schema 替换:模板源 schema → 目标 schema
# ============================================================
SCHEMA_REPLACEMENTS = ["base", "kspg", "dzxx"]
# ============================================================
# 图层过滤配置(layer_filter.py 使用)
# ============================================================
EVENT_LAYERS = ["eqcenter", "震中"] # 按 event 字段过滤
QUEUE_LAYERS = [
"intensity", "intensity_mian",
"dz_ryss", "dz_jjss", "dz_rysw", "dz_jzph", "dz_xzjl",
] # 按 eqqueue_id 字段过滤
# ============================================================
# GPKG 目录路径(项目根目录相对路径)
# ============================================================
GPKG_SUBDIR = "app/data/gpkg"
def get_gpkg_dir(project_root: str = None) -> str:
"""获取 GPKG 目录绝对路径"""
if project_root is None:
project_root = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)
gpkg_dir = os.path.join(project_root, GPKG_SUBDIR)
return os.path.normpath(gpkg_dir).replace("\\", "/")
def build_static_layers_config(gpkg_dir: str = None) -> dict:
"""
构建 template_modifier / qgis_runner 使用的静态底图配置。
返回格式与原有 template_override 的 static_layers 段兼容。
"""
if gpkg_dir is None:
gpkg_dir = get_gpkg_dir()
layers = {}
for name, info in STATIC_LAYERS.items():
layers[name] = {
"file": info["gpkg"],
"table": info["table"],
}
return {
"enabled": True,
"gpkg_dir": gpkg_dir,
"layers": layers,
}