ctc_poc2026/target_table_skills/td_building_grid_m.md

42 lines
1.7 KiB
Markdown
Raw Normal View History

# Skill: td_building_grid_m 楼宇栅格桥接表计算指导 (严谨矩阵版)
## 1. 实现目标
在 PostGIS 中建立楼宇实体与 20m 栅格单元的空间映射,并按维度进行结构化膨胀。
## 2. 计算拓扑 (Topology)
- **计算执行环境****PostGIS (PG)**。
- **基本架构**
1. 空间关联判定。
2. 利用 CROSS JOIN 对每个 (Building, Grid) 对进行维度膨胀(对齐事实表结构)。
## 3. 字段映射矩阵 (The Matrix)
| 目标字段 | 类型 | 取值逻辑 | 缺省处理 |
| :--- | :--- | :--- | :--- |
| **`building_id`** | BIGINT | `td_building.building_id` | - |
| **`regionid`** | BIGINT | `td_grid.regionid` | - |
| **`provincecode`** | INTEGER | `td_building.provincecode` | - |
| **`citycode`** | INTEGER | `td_building.citycode` | - |
| **`districtcode`** | INTEGER | `td_building.districtcode` | - |
| **`indoor_flag`** | SMALLINT | **CROSS JOIN 生成**`(-1, 0, 1)` | - |
| **`data_type`** | INTEGER | **CROSS JOIN 生成**`(-1, 1, 2)` | - |
## 4. 关键计算原语 (Primitives)
- **空间关联**
```sql
ST_Contains(b.aoi_geom, ST_SetSRID(ST_MakePoint(g.center_lon, g.center_lat), 4326))
```
- **关联加速 (强制)**:必须显式包含行政区划三级对齐:
```sql
ON b.provincecode = g.provincecode AND b.citycode = g.citycode AND b.districtcode = g.districtcode
```
- **维度膨胀**
```sql
CROSS JOIN (SELECT unnest(ARRAY[-1, 0, 1]) AS flag)
```
## 5. 存储与优化规范
- 计算完成后同步至 PG 侧 `td_building_grid_m` 表。
- **索引**:对 `building_id`, `regionid`, `indoor_flag` 建立复合 B-TREE 索引。
- 必须同步一份回 Hive 侧PARQUET 格式),支撑指标聚合。