feat: 渠道图层沿用已保存的 QGIS 样式
This commit is contained in:
@@ -15,6 +15,7 @@ import numpy as np
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
TOOL = "AoiChannel"
|
||||
STYLE_DIR = Path(__file__).resolve().parent / "styles"
|
||||
AOI_FIELDS = ["AOI唯一标签", "AOI名称", "空间信息(几何)"]
|
||||
CHANNEL_LAYER_FIELDS = [
|
||||
"渠道编码", "渠道类型", "全网渠道编码", "渠道名称", "星级",
|
||||
@@ -308,6 +309,44 @@ def write_gpkg(layer, path, name):
|
||||
found = connection.execute("SELECT 1 FROM sqlite_master WHERE name LIKE 'rtree_%' LIMIT 1").fetchone()
|
||||
if found is None:
|
||||
raise RuntimeError(f"{path.name} 没有空间索引")
|
||||
if (STYLE_DIR / f"{name}.qml").is_file():
|
||||
apply_layer_style(path, name)
|
||||
|
||||
|
||||
def apply_layer_style(path, table_name):
|
||||
qml = (STYLE_DIR / f"{table_name}.qml").read_text(encoding="utf-8")
|
||||
sld_path = STYLE_DIR / f"{table_name}.sld"
|
||||
sld = sld_path.read_text(encoding="utf-8") if sld_path.is_file() else ""
|
||||
with sqlite3.connect(path) as connection:
|
||||
connection.execute(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS layer_styles (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
f_table_catalog TEXT(256),
|
||||
f_table_schema TEXT(256),
|
||||
f_table_name TEXT(256),
|
||||
f_geometry_column TEXT(256),
|
||||
styleName TEXT(30),
|
||||
styleQML TEXT,
|
||||
styleSLD TEXT,
|
||||
useAsDefault BOOLEAN,
|
||||
description TEXT,
|
||||
owner TEXT(30),
|
||||
ui TEXT(30),
|
||||
update_time DATETIME DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
|
||||
)
|
||||
"""
|
||||
)
|
||||
connection.execute("DELETE FROM layer_styles WHERE f_table_name = ?", (table_name,))
|
||||
connection.execute(
|
||||
"""
|
||||
INSERT INTO layer_styles (
|
||||
f_table_catalog, f_table_schema, f_table_name, f_geometry_column,
|
||||
styleName, styleQML, styleSLD, useAsDefault, description, owner, ui, update_time
|
||||
) VALUES ('', '', ?, 'geom', 'Default', ?, ?, 1, '', '', NULL, strftime('%Y-%m-%dT%H:%M:%fZ','now'))
|
||||
""",
|
||||
(table_name, qml, sld),
|
||||
)
|
||||
|
||||
|
||||
def new_stamp():
|
||||
|
||||
Reference in New Issue
Block a user