feat: 注释停用市场用户量图层
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
1. 准备源数据目录:
|
||||
- `source/GridMap.gpkg`
|
||||
- `source/Grid_5G.gpkg`
|
||||
- `source/Grid_4G.gpkg`
|
||||
<!-- - `source/Grid_4G.gpkg`:用户量停用后不再读取。 -->
|
||||
- `source/BuildingInfo.gpkg`
|
||||
- `source/CellData.gpkg`
|
||||
- `source/GIS.qgz`
|
||||
@@ -28,7 +28,6 @@ zip 内包含:
|
||||
```text
|
||||
GIS.qgz
|
||||
BuildingInfo.gpkg
|
||||
用户量.tif
|
||||
竟对信号.tif
|
||||
```
|
||||
|
||||
@@ -39,11 +38,12 @@ output/全量网格图层.zip
|
||||
├── GIS.qgz
|
||||
├── BuildingInfo.gpkg
|
||||
├── CellData.gpkg
|
||||
├── 用户量.tif
|
||||
└── 竟对信号.tif
|
||||
```
|
||||
|
||||
所有成果包均不再包含 CSV。程序会先合并本次参与处理的全部市场网格边界,再生成两张全域 TIF;网格之间没有数据的区域保持透明。`BuildingInfo.gpkg` 和 `CellData.gpkg` 在汇总包中均为完整源文件副本并保留样式支撑表;`GIS.qgz` 使用全网 BuildingInfo 范围作为初始画布。`用户量.tif` 会复用各单市场包已经计算出的动态 10%/30%/30%/30% 分档阈值,并按市场网格分别绘制到同一张汇总图中,因此汇总图颜色口径与单市场图一致;`竟对信号.tif` 使用固定八档 RSRP 图例,并将竟对 MR 总采样点为 `0` 的符合条件 Grid 标红。设置 `LIMIT` 时,TIF 汇总范围与本次受限处理的市场保持一致。
|
||||
所有成果包均不再包含 CSV 或 `用户量.tif`,专题 TIF 只生成 `竟对信号.tif`。程序先合并本次参与处理的全部市场网格边界,再生成全域竟对信号图;网格之间没有数据的区域保持透明。`BuildingInfo.gpkg` 和 `CellData.gpkg` 在汇总包中均为完整源文件副本并保留样式支撑表;`GIS.qgz` 使用全网 BuildingInfo 范围作为初始画布。竟对信号使用固定八档 RSRP 图例,并将竟对 MR 总采样点为 `0` 的符合条件 Grid 标红。设置 `LIMIT` 时,TIF 汇总范围与本次受限处理的市场保持一致。
|
||||
|
||||
用户量的生成入口、4G 读取、阈值汇总、图例和结果写入代码以注释保留;专用算法函数仍保留供恢复使用。QGIS 模板中的原用户量图层配置保存为 XML 注释,打开项目时不会加载。恢复时需同时恢复这些代码入口和模板配置。
|
||||
|
||||
## 裁切规则
|
||||
|
||||
@@ -55,7 +55,7 @@ output/全量网格图层.zip
|
||||
|
||||
来源:`source/GIS.qgz`
|
||||
|
||||
说明:以该文件为模板生成到每个结果包。单市场 QGIS 会删除 `CellData` 图层,顺序为 `竟对信号`、`用户量`、`BuildInfo`、`GoogleCN`;全量汇总 QGIS 保留 `CellData`,顺序为 `CellData`、`竟对信号`、`用户量`、`BuildInfo`、`GoogleCN`。竟对信号图默认勾选,用户量图默认关闭。程序会读取 QGZ 内的项目 XML,把 BuildInfo 图层范围更新为当前市场实际楼宇范围,并将 QGIS 主画布设置为该范围四周增加 5% 留白。
|
||||
说明:以该文件为模板生成到每个结果包。单市场图层顺序为 `竟对信号`、`BuildInfo`、`GoogleCN`、`必应地图`;全量汇总在最前方另保留 `CellData`。用户量图层已停用,兼容旧模板时也会移除其引用。竟对信号与 GoogleCN 默认勾选,必应地图默认关闭。程序把 BuildInfo 图层范围更新为当前市场实际楼宇范围,并将 QGIS 主画布设置为该范围四周增加 5% 留白。
|
||||
|
||||
QGZ 内的样式数据库、其他图层配置和项目结构保持不变;如果当前市场没有 BuildingInfo 要素,画布范围会回退到市场网格范围。
|
||||
|
||||
@@ -79,7 +79,12 @@ QGZ 内的样式数据库、其他图层配置和项目结构保持不变;如
|
||||
|
||||
说明:不再复制到单市场 ZIP,仅完整复制到 `全量网格图层.zip`。全量 QGZ 中显示为 `CellData`,沿用源 GeoPackage 的分类样式和标注配置;单市场 QGZ 会移除该图层及其引用。
|
||||
|
||||
### 用户量.tif
|
||||
### 用户量.tif(已停用)
|
||||
|
||||
以下为保留的历史计算口径,当前单市场和汇总包均不生成用户量图层,`summary.json` 也不再写入用户量结果。
|
||||
|
||||
<details>
|
||||
<summary>查看原用户量计算口径</summary>
|
||||
|
||||
来源字段:`Grid_5G.gpkg` 和 `Grid_4G.gpkg` 的 `grid20_id`、`mro_total_dl`
|
||||
|
||||
@@ -101,6 +106,8 @@ QGZ 内的样式数据库、其他图层配置和项目结构保持不变;如
|
||||
|
||||
相同数值的像元始终归入同一颜色档位,不会为了强制凑比例而按空间位置拆分,因此实际各档像元占比可能因重复值而偏离 10%/30%/30%/30%。
|
||||
|
||||
</details>
|
||||
|
||||
### 竟对信号.tif
|
||||
|
||||
来源:`source/Grid_5G.gpkg`
|
||||
@@ -132,12 +139,12 @@ QGZ 内的样式数据库、其他图层配置和项目结构保持不变;如
|
||||
|
||||
## 图例说明文件
|
||||
|
||||
每次运行会在 `output/` 根目录更新两份独立图例文件,不重复放入各市场 ZIP:
|
||||
每次运行会在 `output/` 根目录更新竟对信号图例,不重复放入各市场 ZIP:
|
||||
|
||||
- `excellent_heatmap_legend.csv`:说明 4G+5G 合并用户量的四档颜色,依次为前 10% 红、10%~40% 黄、40%~70% 蓝、后 30% 绿。
|
||||
<!-- - `excellent_heatmap_legend.csv`:原用户量四档图例,生成入口已注释停用。 -->
|
||||
- `competitor_signal_legend.csv`:说明竟对 MR 总采样点为 `0` 时使用红色,以及正采样量 Grid 按 `ssb_rsrp_dl` 使用的八档固定颜色;未通过筛选或信号无效的区域透明。
|
||||
|
||||
QGIS 中竟对信号默认显示、用户量默认关闭。单市场 QGIS 不包含 CellData;全量汇总 QGIS 保留 CellData,并沿用源 GeoPackage 的分类样式和标注。
|
||||
QGIS 中竟对信号默认显示,用户量已移除。单市场 QGIS 不包含 CellData;全量汇总 QGIS 保留 CellData,并沿用源 GeoPackage 的分类样式和标注。
|
||||
|
||||
## 常用配置
|
||||
|
||||
@@ -165,15 +172,13 @@ QGIS 中竟对信号默认显示、用户量默认关闭。单市场 QGIS 不包
|
||||
|
||||
当前处理流程已做以下加速:
|
||||
|
||||
- 5G Grid 在同一市场内只执行一次 RTree 查询,同时供竟对信号和用户量合并使用;4G Grid 另执行一次轻量 RTree 查询,只提取 `grid20_id`、`mro_total_dl` 和几何定位信息。
|
||||
- 用户量以 `grid20_id` 建立内存索引,对 4G/5G 做并集去重和采样点求和,不生成或复制包含全部字段的中间大表。
|
||||
- 5G Grid 在同一市场内只执行一次 RTree 查询,用于竟对信号;用户量停用后不再查询 4G、不构建 4G/5G 用户量合并索引。
|
||||
- Grid 和 BuildingInfo 使用 Shapely 批量解析 WKB、判断几何相交并提取边界,减少大量 Python 逐要素调用。
|
||||
- 市场边界使用 Prepared Geometry 加速同一边界与大量 Grid 候选的重复拓扑判断;汇总任务会先修复边界副本的无效拓扑,再执行全域合并。
|
||||
- 热力图平滑使用 NumPy 滑动窗口矩阵乘法,一次处理完整像元矩阵,不再逐行执行卷积。
|
||||
<!-- 原用户量平滑函数及 NumPy 滑动窗口算法仍保留,当前生成流程不再调用。 -->
|
||||
- 不同市场网格使用独立进程并行处理,每个进程自行打开只读 GeoPackage 连接并写入独立 zip。
|
||||
- 单市场范围过大时按 `MAX_RASTER_PIXELS` 自动调整像元大小,结果中记录实际像元尺寸和分辨率调整系数。
|
||||
- 汇总 TIF 使用独立的 `SUMMARY_MAX_RASTER_PIXELS` 清晰度上限,避免受单市场 2500 万像元限制而过度降采样;其中汇总 `用户量.tif` 复用各单市场阈值逐市场绘制,保证总图和单市场图颜色口径一致。
|
||||
- 汇总用户量仍按市场逐个计算,但每个市场只分配覆盖自身有效像元的局部缓冲区,并在四周保留与平滑半径相同的边距;像元对齐、市场阈值、平滑结果和写入顺序保持不变,避免为每个市场重复处理整张全量画布。
|
||||
- 汇总竟对信号 TIF 使用独立的 `SUMMARY_MAX_RASTER_PIXELS` 清晰度上限,避免受单市场 2500 万像元限制而过度降采样。原汇总用户量逐市场局部缓冲区算法仍保留,调用入口已注释。
|
||||
- zip 和 `summary.json` 使用临时文件完成后原子替换,处理中断时不会先删除已有成果。
|
||||
- `output/summary.json` 会记录总耗时、实际并发数以及每个市场的 Grid/Building 分阶段耗时。
|
||||
|
||||
|
||||
@@ -24,19 +24,21 @@ DEFAULT_SOURCE_DIR = Path("source") # 源数据目录,存放 GridMap.gpkg、G
|
||||
OUTPUT_DIR = Path("output") # 输出根目录,每个市场网格会在这里生成一个 JMXXXX.zip 结果包。
|
||||
MARKET_GPKG = DEFAULT_SOURCE_DIR / "GridMap.gpkg" # 市场网格 GeoPackage 文件路径。
|
||||
GRID_5G_GPKG = DEFAULT_SOURCE_DIR / "Grid_5G.gpkg" # 5G Grid;竟对信号仅使用该文件。
|
||||
GRID_4G_GPKG = DEFAULT_SOURCE_DIR / "Grid_4G.gpkg" # 4G Grid;仅参与竟对用户量合并。
|
||||
# 用户量图层停用;以下原代码以注释保留,便于按需恢复。
|
||||
# GRID_4G_GPKG = DEFAULT_SOURCE_DIR / "Grid_4G.gpkg" # 4G Grid;仅参与竟对用户量合并。
|
||||
BUILDING_INFO_GPKG = DEFAULT_SOURCE_DIR / "BuildingInfo.gpkg" # 建筑信息 GeoPackage 文件路径,用于结果包 BuildingInfo 分割和楼宇指标 CSV 名称匹配。
|
||||
CELL_DATA_GPKG = DEFAULT_SOURCE_DIR / "CellData.gpkg" # 小区数据 GeoPackage;仅完整复制到汇总结果包。
|
||||
GIS_PROJECT_SOURCE = DEFAULT_SOURCE_DIR / "GIS.qgz" # 每个市场网格结果包使用的 QGIS 项目模板来源。
|
||||
RSRP_FIELD = "ssb_rsrp_dl" # 用于生成热力图的电信 RSRP 字段名。
|
||||
EXCELLENT_CELL_FIELD = "mro_total_dl" # 用于生成用户量热力图的字段名,值越大越红。
|
||||
# EXCELLENT_CELL_FIELD = "mro_total_dl" # 用于生成用户量热力图的字段名,值越大越红。
|
||||
EXCELLENT_CELL_FIELD = "mro_total_dl" # 竟对信号筛选仍需使用的 5G 竟对总采样量字段。
|
||||
GRID_ID_FIELD = "grid20_id" # 4G/5G 用户量合并去重的唯一索引字段。
|
||||
WEAK_COVER_FIELD = "rsrp_lt_neg105_dl" # 用于生成信号差用户量热力图的字段名,值越大越红。
|
||||
MOBILE_TOTAL_FIELD = "mro_total_yd" # 移动采样点总数字段,用作移动弱覆盖比例分母。
|
||||
MOBILE_WEAK_COVER_FIELD = "rsrp_lt_neg105_yd" # 移动弱覆盖采样点字段,用作目标 Grid 筛选。
|
||||
MARKET_LAYER = None # 市场网格图层名;None 表示自动使用 GPKG 中第一个 feature 图层。
|
||||
GRID_5G_LAYER = None # 5G Grid 图层名;None 表示自动使用 GPKG 中第一个 feature 图层。
|
||||
GRID_4G_LAYER = None # 4G Grid 图层名;None 表示自动使用 GPKG 中第一个 feature 图层。
|
||||
# GRID_4G_LAYER = None # 4G Grid 图层名;None 表示自动使用 GPKG 中第一个 feature 图层。
|
||||
BUILDING_LAYER = None # Building 建筑指标图层名;None 表示自动使用 GPKG 中第一个 feature 图层。
|
||||
BUILDING_INFO_LAYER = None # BuildingInfo 建筑信息图层名;None 表示自动使用 GPKG 中第一个 feature 图层。
|
||||
MARKET_CODE_FIELD = "fid" # GridMap 市场网格唯一 ID 前缀字段。
|
||||
@@ -54,7 +56,8 @@ GIS_PROJECT_OUTPUT_FILENAME = "GIS.qgz" # 每个市场网格结果包内输出
|
||||
HEATMAP_SMOOTH_RADIUS = 10 # 热力图平滑半径,数值越大边界感越弱但细节越柔。
|
||||
HEATMAP_ALPHA = 191 # 热力图有效像元透明度;191 约等于 75% 不透明度。
|
||||
PROJECT_EXTENT_PADDING_RATIO = 0.05 # QGIS 打开后的画布留白比例;0.05 表示在 BuildingInfo 范围四周各增加 5%。
|
||||
USER_COUNT_OUTPUT_FILENAME = "用户量.tif" # 采样点数量热力图输出文件名。
|
||||
# USER_COUNT_OUTPUT_FILENAME = "用户量.tif" # 采样点数量热力图输出文件名。
|
||||
USER_COUNT_OUTPUT_FILENAME = "用户量.tif" # 保留文件名,以移除旧模板中的用户量图层引用。
|
||||
COMPETITOR_SIGNAL_OUTPUT_FILENAME = "竟对信号.tif" # 移动非弱覆盖区域内的竟对 MR 弱覆盖/零采样信号图。
|
||||
COMPETITOR_SIGNAL_MOBILE_WEAK_RATIO_MAX = 20.0 # 移动弱覆盖比例必须严格小于该百分比。
|
||||
COMPETITOR_SIGNAL_WEAK_RATIO_MIN = 20.0 # 竟对 MR 弱覆盖比例必须严格大于该百分比。
|
||||
@@ -70,7 +73,8 @@ COMPETITOR_SIGNAL_RSRP_COLORS = (
|
||||
(58, 14, 247), # [-74, 0],紫色。
|
||||
)
|
||||
SUMMARY_OUTPUT_ENABLED = True # 是否额外生成全部市场网格汇总 TIF 结果包。
|
||||
SUMMARY_OUTPUT_FILENAME = "全量网格图层.zip" # 汇总结果包文件名,包含两张 TIF、GIS.qgz、BuildingInfo.gpkg 和 CellData.gpkg。
|
||||
# SUMMARY_OUTPUT_FILENAME = "全量网格图层.zip" # 汇总结果包文件名,包含两张 TIF、GIS.qgz、BuildingInfo.gpkg 和 CellData.gpkg。
|
||||
SUMMARY_OUTPUT_FILENAME = "全量网格图层.zip" # 包含竟对信号 TIF、GIS.qgz、BuildingInfo.gpkg 和 CellData.gpkg。
|
||||
LEGACY_SUMMARY_OUTPUT_FILENAME = "所有网格汇总.zip" # 旧汇总包文件名;新包成功生成后自动清理。
|
||||
SUMMARY_MARKET_CODE = "全量网格图层" # 汇总任务在日志和 summary.json 中使用的标识。
|
||||
SUMMARY_MAX_RASTER_PIXELS = 100_000_000 # 汇总 TIF 最大像元数;提高该值可增强清晰度,但会增加内存、耗时和文件体积。
|
||||
@@ -175,15 +179,20 @@ def serialize_qgis_project(root, original_data):
|
||||
return bom + (doctype + b"\r\n" if doctype else b"") + xml_data
|
||||
|
||||
|
||||
def remove_qgis_layer(root, datasource_filename):
|
||||
# def remove_qgis_layer(root, datasource_filename):
|
||||
def remove_qgis_layer(root, datasource_filename, required=True):
|
||||
target_layer = None
|
||||
for layer in root.findall(".//projectlayers/maplayer"):
|
||||
datasource = (layer.findtext("datasource") or "").replace("\\", "/")
|
||||
if Path(datasource.split("|", 1)[0]).name == datasource_filename:
|
||||
target_layer = layer
|
||||
break
|
||||
# if target_layer is None:
|
||||
# raise ValueError(f"QGIS 项目模板缺少待移除图层:{datasource_filename}")
|
||||
if target_layer is None:
|
||||
raise ValueError(f"QGIS 项目模板缺少待移除图层:{datasource_filename}")
|
||||
if required:
|
||||
raise ValueError(f"QGIS 项目模板缺少待移除图层:{datasource_filename}")
|
||||
return None
|
||||
|
||||
layer_id = target_layer.findtext("id")
|
||||
layer_name = target_layer.findtext("layername")
|
||||
@@ -254,6 +263,7 @@ def copy_gis_project_to_market(
|
||||
data = source_zip.read(info.filename)
|
||||
if info.filename == project_member:
|
||||
root = ET.fromstring(data)
|
||||
remove_qgis_layer(root, USER_COUNT_OUTPUT_FILENAME, required=False)
|
||||
if not include_cell_data:
|
||||
remove_qgis_layer(root, CELL_DATA_OUTPUT_FILENAME)
|
||||
canvas = root.find(".//mapcanvas[@name='theMapCanvas']")
|
||||
@@ -278,7 +288,7 @@ def copy_gis_project_to_market(
|
||||
set_xml_extent(layer_extent_element, layer_extent)
|
||||
|
||||
raster_filenames = {
|
||||
USER_COUNT_OUTPUT_FILENAME,
|
||||
# USER_COUNT_OUTPUT_FILENAME,
|
||||
COMPETITOR_SIGNAL_OUTPUT_FILENAME,
|
||||
}
|
||||
for layer in root.findall(".//projectlayers/maplayer"):
|
||||
@@ -1687,10 +1697,10 @@ def export_market_grid_outputs(
|
||||
market,
|
||||
pixel_width,
|
||||
pixel_height,
|
||||
user_count_path,
|
||||
# user_count_path,
|
||||
competitor_signal_path,
|
||||
csv_path,
|
||||
grid_4g_source=None,
|
||||
# grid_4g_source=None,
|
||||
max_raster_pixels=None,
|
||||
):
|
||||
minx, miny, maxx, maxy, pixel_width, pixel_height, width, height, scale_factor = market_raster_layout(
|
||||
@@ -1706,7 +1716,7 @@ def export_market_grid_outputs(
|
||||
MOBILE_TOTAL_FIELD,
|
||||
MOBILE_WEAK_COVER_FIELD,
|
||||
)
|
||||
user_count_records = {}
|
||||
# user_count_records = {}
|
||||
competitor_signal_value_sum = np.zeros((height, width), dtype=np.float32)
|
||||
competitor_signal_value_weight = np.zeros((height, width), dtype=np.uint16)
|
||||
zero_total_mask = np.zeros((height, width), dtype=bool)
|
||||
@@ -1721,13 +1731,14 @@ def export_market_grid_outputs(
|
||||
"no_center_pixels": 0,
|
||||
}
|
||||
|
||||
fields = list(
|
||||
dict.fromkeys(
|
||||
(*CSV_SOURCE_FIELDS, *raster_fields, GRID_ID_FIELD)
|
||||
if csv_path is not None
|
||||
else (*raster_fields, GRID_ID_FIELD)
|
||||
)
|
||||
)
|
||||
# fields = list(
|
||||
# dict.fromkeys(
|
||||
# (*CSV_SOURCE_FIELDS, *raster_fields, GRID_ID_FIELD)
|
||||
# if csv_path is not None
|
||||
# else (*raster_fields, GRID_ID_FIELD)
|
||||
# )
|
||||
# )
|
||||
fields = list(dict.fromkeys((*CSV_SOURCE_FIELDS, *raster_fields) if csv_path is not None else raster_fields))
|
||||
if csv_path is None and CLIP_MODE == "center":
|
||||
fields.extend(field for field in ("longitude", "latitude") if field not in fields)
|
||||
require_columns(grid_5g_conn, grid_5g_layer.table_name, fields)
|
||||
@@ -1747,8 +1758,8 @@ def export_market_grid_outputs(
|
||||
"""
|
||||
params = (maxx, minx, maxy, miny)
|
||||
candidates = 0
|
||||
user_count_5g_clipped_rows = 0
|
||||
user_count_5g_invalid_grid_ids = 0
|
||||
# user_count_5g_clipped_rows = 0
|
||||
# user_count_5g_invalid_grid_ids = 0
|
||||
csv_rows = 0
|
||||
csv_skipped = csv_path is None or (csv_path.exists() and not OVERWRITE)
|
||||
csv_file = None
|
||||
@@ -1799,17 +1810,17 @@ def export_market_grid_outputs(
|
||||
if window is None:
|
||||
continue
|
||||
|
||||
if user_count_path is not None:
|
||||
user_count_5g_clipped_rows += 1
|
||||
if not merge_user_count_record(
|
||||
user_count_records,
|
||||
values.get(GRID_ID_FIELD),
|
||||
window,
|
||||
numeric_values[EXCELLENT_CELL_FIELD],
|
||||
"5G",
|
||||
prefer_geometry=True,
|
||||
):
|
||||
user_count_5g_invalid_grid_ids += 1
|
||||
# if user_count_path is not None:
|
||||
# user_count_5g_clipped_rows += 1
|
||||
# if not merge_user_count_record(
|
||||
# user_count_records,
|
||||
# values.get(GRID_ID_FIELD),
|
||||
# window,
|
||||
# numeric_values[EXCELLENT_CELL_FIELD],
|
||||
# "5G",
|
||||
# prefer_geometry=True,
|
||||
# ):
|
||||
# user_count_5g_invalid_grid_ids += 1
|
||||
|
||||
competitor_total = numeric_values[EXCELLENT_CELL_FIELD]
|
||||
competitor_rsrp = numeric_values[RSRP_FIELD]
|
||||
@@ -1871,49 +1882,49 @@ def export_market_grid_outputs(
|
||||
csv_file.close()
|
||||
shapely.destroy_prepared(market.geometry)
|
||||
|
||||
user_count_result = None
|
||||
if user_count_path is not None:
|
||||
if grid_4g_source is None:
|
||||
raise ValueError("生成竟对用户量图层时必须提供 Grid_4G 数据源")
|
||||
grid_4g_conn, grid_4g_layer, grid_4g_rtree = grid_4g_source
|
||||
source_stats = {
|
||||
"5G": {
|
||||
"candidates": candidates,
|
||||
"clipped_rows": user_count_5g_clipped_rows,
|
||||
"invalid_grid_ids": user_count_5g_invalid_grid_ids,
|
||||
}
|
||||
}
|
||||
source_stats["4G"] = collect_user_count_source(
|
||||
user_count_records,
|
||||
grid_4g_conn,
|
||||
grid_4g_layer,
|
||||
grid_4g_rtree,
|
||||
market,
|
||||
minx,
|
||||
maxy,
|
||||
pixel_width,
|
||||
pixel_height,
|
||||
width,
|
||||
height,
|
||||
"4G",
|
||||
)
|
||||
user_count_state = build_merged_user_count_state(user_count_records, height, width)
|
||||
user_count_result = render_ranked_raster(
|
||||
user_count_state,
|
||||
market,
|
||||
user_count_path,
|
||||
minx,
|
||||
maxy,
|
||||
pixel_width,
|
||||
pixel_height,
|
||||
width,
|
||||
height,
|
||||
sum(stats["candidates"] for stats in source_stats.values()),
|
||||
EXCELLENT_COLORS,
|
||||
EXCELLENT_PERCENT_STEPS,
|
||||
)
|
||||
user_count_result.update(merged_user_count_metadata(user_count_records, source_stats))
|
||||
del user_count_state
|
||||
# user_count_result = None
|
||||
# if user_count_path is not None:
|
||||
# if grid_4g_source is None:
|
||||
# raise ValueError("生成竟对用户量图层时必须提供 Grid_4G 数据源")
|
||||
# grid_4g_conn, grid_4g_layer, grid_4g_rtree = grid_4g_source
|
||||
# source_stats = {
|
||||
# "5G": {
|
||||
# "candidates": candidates,
|
||||
# "clipped_rows": user_count_5g_clipped_rows,
|
||||
# "invalid_grid_ids": user_count_5g_invalid_grid_ids,
|
||||
# }
|
||||
# }
|
||||
# source_stats["4G"] = collect_user_count_source(
|
||||
# user_count_records,
|
||||
# grid_4g_conn,
|
||||
# grid_4g_layer,
|
||||
# grid_4g_rtree,
|
||||
# market,
|
||||
# minx,
|
||||
# maxy,
|
||||
# pixel_width,
|
||||
# pixel_height,
|
||||
# width,
|
||||
# height,
|
||||
# "4G",
|
||||
# )
|
||||
# user_count_state = build_merged_user_count_state(user_count_records, height, width)
|
||||
# user_count_result = render_ranked_raster(
|
||||
# user_count_state,
|
||||
# market,
|
||||
# user_count_path,
|
||||
# minx,
|
||||
# maxy,
|
||||
# pixel_width,
|
||||
# pixel_height,
|
||||
# width,
|
||||
# height,
|
||||
# sum(stats["candidates"] for stats in source_stats.values()),
|
||||
# EXCELLENT_COLORS,
|
||||
# EXCELLENT_PERCENT_STEPS,
|
||||
# )
|
||||
# user_count_result.update(merged_user_count_metadata(user_count_records, source_stats))
|
||||
# del user_count_state
|
||||
|
||||
competitor_signal_state = {
|
||||
"value_sum": competitor_signal_value_sum,
|
||||
@@ -1960,7 +1971,8 @@ def export_market_grid_outputs(
|
||||
zero_total_mask,
|
||||
)
|
||||
|
||||
for result in (user_count_result, competitor_signal_result):
|
||||
# for result in (user_count_result, competitor_signal_result):
|
||||
for result in (competitor_signal_result,):
|
||||
if result is None:
|
||||
continue
|
||||
result["raster_extent"] = [
|
||||
@@ -1983,7 +1995,7 @@ def export_market_grid_outputs(
|
||||
"skipped": csv_skipped,
|
||||
}
|
||||
return (
|
||||
user_count_result,
|
||||
# user_count_result,
|
||||
competitor_signal_result,
|
||||
csv_result,
|
||||
)
|
||||
@@ -2080,25 +2092,25 @@ def process_market(market, pixel_width, pixel_height, output_dir):
|
||||
|
||||
with (
|
||||
open_read_connection(GRID_5G_GPKG) as grid_5g_conn,
|
||||
open_read_connection(GRID_4G_GPKG) as grid_4g_conn,
|
||||
# open_read_connection(GRID_4G_GPKG) as grid_4g_conn,
|
||||
open_read_connection(BUILDING_INFO_GPKG) as building_info_conn,
|
||||
):
|
||||
grid_5g_layer = resolve_feature_layer(grid_5g_conn, GRID_5G_LAYER)
|
||||
grid_4g_layer = resolve_feature_layer(grid_4g_conn, GRID_4G_LAYER)
|
||||
# grid_4g_layer = resolve_feature_layer(grid_4g_conn, GRID_4G_LAYER)
|
||||
building_info_layer = resolve_feature_layer(building_info_conn, BUILDING_INFO_LAYER)
|
||||
grid_5g_rtree = rtree_name(grid_5g_conn, grid_5g_layer)
|
||||
grid_4g_rtree = rtree_name(grid_4g_conn, grid_4g_layer)
|
||||
# grid_4g_rtree = rtree_name(grid_4g_conn, grid_4g_layer)
|
||||
building_info_rtree = rtree_name(building_info_conn, building_info_layer)
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix=f"{safe_filename(market.code)}_") as temp_dir:
|
||||
market_dir = Path(temp_dir)
|
||||
gis_project_path = market_dir / GIS_PROJECT_OUTPUT_FILENAME
|
||||
|
||||
user_count_path = market_dir / excellent_heatmap_raster_filename(EXCELLENT_CELL_FIELD)
|
||||
# user_count_path = market_dir / excellent_heatmap_raster_filename(EXCELLENT_CELL_FIELD)
|
||||
competitor_signal_path = market_dir / competitor_signal_raster_filename()
|
||||
grid_started_at = perf_counter()
|
||||
(
|
||||
user_count_result,
|
||||
# user_count_result,
|
||||
competitor_signal_result,
|
||||
_,
|
||||
) = export_market_grid_outputs(
|
||||
@@ -2108,10 +2120,10 @@ def process_market(market, pixel_width, pixel_height, output_dir):
|
||||
market,
|
||||
pixel_width,
|
||||
pixel_height,
|
||||
user_count_path,
|
||||
# user_count_path,
|
||||
competitor_signal_path,
|
||||
None,
|
||||
(grid_4g_conn, grid_4g_layer, grid_4g_rtree),
|
||||
# (grid_4g_conn, grid_4g_layer, grid_4g_rtree),
|
||||
)
|
||||
grid_elapsed = perf_counter() - grid_started_at
|
||||
|
||||
@@ -2143,7 +2155,7 @@ def process_market(market, pixel_width, pixel_height, output_dir):
|
||||
"market_fid": market.fid,
|
||||
"market_code": market.code,
|
||||
"market_name": market.name,
|
||||
"excellent_heatmap_result": rewrite_result_for_zip(user_count_result, zip_path, market_dir),
|
||||
# "excellent_heatmap_result": rewrite_result_for_zip(user_count_result, zip_path, market_dir),
|
||||
"competitor_signal_result": rewrite_result_for_zip(
|
||||
competitor_signal_result,
|
||||
zip_path,
|
||||
@@ -2160,7 +2172,8 @@ def process_market(market, pixel_width, pixel_height, output_dir):
|
||||
}
|
||||
|
||||
|
||||
def process_summary_grid_outputs(markets, pixel_width, pixel_height, output_dir, market_user_thresholds=None):
|
||||
# def process_summary_grid_outputs(markets, pixel_width, pixel_height, output_dir, market_user_thresholds=None):
|
||||
def process_summary_grid_outputs(markets, pixel_width, pixel_height, output_dir):
|
||||
started_at = perf_counter()
|
||||
output_dir = Path(output_dir)
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
@@ -2181,18 +2194,18 @@ def process_summary_grid_outputs(markets, pixel_width, pixel_height, output_dir,
|
||||
|
||||
with (
|
||||
open_read_connection(GRID_5G_GPKG) as grid_5g_conn,
|
||||
open_read_connection(GRID_4G_GPKG) as grid_4g_conn,
|
||||
# open_read_connection(GRID_4G_GPKG) as grid_4g_conn,
|
||||
):
|
||||
grid_5g_layer = resolve_feature_layer(grid_5g_conn, GRID_5G_LAYER)
|
||||
grid_4g_layer = resolve_feature_layer(grid_4g_conn, GRID_4G_LAYER)
|
||||
# grid_4g_layer = resolve_feature_layer(grid_4g_conn, GRID_4G_LAYER)
|
||||
grid_5g_rtree = rtree_name(grid_5g_conn, grid_5g_layer)
|
||||
grid_4g_rtree = rtree_name(grid_4g_conn, grid_4g_layer)
|
||||
# grid_4g_rtree = rtree_name(grid_4g_conn, grid_4g_layer)
|
||||
with tempfile.TemporaryDirectory(prefix="market_grid_summary_") as temp_dir:
|
||||
summary_dir = Path(temp_dir)
|
||||
user_count_path = summary_dir / excellent_heatmap_raster_filename(EXCELLENT_CELL_FIELD)
|
||||
# user_count_path = summary_dir / excellent_heatmap_raster_filename(EXCELLENT_CELL_FIELD)
|
||||
competitor_signal_path = summary_dir / competitor_signal_raster_filename()
|
||||
(
|
||||
_,
|
||||
# _, # 原用户量结果
|
||||
competitor_signal_result,
|
||||
_,
|
||||
) = export_market_grid_outputs(
|
||||
@@ -2202,23 +2215,23 @@ def process_summary_grid_outputs(markets, pixel_width, pixel_height, output_dir,
|
||||
summary_market,
|
||||
pixel_width,
|
||||
pixel_height,
|
||||
None,
|
||||
# None, # 原 user_count_path
|
||||
competitor_signal_path,
|
||||
None,
|
||||
max_raster_pixels=SUMMARY_MAX_RASTER_PIXELS,
|
||||
)
|
||||
user_count_result = render_summary_user_count_by_market(
|
||||
(
|
||||
("5G", grid_5g_conn, grid_5g_layer, grid_5g_rtree),
|
||||
("4G", grid_4g_conn, grid_4g_layer, grid_4g_rtree),
|
||||
),
|
||||
markets,
|
||||
pixel_width,
|
||||
pixel_height,
|
||||
user_count_path,
|
||||
SUMMARY_MAX_RASTER_PIXELS,
|
||||
market_user_thresholds,
|
||||
)
|
||||
# user_count_result = render_summary_user_count_by_market(
|
||||
# (
|
||||
# ("5G", grid_5g_conn, grid_5g_layer, grid_5g_rtree),
|
||||
# ("4G", grid_4g_conn, grid_4g_layer, grid_4g_rtree),
|
||||
# ),
|
||||
# markets,
|
||||
# pixel_width,
|
||||
# pixel_height,
|
||||
# user_count_path,
|
||||
# SUMMARY_MAX_RASTER_PIXELS,
|
||||
# market_user_thresholds,
|
||||
# )
|
||||
building_info_path = summary_dir / BUILDING_INFO_OUTPUT_FILENAME
|
||||
shutil.copy2(BUILDING_INFO_GPKG, building_info_path)
|
||||
with open_read_connection(BUILDING_INFO_GPKG) as building_info_conn:
|
||||
@@ -2255,7 +2268,7 @@ def process_summary_grid_outputs(markets, pixel_width, pixel_height, output_dir,
|
||||
remove_file_with_retry(legacy_zip_path)
|
||||
return {
|
||||
"market_code": summary_market.code,
|
||||
"excellent_heatmap_result": rewrite_result_for_zip(user_count_result, zip_path, summary_dir),
|
||||
# "excellent_heatmap_result": rewrite_result_for_zip(user_count_result, zip_path, summary_dir),
|
||||
"competitor_signal_result": rewrite_result_for_zip(
|
||||
competitor_signal_result,
|
||||
zip_path,
|
||||
@@ -2278,7 +2291,7 @@ def main():
|
||||
raise ValueError("GEOMETRY_BATCH_SIZE 必须大于 0")
|
||||
if PROJECT_EXTENT_PADDING_RATIO < 0:
|
||||
raise ValueError("PROJECT_EXTENT_PADDING_RATIO 不能小于 0")
|
||||
validate_smoothing_radius("HEATMAP_SMOOTH_RADIUS", HEATMAP_SMOOTH_RADIUS)
|
||||
# validate_smoothing_radius("HEATMAP_SMOOTH_RADIUS", HEATMAP_SMOOTH_RADIUS)
|
||||
if not 0 <= COMPETITOR_SIGNAL_MOBILE_WEAK_RATIO_MAX <= 100:
|
||||
raise ValueError("COMPETITOR_SIGNAL_MOBILE_WEAK_RATIO_MAX 必须在 0 到 100 之间")
|
||||
if not 0 <= COMPETITOR_SIGNAL_WEAK_RATIO_MIN <= 100:
|
||||
@@ -2302,7 +2315,7 @@ def main():
|
||||
required_files = (
|
||||
MARKET_GPKG,
|
||||
GRID_5G_GPKG,
|
||||
GRID_4G_GPKG,
|
||||
# GRID_4G_GPKG,
|
||||
BUILDING_INFO_GPKG,
|
||||
CELL_DATA_GPKG,
|
||||
GIS_PROJECT_SOURCE,
|
||||
@@ -2315,17 +2328,17 @@ def main():
|
||||
with (
|
||||
open_read_connection(MARKET_GPKG) as market_conn,
|
||||
open_read_connection(GRID_5G_GPKG) as grid_5g_conn,
|
||||
open_read_connection(GRID_4G_GPKG) as grid_4g_conn,
|
||||
# open_read_connection(GRID_4G_GPKG) as grid_4g_conn,
|
||||
open_read_connection(BUILDING_INFO_GPKG) as building_info_conn,
|
||||
):
|
||||
market_layer = resolve_feature_layer(market_conn, MARKET_LAYER)
|
||||
grid_5g_layer = resolve_feature_layer(grid_5g_conn, GRID_5G_LAYER)
|
||||
grid_4g_layer = resolve_feature_layer(grid_4g_conn, GRID_4G_LAYER)
|
||||
# grid_4g_layer = resolve_feature_layer(grid_4g_conn, GRID_4G_LAYER)
|
||||
building_info_layer = resolve_feature_layer(building_info_conn, BUILDING_INFO_LAYER)
|
||||
if (
|
||||
market_layer.srs_id != 4326
|
||||
or grid_5g_layer.srs_id != 4326
|
||||
or grid_4g_layer.srs_id != 4326
|
||||
# or grid_4g_layer.srs_id != 4326
|
||||
):
|
||||
raise ValueError("当前脚本只处理 EPSG:4326 的输入图层")
|
||||
if building_info_layer.srs_id not in BUILDING_INFO_ALLOWED_SRS_IDS:
|
||||
@@ -2334,15 +2347,16 @@ def main():
|
||||
require_columns(
|
||||
grid_5g_conn,
|
||||
grid_5g_layer.table_name,
|
||||
(*CSV_SOURCE_FIELDS, MOBILE_TOTAL_FIELD, MOBILE_WEAK_COVER_FIELD, GRID_ID_FIELD),
|
||||
# (*CSV_SOURCE_FIELDS, MOBILE_TOTAL_FIELD, MOBILE_WEAK_COVER_FIELD, GRID_ID_FIELD),
|
||||
(*CSV_SOURCE_FIELDS, MOBILE_TOTAL_FIELD, MOBILE_WEAK_COVER_FIELD),
|
||||
)
|
||||
grid_4g_required_fields = [GRID_ID_FIELD, EXCELLENT_CELL_FIELD]
|
||||
if CLIP_MODE == "center":
|
||||
grid_4g_required_fields.extend(("longitude", "latitude"))
|
||||
require_columns(grid_4g_conn, grid_4g_layer.table_name, grid_4g_required_fields)
|
||||
# grid_4g_required_fields = [GRID_ID_FIELD, EXCELLENT_CELL_FIELD]
|
||||
# if CLIP_MODE == "center":
|
||||
# grid_4g_required_fields.extend(("longitude", "latitude"))
|
||||
# require_columns(grid_4g_conn, grid_4g_layer.table_name, grid_4g_required_fields)
|
||||
require_columns(building_info_conn, building_info_layer.table_name, ["name"])
|
||||
rtree_name(grid_5g_conn, grid_5g_layer)
|
||||
rtree_name(grid_4g_conn, grid_4g_layer)
|
||||
# rtree_name(grid_4g_conn, grid_4g_layer)
|
||||
rtree_name(building_info_conn, building_info_layer)
|
||||
pixel_width = PIXEL_WIDTH
|
||||
pixel_height = PIXEL_HEIGHT
|
||||
@@ -2367,20 +2381,20 @@ def main():
|
||||
markets = markets[:LIMIT]
|
||||
layer_names = {
|
||||
"grid_5g": grid_5g_layer.table_name,
|
||||
"grid_4g": grid_4g_layer.table_name,
|
||||
# "grid_4g": grid_4g_layer.table_name,
|
||||
"building_info": building_info_layer.table_name,
|
||||
}
|
||||
|
||||
excellent_legend_path = write_excellent_heatmap_legend(OUTPUT_DIR, EXCELLENT_CELL_FIELD)
|
||||
# excellent_legend_path = write_excellent_heatmap_legend(OUTPUT_DIR, EXCELLENT_CELL_FIELD)
|
||||
competitor_signal_legend_path = write_competitor_signal_legend(OUTPUT_DIR)
|
||||
worker_count = max(1, min(MAX_WORKERS, len(markets))) if markets else 1
|
||||
print(f"市场网格数量:{len(markets)}")
|
||||
print(f"并行进程数:{worker_count}")
|
||||
print(f"5G Grid 图层:{layer_names['grid_5g']}")
|
||||
print(f"4G Grid 图层:{layer_names['grid_4g']}")
|
||||
# print(f"4G Grid 图层:{layer_names['grid_4g']}")
|
||||
print(f"BuildingInfo 图层:{layer_names['building_info']}")
|
||||
print(f"像元大小:{pixel_width}, {pixel_height}")
|
||||
print(f"用户量图例:{excellent_legend_path}")
|
||||
# print(f"用户量图例:{excellent_legend_path}")
|
||||
print(f"竟对信号图例:{competitor_signal_legend_path}")
|
||||
|
||||
started_at = perf_counter()
|
||||
@@ -2421,24 +2435,24 @@ def main():
|
||||
summary_grid_result = None
|
||||
if SUMMARY_OUTPUT_ENABLED and markets:
|
||||
print("开始生成全部市场网格汇总 TIF……")
|
||||
market_user_thresholds = {
|
||||
outcome["market_code"]: outcome["excellent_heatmap_result"].get("thresholds")
|
||||
for outcome in outcomes
|
||||
if outcome.get("excellent_heatmap_result")
|
||||
}
|
||||
# market_user_thresholds = {
|
||||
# outcome["market_code"]: outcome["excellent_heatmap_result"].get("thresholds")
|
||||
# for outcome in outcomes
|
||||
# if outcome.get("excellent_heatmap_result")
|
||||
# }
|
||||
summary_grid_result = process_summary_grid_outputs(
|
||||
markets,
|
||||
pixel_width,
|
||||
pixel_height,
|
||||
OUTPUT_DIR,
|
||||
market_user_thresholds,
|
||||
# market_user_thresholds,
|
||||
)
|
||||
print(
|
||||
f"汇总 TIF 完成:{summary_grid_result['zip_result']['output']},"
|
||||
f"耗时 {summary_grid_result['elapsed_seconds']:.1f} 秒"
|
||||
)
|
||||
result_mappings = {
|
||||
"excellent_heatmap_results": "excellent_heatmap_result",
|
||||
# "excellent_heatmap_results": "excellent_heatmap_result",
|
||||
"competitor_signal_results": "competitor_signal_result",
|
||||
"building_info_results": "building_info_result",
|
||||
"cell_data_results": "cell_data_result",
|
||||
@@ -2448,9 +2462,9 @@ def main():
|
||||
summary = {
|
||||
"market_gpkg": str(MARKET_GPKG),
|
||||
"grid_5g_gpkg": str(GRID_5G_GPKG),
|
||||
"grid_4g_gpkg": str(GRID_4G_GPKG),
|
||||
"user_count_grid_id_field": GRID_ID_FIELD,
|
||||
"user_count_merge_rule": "Grid_5G + Grid_4G union by grid20_id and sum mro_total_dl",
|
||||
# "grid_4g_gpkg": str(GRID_4G_GPKG),
|
||||
# "user_count_grid_id_field": GRID_ID_FIELD,
|
||||
# "user_count_merge_rule": "Grid_5G + Grid_4G union by grid20_id and sum mro_total_dl",
|
||||
"building_info_gpkg": str(BUILDING_INFO_GPKG),
|
||||
"cell_data_gpkg": str(CELL_DATA_GPKG),
|
||||
"gis_project_source": str(GIS_PROJECT_SOURCE),
|
||||
|
||||
Binary file not shown.
+59
-12
@@ -1,8 +1,10 @@
|
||||
import tempfile
|
||||
import sqlite3
|
||||
import unittest
|
||||
import xml.etree.ElementTree as ET
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
from contextlib import closing
|
||||
|
||||
import numpy as np
|
||||
import tifffile
|
||||
@@ -112,6 +114,29 @@ class UserCountMergeTest(unittest.TestCase):
|
||||
|
||||
|
||||
class CompetitorSignalTest(unittest.TestCase):
|
||||
def test_grid_export_needs_no_4g_or_user_count_grid_id(self):
|
||||
with closing(sqlite3.connect(":memory:")) as conn, tempfile.TemporaryDirectory() as temp_dir:
|
||||
conn.execute(
|
||||
"create table grid (fid integer primary key, geom blob, mro_total_dl real, "
|
||||
"ssb_rsrp_dl real, rsrp_lt_neg105_dl real, mro_total_yd real, rsrp_lt_neg105_yd real)"
|
||||
)
|
||||
conn.execute("create virtual table grid_rtree using rtree(id, minx, maxx, miny, maxy)")
|
||||
for index, (total, rsrp, weak) in enumerate(((100, -95, 40), (0, None, None), (100, -95, 0))):
|
||||
conn.execute("insert into grid values (?, ?, ?, ?, ?, 100, 10)",
|
||||
(index + 1, box(index, 0, index + 1, 1).wkb, total, rsrp, weak))
|
||||
conn.execute("insert into grid_rtree values (?, ?, ?, 0, 1)", (index + 1, index, index + 1))
|
||||
output = Path(temp_dir) / main.COMPETITOR_SIGNAL_OUTPUT_FILENAME
|
||||
result, csv_result = main.export_market_grid_outputs(
|
||||
conn, main.LayerInfo("grid", "geom", "fid", 4326), "grid_rtree",
|
||||
main.MarketFeature(1, "1-test", "test", box(0, 0, 3, 1)), 1, 1, output, None,
|
||||
)
|
||||
pixels = tifffile.imread(output)
|
||||
self.assertEqual(pixels[0, :, 3].tolist(), [main.HEATMAP_ALPHA, main.HEATMAP_ALPHA, 0])
|
||||
self.assertEqual(pixels[0, 1, :3].tolist(), list(main.COMPETITOR_SIGNAL_RSRP_COLORS[0]))
|
||||
self.assertEqual(result["raster_extent"], [0, 0, 3, 1])
|
||||
self.assertIsNone(csv_result)
|
||||
self.assertEqual([item.name for item in Path(temp_dir).iterdir()], [main.COMPETITOR_SIGNAL_OUTPUT_FILENAME])
|
||||
|
||||
def test_filter_accepts_weak_coverage_or_zero_competitor_samples(self):
|
||||
self.assertTrue(main.competitor_signal_is_eligible(199.0, 1000.0, 1.0, 1.0))
|
||||
self.assertTrue(main.competitor_signal_is_eligible(199.0, 1000.0, None, 0.0))
|
||||
@@ -385,11 +410,12 @@ class QgisProjectTest(unittest.TestCase):
|
||||
canvas = project.find(".//mapcanvas[@name='theMapCanvas']/extent")
|
||||
overview = project.find(".//mapcanvas[@name='mAreaCanvas']/extent")
|
||||
building_layer = project.find(".//projectlayers/maplayer/extent")
|
||||
user_count_layer = next(
|
||||
layer
|
||||
for layer in project.findall(".//projectlayers/maplayer")
|
||||
if layer.findtext("datasource") == f"./{main.USER_COUNT_OUTPUT_FILENAME}"
|
||||
)
|
||||
# user_count_layer = next(
|
||||
# layer
|
||||
# for layer in project.findall(".//projectlayers/maplayer")
|
||||
# if layer.findtext("datasource") == f"./{main.USER_COUNT_OUTPUT_FILENAME}"
|
||||
# )
|
||||
self.assertNotIn(main.USER_COUNT_OUTPUT_FILENAME, updated_xml.decode("utf-8"))
|
||||
competitor_signal_layer = next(
|
||||
layer
|
||||
for layer in project.findall(".//projectlayers/maplayer")
|
||||
@@ -399,8 +425,8 @@ class QgisProjectTest(unittest.TestCase):
|
||||
self.assertEqual(read_extent(canvas), (9, 19, 31, 41))
|
||||
self.assertEqual(read_extent(overview), (100, 100, 200, 200))
|
||||
self.assertEqual(read_extent(building_layer), (10, 20, 30, 40))
|
||||
self.assertEqual(read_extent(user_count_layer.find("extent")), (0, -1, 2, 1))
|
||||
self.assertEqual(read_extent(user_count_layer.find("wgs84extent")), (0, -1, 2, 1))
|
||||
# self.assertEqual(read_extent(user_count_layer.find("extent")), (0, -1, 2, 1))
|
||||
# self.assertEqual(read_extent(user_count_layer.find("wgs84extent")), (0, -1, 2, 1))
|
||||
self.assertEqual(read_extent(competitor_signal_layer.find("extent")), (0, -1, 2, 1))
|
||||
self.assertEqual(read_extent(competitor_signal_layer.find("wgs84extent")), (0, -1, 2, 1))
|
||||
self.assertEqual(result["extent_source"], "building_info")
|
||||
@@ -408,7 +434,8 @@ class QgisProjectTest(unittest.TestCase):
|
||||
self.assertEqual(result["canvas_extent"], [9.0, 19.0, 31.0, 41.0])
|
||||
self.assertFalse(result["includes_cell_data"])
|
||||
|
||||
def test_repository_template_contains_only_two_thematic_rasters(self):
|
||||
# def test_repository_template_contains_only_two_thematic_rasters(self):
|
||||
def test_repository_template_contains_only_competitor_signal(self):
|
||||
self.assertEqual(main.GIS_PROJECT_SOURCE, main.DEFAULT_SOURCE_DIR / "GIS.qgz")
|
||||
with zipfile.ZipFile(main.GIS_PROJECT_SOURCE) as archive:
|
||||
self.assertIsNone(archive.testzip())
|
||||
@@ -436,14 +463,16 @@ class QgisProjectTest(unittest.TestCase):
|
||||
]
|
||||
self.assertEqual(
|
||||
{item.get("name") for item in raster_tree_layers},
|
||||
{"用户量", Path(main.COMPETITOR_SIGNAL_OUTPUT_FILENAME).stem},
|
||||
# {"用户量", Path(main.COMPETITOR_SIGNAL_OUTPUT_FILENAME).stem},
|
||||
{Path(main.COMPETITOR_SIGNAL_OUTPUT_FILENAME).stem},
|
||||
)
|
||||
user_count_tree = next(item for item in raster_tree_layers if item.get("name") == "用户量")
|
||||
self.assertEqual(user_count_tree.get("checked"), "Qt::Unchecked")
|
||||
# user_count_tree = next(item for item in raster_tree_layers if item.get("name") == "用户量")
|
||||
# self.assertEqual(user_count_tree.get("checked"), "Qt::Unchecked")
|
||||
tree_layers = project.findall("./layer-tree-group/layer-tree-layer")
|
||||
self.assertEqual(
|
||||
[item.get("name") for item in tree_layers],
|
||||
["CellData", Path(main.COMPETITOR_SIGNAL_OUTPUT_FILENAME).stem, "用户量", "BuildInfo", "GoogleCN", "必应地图"],
|
||||
# ["CellData", Path(main.COMPETITOR_SIGNAL_OUTPUT_FILENAME).stem, "用户量", "BuildInfo", "GoogleCN", "必应地图"],
|
||||
["CellData", Path(main.COMPETITOR_SIGNAL_OUTPUT_FILENAME).stem, "BuildInfo", "GoogleCN", "必应地图"],
|
||||
)
|
||||
self.assertEqual(tree_layers[-2].get("checked"), "Qt::Checked")
|
||||
self.assertEqual(tree_layers[-1].get("checked"), "Qt::Unchecked")
|
||||
@@ -455,6 +484,24 @@ class QgisProjectTest(unittest.TestCase):
|
||||
self.assertEqual(cell_layer.findtext("datasource"), "./CellData.gpkg|layername=_20260701")
|
||||
self.assertEqual(cell_layer.find("renderer-v2").get("type"), "categorizedSymbol")
|
||||
|
||||
def test_market_and_summary_projects_have_no_user_count_layer(self):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
for include_cell_data in (False, True):
|
||||
with self.subTest(include_cell_data=include_cell_data):
|
||||
output = Path(temp_dir) / f"GIS-{include_cell_data}.qgz"
|
||||
main.copy_gis_project_to_market(
|
||||
main.GIS_PROJECT_SOURCE, output,
|
||||
main.MarketFeature(1, "1-test", "test", box(0, 0, 1, 1)),
|
||||
None, include_cell_data=include_cell_data,
|
||||
)
|
||||
with zipfile.ZipFile(output) as archive:
|
||||
xml = archive.read("GIS.qgs")
|
||||
self.assertNotIn(main.USER_COUNT_OUTPUT_FILENAME, xml.decode("utf-8"))
|
||||
names = [item.get("name") for item in ET.fromstring(xml).iter("layer-tree-layer")]
|
||||
self.assertEqual("CellData" in names, include_cell_data)
|
||||
self.assertIn(Path(main.COMPETITOR_SIGNAL_OUTPUT_FILENAME).stem, names)
|
||||
self.assertEqual(names[-2:], ["GoogleCN", "必应地图"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user