H3 Polyfill 与行政区边界处理
1. 问题背景
在使用 Uber H3 进行行政区划离散化时,核心问题是:
如何将连续的 polygon(行政区)映射为离散的 hex(H3 索引),同时处理边界误差?
2. Polyfill 的本质
输入
- Polygon(GeoJSON 格式)
- Resolution(0 ~ 15)
输出
Set
例如:
["8928308280fffff", "8928308280bffff", ...]
3. 默认语义(非常关键)
hex ∈ polyfill ⇔ centroid(hex) ∈ polygon
即:
是否包含由 hex 中心点决定
4. Polyfill 的性质
| 属性 | 是否成立 |
|---|---|
| 唯一性 | ✅ |
| 无重复 | ✅ |
| 完整覆盖 polygon | ❌ |
| 不越界 | ✅ |
| 精确表达边界 | ❌ |
5. 边界问题本质
1. 漏(False Negative)
hex 与 polygon 相交
但 centroid 在 polygon 外 → 被丢弃
2. 不存在重复
若 polygon 不重叠:
polyfill(A) ∩ polyfill(B) = ∅
6. 是否完全覆盖?
结论:
❌ 不完全覆盖
✅ 是 polygon 的“内近似(inner approximation)”
7. 严格边界需求
必须引入:
Point-in-Polygon(PIP)
8. 最优工程方案(推荐)
两阶段模型
Stage 1: H3 粗过滤
Stage 2: PIP 精确判断
9. Core / Boundary 优化(工业标准)
分类:
- core:hex 完全在 polygon 内
- boundary:hex 与 polygon 相交
查询逻辑:
if hex ∈ core:
直接返回
else:
PIP 判断
10. 如何构建 core
方法 1(推荐):
- polyfill + kRing
- hex 顶点全部在 polygon 内 → core
11. H3 官方能力(重要)
支持 containment mode:
- CENTER(默认)
- FULL(完全包含)
- OVERLAPPING(相交)
示例:
h3shape_to_cells_experimental(..., contain='full')
12. 工程建议
生产环境推荐:
polyfill(center)
- 自定义 core 判断
- boundary PIP
避免直接依赖 experimental API
13. 最终结论
- polyfill 是“中心点分类”,不是几何覆盖
- hex 不等于 polygon 子集
- 严格边界必须依赖几何计算
- 最优方案:core + boundary + PIP
14. 一句话总结
H3 是空间索引工具,不是精确几何表达工具。
浙公网安备 33010602011771号