feat: 注释停用市场用户量图层
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user