feat: 输出渠道点图层并匹配渠道点落入的 AOI
This commit is contained in:
@@ -17,5 +17,5 @@
|
||||
|
||||
| 工具 | 说明 | 运行 | 数据源 |
|
||||
| --- | --- | --- | --- |
|
||||
| AoiChannel | AOI 与渠道 2 公里范围交叠 | `python Scripts/AoiChannel.py` | `Source/AOI/`、`Source/实体渠道匹配表/` |
|
||||
| AoiChannel | AOI 与渠道 2 公里交叠,并匹配渠道点落入的 AOI | `python Scripts/AoiChannel.py` | `Source/AOI/`、`Source/实体渠道匹配表/` |
|
||||
| AoiSample | 按 AOI 统计各月移动采样点占比 | `python Scripts/AoiSample.py` | `Source/AOI/`、`Source/众测数据/Grids/` |
|
||||
|
||||
+32
-1
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""AOI 与渠道 2 公里范围的交叠匹配。"""
|
||||
"""AOI 与渠道 2 公里范围交叠,并匹配渠道点落入的 AOI。"""
|
||||
|
||||
import json
|
||||
import os
|
||||
@@ -303,6 +303,33 @@ def overlap_tables(aoi, channels):
|
||||
return table[columns], channel_aoi[channel_columns], stored
|
||||
|
||||
|
||||
def point_aoi_table(aoi, channels):
|
||||
columns = [*CHANNEL_FIELDS, "AOI唯一标签", "AOI名称"]
|
||||
if aoi.empty or channels.empty:
|
||||
return pd.DataFrame(columns=columns)
|
||||
tree = STRtree(aoi.geometry.to_numpy())
|
||||
pairs = tree.query(channels.geometry.to_numpy(), predicate="intersects")
|
||||
if pairs.shape[1] == 0:
|
||||
return pd.DataFrame(columns=columns)
|
||||
channel_index = pairs[0]
|
||||
aoi_index = pairs[1]
|
||||
table = pd.DataFrame({
|
||||
"渠道编码": channels["渠道编码"].to_numpy()[channel_index],
|
||||
"全网渠道编码": channels["全网渠道编码"].to_numpy()[channel_index],
|
||||
"渠道名称": channels["渠道名称"].to_numpy()[channel_index],
|
||||
"所属渠道管理员工姓名": channels["所属渠道管理员工姓名"].to_numpy()[channel_index],
|
||||
"地理经度": channels["地理经度"].to_numpy()[channel_index],
|
||||
"地理纬度": channels["地理纬度"].to_numpy()[channel_index],
|
||||
"AOI唯一标签": aoi["AOI唯一标签"].to_numpy()[aoi_index],
|
||||
"AOI名称": aoi["AOI名称"].to_numpy()[aoi_index],
|
||||
})
|
||||
return table.sort_values(["渠道编码", "AOI唯一标签"], ascending=[True, True], kind="mergesort")
|
||||
|
||||
|
||||
def channel_points(channels):
|
||||
return gpd.GeoDataFrame(channels[CHANNEL_LAYER_FIELDS], geometry=channels.geometry, crs=channels.crs)
|
||||
|
||||
|
||||
def write_gpkg(layer, path, name):
|
||||
layer.to_file(path, layer=name, driver="GPKG", spatial_index=True, encoding="UTF-8")
|
||||
with sqlite3.connect(path) as connection:
|
||||
@@ -394,19 +421,23 @@ def main():
|
||||
aoi, aoi_blank, aoi_removed, aoi_invalid = read_aoi(aoi_path)
|
||||
channels, channel_blank, channel_removed, channel_invalid = read_channels(channel_path)
|
||||
aoi_channel, channel_aoi, circles = overlap_tables(aoi, channels)
|
||||
contained = point_aoi_table(aoi, channels)
|
||||
staging = temporary / "out"
|
||||
staging.mkdir()
|
||||
write_gpkg(aoi, staging / "AOI.gpkg", "AOI")
|
||||
write_gpkg(circles, staging / "Channel.gpkg", "Channel")
|
||||
write_gpkg(channel_points(channels), staging / "ChannelPoint.gpkg", "ChannelPoint")
|
||||
with pd.ExcelWriter(staging / "result.xlsx", engine="openpyxl") as writer:
|
||||
aoi_channel.to_excel(writer, sheet_name="AOI-渠道", index=False)
|
||||
channel_aoi.to_excel(writer, sheet_name="渠道-AOI", index=False)
|
||||
contained.to_excel(writer, sheet_name="渠道-单点-AOI", index=False)
|
||||
output = ROOT / "Output" / TOOL / stamp
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.move(staging, output)
|
||||
print(f"AOI {len(aoi)},丢弃空几何 {aoi_blank},去掉重复 {aoi_removed},无效几何 {aoi_invalid}")
|
||||
print(f"渠道 {len(channels)},丢弃空坐标 {channel_blank},去掉重复 {channel_removed},无效坐标 {channel_invalid}")
|
||||
print(f"交叠 {len(aoi_channel)}")
|
||||
print(f"渠道点落入 {len(contained)}")
|
||||
print(f"输出 {relative(output)}")
|
||||
finally:
|
||||
cleanup(temporary)
|
||||
|
||||
+1
-1
@@ -9,6 +9,6 @@
|
||||
| 工具 | 数据源路径 | 格式摘要 | 详细说明 |
|
||||
| --- | --- | --- | --- |
|
||||
| AoiChannel | `Source/AOI/全量AOI清单_202609.csv` | CSV,WKT 多边形 | [AoiChannel](../docs/数据源/AoiChannel.md) |
|
||||
| AoiChannel | `Source/实体渠道匹配表/【26年11月11日】实体渠道匹配表v2s_渠道信息.xlsx` | xlsx,经纬度点,生成 2 公里圆 | [AoiChannel](../docs/数据源/AoiChannel.md) |
|
||||
| AoiChannel | `Source/实体渠道匹配表/【26年11月11日】实体渠道匹配表v2s_渠道信息.xlsx` | xlsx,经纬度点,生成 2 公里圆并保留原始点 | [AoiChannel](../docs/数据源/AoiChannel.md) |
|
||||
| AoiSample | `Source/AOI/全量AOI清单_202609.csv` | CSV,WKT 多边形 | [AoiSample](../docs/数据源/AoiSample.md) |
|
||||
| AoiSample | `Source/众测数据/Grids/4G/`、`Source/众测数据/Grids/5G/` | 按月 GPKG 栅格,采样点数量 | [AoiSample](../docs/数据源/AoiSample.md) |
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
- 命名格式:`实体渠道匹配表*.xlsx`
|
||||
- 数据格式:xlsx。使用含下列字段的工作表,当前是 Sheet1。
|
||||
- 字段:渠道编码、渠道类型、全网渠道编码、渠道名称、星级、所属渠道管理员工姓名、地理经度、地理纬度、连锁、头腰尾标识
|
||||
- 说明:经纬度是十进制度。经度或纬度为空的记录先丢弃。其余记录提取这些字段后去重。每个点生成半径 2 公里的圆。渠道图层保留渠道编码、渠道类型、全网渠道编码、渠道名称、星级、地理经度、地理纬度、连锁、头腰尾标识。样式为无填充、红色边线,保存在 `Scripts/styles/Channel.qml`。交叠面积单位是平方米。
|
||||
- 说明:经纬度是十进制度。经度或纬度为空的记录先丢弃。其余记录提取这些字段后去重。每个点生成半径 2 公里的圆,同时保留原始点。渠道圆图层和渠道点图层都保留渠道编码、渠道类型、全网渠道编码、渠道名称、星级、地理经度、地理纬度、连锁、头腰尾标识。圆图层样式为无填充、红色边线,保存在 `Scripts/styles/Channel.qml`。交叠面积单位是平方米。渠道点落入 AOI 时,一个点可以对应多个 AOI。
|
||||
|
||||
Reference in New Issue
Block a user