Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
sutpc
/
heatmap
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3d9e6f07
authored
Nov 03, 2026
by
liimin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化导入数据清洗算法
1 parent
e7c11cf3
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
687 additions
and
42 deletions
.workbuddy/memory/2026-11-03.md
public/geo/shenzhen-offshore-corridors.geojson
src/features/heatmap/aggregate/types.ts
src/features/heatmap/data/applyExclusions.ts
src/features/heatmap/data/cleanRules.ts
src/features/heatmap/data/ingestCore.ts
src/features/heatmap/data/offshore.test.ts
src/features/heatmap/geo/districtShapes.ts
src/features/heatmap/geo/offshoreCorridors.test.ts
src/features/heatmap/geo/offshoreCorridors.ts
src/layout/ImportControl.tsx
.workbuddy/memory/2026-11-03.md
View file @
3d9e6f0
...
@@ -62,3 +62,63 @@
...
@@ -62,3 +62,63 @@
4.
**命中案件去 AI 味**
(按 skill + design-tokens 重做):用户嫌渐变 / 阴影 / hover 上浮 / 竖条 / pill / 箭头「AI 味太浓」。改成标准企业 KPI 数据卡:白底 + 1px
`--hm-divider`
描边 + 8px 圆角 + 12/16px padding,无渐变、无阴影、无 transform、无 active 缩放;两行规整布局(第一行「命中案件 / 占全量 xx%」12px 次文,第二行 30px/600 主色数值 + 12px「起」+ 右端纯文字「查看清单」);hover 只换 border-color + 极浅底 120ms;主色仅用于数值与文本按钮。删
`.hm-hero__accent`
/
`__arrow`
/
`:active`
与相应 JSX;
`ArrowRightOutlined`
import 保留(面板其他「查看全部」仍在用)。顺手修掉 hero 的过时 title(还写着「按区、街道、关键词收窄」,抽屉筛选早已只留报案时间)。
4.
**命中案件去 AI 味**
(按 skill + design-tokens 重做):用户嫌渐变 / 阴影 / hover 上浮 / 竖条 / pill / 箭头「AI 味太浓」。改成标准企业 KPI 数据卡:白底 + 1px
`--hm-divider`
描边 + 8px 圆角 + 12/16px padding,无渐变、无阴影、无 transform、无 active 缩放;两行规整布局(第一行「命中案件 / 占全量 xx%」12px 次文,第二行 30px/600 主色数值 + 12px「起」+ 右端纯文字「查看清单」);hover 只换 border-color + 极浅底 120ms;主色仅用于数值与文本按钮。删
`.hm-hero__accent`
/
`__arrow`
/
`:active`
与相应 JSX;
`ArrowRightOutlined`
import 保留(面板其他「查看全部」仍在用)。顺手修掉 hero 的过时 title(还写着「按区、街道、关键词收窄」,抽屉筛选早已只留报案时间)。
验证:tsc 0 错误 / vitest 412 passed (30 files) /
`vite build --emptyOutDir=false`
成功 / ESLint 0 error / Prettier 全通过。未新增测试(同第三轮理由)。
验证:tsc 0 错误 / vitest 412 passed (30 files) /
`vite build --emptyOutDir=false`
成功 / ESLint 0 error / Prettier 全通过。未新增测试(同第三轮理由)。
## 第五轮:`shenzhen-land.geojson` 坐标系查证 + 近海剔除方案(只查证与方案,未改代码)
超人追问
`public/geo/shenzhen-land.geojson`
是高德点还是 GPS 原始点(他记得是从 datav 下的)。
### 查证结论(硬证据,推翻「datav 下载」的记忆)
1.
**它根本不是 datav 数据,是 Natural Earth 10m land,WGS-84。**
-
`.tmp/ne_land.json`
顶层
`"name":"ne_10m_land"`
、
`"crs":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"}`
。
-
掩膜 823 个顶点里
**800 个与 NE 顶点 6 位小数逐点完全重合**
,剩下 23 个全部落在
`x=113.45 / x=114.85 / y=22.25 / y=23.15`
四条边上(bbox 裁剪插入的交点)。
-
`.tmp/sz-land.json`
与
`public/geo/shenzhen-land.geojson`
**字节完全相同**
(
`cmp`
通过),生成链 2026-11-02 17:09→17:11。
-
**唯一加工 = bbox 矩形裁剪 `[113.45,22.25]–[114.85,23.15]`,无任何坐标系变换。**
2.
**datav 下的是另一份 `public/geo/shenzhen.geojson`**
:
`adcode`
/
`acroutes`
/
`childrenNum`
/
`centroid`
/
`subFeatureIndex`
全是 DataV.GeoAtlas schema,9 个区(440303–440311,无大鹏新区)。datav 属阿里系走高德 → GCJ-02。
3.
裁框远大于深圳(北到 23.15 ≈ 增城/博罗,西到 113.45 ≈ 中山/珠海),所以掩膜
**含东莞/广州/香港/中山陆地**
→
`offshoreVerdict`
对邻市陆地点返回
`onLand=true`
。当前设计下这是对的(归属交给 C 类地址判定),但意味着这份掩膜
**只能答「在不在水上」,答不了「在不在深圳」**
。
### 关键发现:真正的瓶颈不是坐标系,是掩膜精度
`classifyOffshore`
已经做了 GCJ-02→WGS-84 归一化,坐标系层没问题。问题在掩膜分辨率:
**NE 10m land 在深圳段相邻顶点间距:p10 537m / 中位 1206m / p75 1776m / p90 2674m / 最大 6986m,平均 1464m;61.6% 的边 >1km,21% >2km。**
→ 岸线被简化到 km 量级,
`distM`
这个数自身误差就在几百米~1km。小于 1km 的岸线特征(码头/突堤/小海湾/填海角/跨海引桥)在掩膜里不存在。深圳恰是填海最狠的城市(前海、大铲湾、机场西、深圳湾超总)。
ASCII 渲染确认大尺度是对的(珠江口/深圳湾/大鹏湾/大亚湾都能分出,香港算陆地),但西部海岸带细看有 km 级锯齿与可疑碎块。
### 掩膜精度实测(OSM 岸线 vs NE 掩膜,硬数)
已抓到 OSM
`natural=coastline`
深圳周边 1461 条 / 65769 顶点(
`.tmp/osm_coast_good.json`
,对比脚本
`.tmp/_cmp2.mjs`
/
`_cmp3.mjs`
)。
**OSM 岸线点到 NE 岸线的距离**
:
-
**大陆岸线(n=29987)**
:p10 40m / p25 112m /
**中位 259m**
/ p75 680m / p90 6005m;45% >300m、31% >500m、19% >1km。
-
**岛屿岸线(n=12475)**
:中位 1642m,60% >1km →
**NE 基本没有珠江口/香港的离岛**
(内伶仃、大铲、香港离岛等),岛上的点会被判「落水」。
-
**分区(0.1° 格中位偏差)**
:深圳
**东部基岩海岸**
(114.3–114.5 / 22.4–22.6)只有
**90–155m**
;
**西部填海区**
(113.8–114.0 / 22.5–22.6)
**494–810m**
→ 印证填海区 NE 落后 500–650m。最好的格 113.9/22.5 = 90m,最差的深圳格 114.0/22.5 = 810m。
-
**结论:D(近岸带阈值)取 1000m**
,能覆盖西部填海区 500–650m 的中位偏差与局部 km 级长尾;取 300/500m 会误杀填海区与岸边合法点。
-
踩坑:第一版距离函数漏乘
`rad`
(度数当弧度用),结果大了 57.3 倍,
`proj`
必须先自检「0.001° 纬 ≈ 111m」。
### 方案(已提交超人,待他定是否落地)
-
**量级**
:42,806 条里坐标在深圳行政界外仅 23 条(0.05%),其中 21 条是
**合法跨海点**
(深中通道西人工岛等)→ 真漂移点只有个位数到几十条。
-
**核心判断:不能用「距岸距离」单独当判据**
—— 深中通道 24km、深圳湾大桥 5.5km,任何距离阈值都会误杀。正确判据 = 「不在陆地」∩「不在任何海上合法构筑物上」→ 才是漂移点。
-
**S1(立刻)**
:
`OFFSHORE`
按
`distM`
拆两档(用
`1<<12`
),
`OFFSHORE_NEAR`
(≤D,只标记不剔)/
`OFFSHORE_FAR`
(>D,默认剔除)。
**D 必须拿真实数据跑 distM 直方图看拐点定,不能拍脑袋**
;按掩膜误差预估落在 1–2km。
-
**S2(真解法)**
:拉 OSM 重做高精度掩膜 + 生成「海上合法走廊」白名单(
`man_made=pier/breakwater`
、跨海高速水面段、人工岛),点落在走廊缓冲 30m 内即合法。
-
**S3**
:修
`offshoreVerdict`
的 bbox 守卫(现在「覆盖区外即按陆地」,南边 22.25 以下海域会漏判;掩膜换成只盖深圳后洞更大)→ 改成「无法判定,不标不剔」;
`ensureLandMask()`
失败静默降级到行政区边界 = 整类失效(行政区边界抓不到海上点,
`offshore.test.ts`
有钉死对照),应在导入报告里显式提示。
### 环境事实(联网)
Overpass 在本机极不稳定:
`overpass-api.de`
POST 不带 UA → 406;带 UA
**偶发成功(4.5MB / 8 分钟)**
,也常 502;
`kumi`
/
`private.coffee`
一律超时;
`overpass.osm.ch`
是瑞士抽取,深圳查询恒 0 条。
**要拉 OSM 就走 `osm-china-extract` 技能(瓦片 + 断点缓存 + 端点容灾),不要直连。**
分析脚本已备:
`.tmp/_cmp_coast.mjs`
(OSM 岸线点到 NE 岸线距离分布)。
---
## S2 海上合法走廊 · 已落地(2026-11-03)
S1/S3 此前已落地(OFFSHORE 拆 OFFSHORE_NEAR/OFFSHORE_FAR 两档,均 defaultOn=false 默认不剔除;bbox 守卫改「无法判定不标不剔」;陆地掩膜降级在报告 warnings 显式提示)。本日落地 S2。
### 关键决策:不直连 OSM,改用离线策展白名单
-
本沙箱
**出站网络被封**
(curl Overpass 返回空、exit 0),且浏览器内直连 Overpass 有 CORS/限流/宕机风险。
-
走廊做成
**随仓库提交的静态 GeoJSON**
`public/geo/shenzhen-offshore-corridors.geojson`
(WGS-84,与陆地掩膜同系),运行期同源静态 fetch 一次(无
`osm-china-extract`
技能也不影响,可审计)。增删结构改这份文件即可。
-
坐标
**来自真实数据反推**
:用生产
`classifyOffshore`
跑真实 9 月清单(42,806 行),取全部 60 条 FAR + 535 条 NEAR 落水点,按地址+坐标聚类认出真实合法结构后策展,而非凭记忆猜坐标。
### 落点(真实数据验证)
-
远海档 FAR 60 条
**全部被豁免标记**
(仍 FAR=0):深中通道西人工岛/深中隧道 18、盐田国际集装箱码头 16、深圳湾公园/滨海大道/后海湾 121(含近岸档合法点)、前海·妈湾·大铲湾港区 116、宝安西部填海区 50、广深沿江高速西部海岸高架 10、孖洲岛 1。
-
近岸档 NEAR 由 535 →
**263**
仍标(272 条近岸合法结构被走廊豁免;剩 263 条是掩膜 km 级精度的陆上误报,属预期残留,仍默认不剔除)。
-
流程:
`geo/offshoreCorridors.ts`
(parseCorridors + pointInLegalCorridor 米↔度投影命中 + ensureLegalCorridors 容灾)+
`cleanRules.classifyOffshore`
增第 4 参
`corridors`
命中即 flag=0 回写
`corridor`
名 +
`ingestCore`
生产路径传入并在
`report.warnings`
显式说明豁免条数。容灾:拉不到 →
`legalCorridors()`
返回 null → 整道跳过,退化成 S1/S3,不卡导入。
### 验证
-
`tsc --noEmit`
0 错;
`vitest run`
**423 passed(31 文件,含新增 offshoreCorridors.test.ts 11 例)**
。临时诊断脚本已删。
### 留口(未做)
-
NEAR 残留 263 条陆上误报(掩膜精度,非走廊能救)→ 真解法是高精度岸线,待联网走 OSM 重做掩膜时一并处理。
-
走廊 buffer 偏 generous(700m~3km),因豁免只影响「默认不剔除」清单去噪,过度缓冲最坏也只是把近旁真漂移点也免标(仍默认保留),风险可控。
public/geo/shenzhen-offshore-corridors.geojson
0 → 100644
View file @
3d9e6f0
{
"type": "FeatureCollection",
"name": "深圳海上合法走廊(跨海构筑物白名单)",
"description": "已知的合法跨海 / 近岸构筑物,落水判定命中即豁免标记。坐标系 WGS-84,与陆地掩膜同系。增删结构改这份文件即可。",
"features": [
{
"type": "Feature",
"properties": { "name": "深中通道(含西人工岛 / 深中隧道)", "bufferM": 700 },
"geometry": {
"type": "LineString",
"coordinates": [
[113.792, 22.631],
[113.800, 22.605],
[113.801, 22.589],
[113.785, 22.578],
[113.770, 22.571],
[113.745, 22.553]
]
}
},
{
"type": "Feature",
"properties": { "name": "盐田国际集装箱码头", "bufferM": 2200 },
"geometry": {
"type": "Point",
"coordinates": [114.2832, 22.5674]
}
},
{
"type": "Feature",
"properties": { "name": "深圳湾(深圳湾公园 / 滨海大道 / 后海湾)", "bufferM": 1500 },
"geometry": {
"type": "LineString",
"coordinates": [
[114.035, 22.498],
[114.000, 22.512],
[113.990, 22.519],
[113.975, 22.519],
[113.962, 22.510],
[113.965, 22.488]
]
}
},
{
"type": "Feature",
"properties": { "name": "前海·妈湾·大铲湾港区", "bufferM": 2600 },
"geometry": {
"type": "Point",
"coordinates": [113.872, 22.527]
}
},
{
"type": "Feature",
"properties": { "name": "孖洲岛", "bufferM": 1500 },
"geometry": {
"type": "Point",
"coordinates": [113.850, 22.496]
}
},
{
"type": "Feature",
"properties": { "name": "宝安西部填海区(海洋新城 · 会展 · 宝安综合港)", "bufferM": 3000 },
"geometry": {
"type": "Point",
"coordinates": [113.763, 22.690]
}
},
{
"type": "Feature",
"properties": { "name": "广深沿江高速(西部海岸高架)", "bufferM": 900 },
"geometry": {
"type": "LineString",
"coordinates": [
[113.792, 22.631],
[113.800, 22.612],
[113.810, 22.585],
[113.825, 22.555],
[113.845, 22.530],
[113.862, 22.505],
[113.872, 22.490]
]
}
}
]
}
src/features/heatmap/aggregate/types.ts
View file @
3d9e6f0
...
@@ -206,7 +206,8 @@ export type CleanClassKey =
...
@@ -206,7 +206,8 @@ export type CleanClassKey =
|
'MISSING'
|
'MISSING'
|
'MISSING_PARTIAL'
|
'MISSING_PARTIAL'
|
'OUTSIDE'
|
'OUTSIDE'
|
'OFFSHORE'
|
'OFFSHORE_NEAR'
|
'OFFSHORE_FAR'
|
'ISO_200'
|
'ISO_200'
|
'ISO_500'
|
'ISO_500'
|
'ISO_1000'
|
'ISO_1000'
...
@@ -296,6 +297,12 @@ export interface ImportReport {
...
@@ -296,6 +297,12 @@ export interface ImportReport {
* 可选:旧导入没有这一段。
* 可选:旧导入没有这一段。
*/
*/
attrSources
?:
AttrSource
[];
attrSources
?:
AttrSource
[];
/**
* 导入过程中的非致命提示(不影响解析,但导入人应看到)。
* 例:陆地掩膜未就绪、落水判定已降级到行政区边界(抓不到沿海水域),这一条就写在这里,
* 界面在报告顶部用一行提示,避免「为什么海上点没被标出来」这类疑问。
*/
warnings
?:
string
[];
}
}
/** ImportReport.attrSources 的一项:一个车辆属性列的取数来源 */
/** ImportReport.attrSources 的一项:一个车辆属性列的取数来源 */
...
...
src/features/heatmap/data/applyExclusions.ts
View file @
3d9e6f0
...
@@ -27,7 +27,8 @@ export const FLAG_OF_KEY: Record<CleanClassKey, number> = {
...
@@ -27,7 +27,8 @@ export const FLAG_OF_KEY: Record<CleanClassKey, number> = {
MISSING
:
FLAG
.
MISSING
,
MISSING
:
FLAG
.
MISSING
,
MISSING_PARTIAL
:
FLAG
.
MISSING_PARTIAL
,
MISSING_PARTIAL
:
FLAG
.
MISSING_PARTIAL
,
OUTSIDE
:
FLAG
.
OUTSIDE
,
OUTSIDE
:
FLAG
.
OUTSIDE
,
OFFSHORE
:
FLAG
.
OFFSHORE
,
OFFSHORE_NEAR
:
FLAG
.
OFFSHORE_NEAR
,
OFFSHORE_FAR
:
FLAG
.
OFFSHORE_FAR
,
ISO_200
:
FLAG
.
ISO_200
,
ISO_200
:
FLAG
.
ISO_200
,
ISO_500
:
FLAG
.
ISO_500
,
ISO_500
:
FLAG
.
ISO_500
,
ISO_1000
:
FLAG
.
ISO_1000
,
ISO_1000
:
FLAG
.
ISO_1000
,
...
...
src/features/heatmap/data/cleanRules.ts
View file @
3d9e6f0
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
import
{
metersPerDegLng
,
M_PER_DEG_LAT
}
from
'../geo/polygon'
;
import
{
metersPerDegLng
,
M_PER_DEG_LAT
}
from
'../geo/polygon'
;
import
{
gcj02ToWgs84
}
from
'../geo/coord'
;
import
{
gcj02ToWgs84
}
from
'../geo/coord'
;
import
{
offshoreVerdict
,
type
NamedPolys
}
from
'../geo/districtShapes'
;
import
{
offshoreVerdict
,
type
NamedPolys
}
from
'../geo/districtShapes'
;
import
{
pointInLegalCorridor
,
type
CorridorFeature
}
from
'../geo/offshoreCorridors'
;
import
{
ROAD_UNRESOLVED
}
from
'../aggregate/dims'
;
import
{
ROAD_UNRESOLVED
}
from
'../aggregate/dims'
;
import
{
UNRESOLVED_LABEL
}
from
'../aggregate/types'
;
import
{
UNRESOLVED_LABEL
}
from
'../aggregate/types'
;
import
type
{
CleanClassKey
,
CleanSample
}
from
'../aggregate/types'
;
import
type
{
CleanClassKey
,
CleanSample
}
from
'../aggregate/types'
;
...
@@ -92,14 +93,21 @@ export const FLAG = {
...
@@ -92,14 +93,21 @@ export const FLAG = {
*/
*/
SMALL
:
1
<<
8
,
SMALL
:
1
<<
8
,
/**
/**
* 坐标落水 / 域外
:出险地址写的是深圳辖区,坐标却不在任何深圳行政区陆域多边形内
* 坐标落水 / 域外
(近岸档):出险地址写的是深圳辖区,坐标却不在任何深圳行政区陆域多边形内,
*
(飘到了海上或市域外)。与 C 类(邻市,纯地址文本)互补、不重叠 —— 这里只回答
*
但离最近陆界 ≤ OFFSHORE_FAR_DIST_M(1000m)。这一档**大部分是误报**:深圳是全国填海最狠的城市
*
「坐标在不在深圳陆域」,绝不反推「这条是邻市」(旧版正是拿坐标判邻市才把凤岗镇误判成深圳)。
*
(前海、大铲湾、机场西、深圳湾超总),这些填海区 Natural Earth 10m 陆地掩膜根本没有;
*
判定靠 `geo/districtShapes.ts` 的 `offshoreVerdict`(射线法 + 距区界距离),见那里的大段注释
。
*
掩膜自身在深圳段也是 km 级精度(中位偏差 259m、西部填海区 500–810m),近岸点极易被判反
。
*
用第 11 位:上面 0/1/2 留给可能的预留,3~10 已被 OUTSIDE/ISO/SPARSE/SPARSE_STREET/SMALL 占住,
*
码头、突堤、滨海公园同理。所以它只标记、**默认不剔除**,交给导入人逐条确认。
*
这一位落在「高度」区间,和 SMALL 同段,Uint16 还有 4 位富余
。
*
用第 11 位
。
*/
*/
OFFSHORE
:
1
<<
11
,
OFFSHORE_NEAR
:
1
<<
11
,
/**
* 坐标落水 / 域外(远海档):离最近陆界 > OFFSHORE_FAR_DIST_M(1000m)。
* 这一档才更像真问题:深中通道西人工岛(离岸 ~6km)、孖洲岛(~2.3km)这类跨海构筑物,
* 或坐标真实漂移到了海上。仍**默认不剔除**,但比近岸档更值得逐条复核。
* 用第 12 位(Uint16 还有 3 位富余)。
*/
OFFSHORE_FAR
:
1
<<
12
,
}
as
const
;
}
as
const
;
/** 孤立点三档半径(米),与 FLAG.ISO_* 一一对应 */
/** 孤立点三档半径(米),与 FLAG.ISO_* 一一对应 */
...
@@ -389,23 +397,44 @@ function isShenzhenWord(s: string): boolean {
...
@@ -389,23 +397,44 @@ function isShenzhenWord(s: string): boolean {
* `shapes` 是 **WGS-84**(Natural Earth)。两套系差 ~500m,必须先把案件点归一化到 WGS-84
* `shapes` 是 **WGS-84**(Natural Earth)。两套系差 ~500m,必须先把案件点归一化到 WGS-84
* 再比,否则近岸点会被判反(岸上误杀、海上漏抓)。转换只在这里发生一次,几何判定保持纯 WGS-84。
* 再比,否则近岸点会被判反(岸上误杀、海上漏抓)。转换只在这里发生一次,几何判定保持纯 WGS-84。
*/
*/
/** 离岸两档的分界距离(米):≤ 此值判「近岸」,> 此值判「远海」。值来自真实数据 distM 直方图 + 掩膜精度实测 */
export
const
OFFSHORE_FAR_DIST_M
=
1000
;
export
function
classifyOffshore
(
export
function
classifyOffshore
(
lng
:
number
,
lng
:
number
,
lat
:
number
,
lat
:
number
,
shapes
:
NamedPolys
[]
|
null
,
shapes
:
NamedPolys
[]
|
null
,
):
{
flag
:
number
;
note
:
string
}
{
corridors
?:
CorridorFeature
[]
|
null
,
if
(
!
shapes
)
return
{
flag
:
0
,
note
:
''
};
):
{
flag
:
number
;
note
:
string
;
corridor
:
string
}
{
if
(
!
shapes
)
return
{
flag
:
0
,
note
:
''
,
corridor
:
''
};
const
[
wlng
,
wlat
]
=
gcj02ToWgs84
(
lng
,
lat
);
// GCJ-02 案件点 → WGS-84,对齐陆地掩膜
const
[
wlng
,
wlat
]
=
gcj02ToWgs84
(
lng
,
lat
);
// GCJ-02 案件点 → WGS-84,对齐陆地掩膜
const
v
=
offshoreVerdict
(
wlng
,
wlat
,
shapes
);
const
v
=
offshoreVerdict
(
wlng
,
wlat
,
shapes
);
if
(
v
.
onLand
)
return
{
flag
:
0
,
note
:
''
};
// 掩膜覆盖区外(或掩膜本身为空)无法判定 → 不标不剔,绝不假装「在陆地上」
if
(
!
v
.
judged
)
return
{
flag
:
0
,
note
:
''
,
corridor
:
''
};
if
(
v
.
onLand
)
return
{
flag
:
0
,
note
:
''
,
corridor
:
''
};
// 命中海上合法走廊(深中通道 / 深圳湾大桥 / 盐田港 …)→ 视为合法跨海构筑物,豁免落水标记。
// 走廊是 WGS-84,与已归一化的 (wlng,wlat) 同系;命中即不标,避免把桥 / 岛 / 码头混进「疑似漂移」清单。
if
(
corridors
)
{
const
hit
=
pointInLegalCorridor
(
wlng
,
wlat
,
corridors
);
if
(
hit
.
hit
)
{
return
{
flag
:
0
,
note
:
`命中海上合法走廊「
${
hit
.
name
}
」:跨海桥 / 人工岛 / 码头 / 填海区等合法构筑物,不标记落水`
,
corridor
:
hit
.
name
,
};
}
}
const
dist
=
Number
.
isFinite
(
v
.
distM
)
?
Math
.
round
(
v
.
distM
)
:
null
;
const
dist
=
Number
.
isFinite
(
v
.
distM
)
?
Math
.
round
(
v
.
distM
)
:
null
;
const
tail
=
const
far
=
dist
!==
null
&&
dist
>
OFFSHORE_FAR_DIST_M
;
dist
!==
null
const
band
=
far
?
'远海'
:
'近岸'
;
?
`,距最近区界约
${
dist
}
m —— 落在海上或市域外,参考意义不大`
const
tail
=
dist
!==
null
?
`,距最近陆界约
${
dist
}
m(
${
band
}
)`
:
`(
${
band
}
)`
;
:
` —— 落在海上或市域外`
;
const
extra
=
far
?
' —— 多为跨海构筑物(如深中通道、人工岛)或坐标真实漂移,请逐条确认'
:
' —— 多为近岸合法点(码头/填海区/滨海公园)或掩膜 km 级精度误差所致,参考性低'
;
return
{
return
{
flag
:
FLAG
.
OFFSHORE
,
flag
:
far
?
FLAG
.
OFFSHORE_FAR
:
FLAG
.
OFFSHORE_NEAR
,
note
:
`出险地址写的是深圳辖区,坐标却不在任何深圳行政区陆域多边形内
${
tail
}
`
,
note
:
`出险地址写的是深圳辖区,坐标却不在任何深圳行政区陆域多边形内
${
tail
}${
extra
}
`
,
corridor
:
''
,
};
};
}
}
...
@@ -984,7 +1013,8 @@ export const CLASS_DEFAULTS: Record<CleanClassKey, { fixed: boolean; defaultOn:
...
@@ -984,7 +1013,8 @@ export const CLASS_DEFAULTS: Record<CleanClassKey, { fixed: boolean; defaultOn:
SPARSE
:
{
fixed
:
false
,
defaultOn
:
false
},
SPARSE
:
{
fixed
:
false
,
defaultOn
:
false
},
SPARSE_STREET
:
{
fixed
:
false
,
defaultOn
:
false
},
SPARSE_STREET
:
{
fixed
:
false
,
defaultOn
:
false
},
SMALL
:
{
fixed
:
false
,
defaultOn
:
false
},
SMALL
:
{
fixed
:
false
,
defaultOn
:
false
},
OFFSHORE
:
{
fixed
:
false
,
defaultOn
:
false
},
OFFSHORE_NEAR
:
{
fixed
:
false
,
defaultOn
:
false
},
OFFSHORE_FAR
:
{
fixed
:
false
,
defaultOn
:
false
},
};
};
/**
/**
...
@@ -1037,9 +1067,14 @@ export const CLASS_INFO: Record<CleanClassKey, { label: string; reason: string }
...
@@ -1037,9 +1067,14 @@ export const CLASS_INFO: Record<CleanClassKey, { label: string; reason: string }
reason
:
reason
:
'这个点周围半径内的案件数(含它自己)≤ 阈值。用圆而不是方格,是为了不让一条与业务无关的网格线决定真实聚集的去留。剔掉的是真实事故,只是在全市视图上不成气候'
,
'这个点周围半径内的案件数(含它自己)≤ 阈值。用圆而不是方格,是为了不让一条与业务无关的网格线决定真实聚集的去留。剔掉的是真实事故,只是在全市视图上不成气候'
,
},
},
OFFSHORE
:
{
OFFSHORE_NEAR
:
{
label
:
'坐标落水 / 域外'
,
label
:
'坐标落水 / 域外 · 近岸(≤1km)'
,
reason
:
'出险地址写的是深圳辖区(C 类按地址文本判定放行),坐标却不在任何深圳行政区陆域多边形内,且离最近陆界 ≤ 1km。这一档**大部分是误报**:深圳填海最狠(前海/大铲湾/机场西/深圳湾超总),这些陆地 Natural Earth 掩膜根本没有;掩膜自身在深圳段也是 km 级精度(中位偏差 259m、西部填海区 500–810m),近岸点极易被判反。码头、突堤、滨海公园同理。默认不勾选(即默认保留、不剔除);若确认要排除,勾上即可 —— 它仍是真实事故、地图上照样落点'
,
},
OFFSHORE_FAR
:
{
label
:
'坐标落水 / 域外 · 远海(>1km)'
,
reason
:
reason
:
'出险地址写的是深圳辖区
(C 类按地址文本判定放行),坐标却不在任何深圳行政区陆域多边形内 —— 落在海上或市域外。与邻市(C 类)是两套互补口径:这里只回答「坐标在不在深圳陆域」,不反推归属。坐标飘到海上或市域外,对定位真实出险位置的参考意义不大,多半是坐标采集或回填出错。默认不勾选(即默认保留、不剔除);若确认要排除这批点,勾上即可 ——
它仍是真实事故、地图上照样落点'
,
'出险地址写的是深圳辖区
,坐标却不在任何深圳行政区陆域多边形内,且离最近陆界 > 1km。这一档才更像真问题:深中通道西人工岛(离岸 ~6km)、孖洲岛(~2.3km)这类跨海构筑物,或坐标真实漂移到了海上。默认不勾选(即默认保留、不剔除);请逐条确认 —— 跨海合法构筑物可保留,真漂移点可勾上剔除,
它仍是真实事故、地图上照样落点'
,
},
},
};
};
src/features/heatmap/data/ingestCore.ts
View file @
3d9e6f0
...
@@ -33,6 +33,7 @@ import {
...
@@ -33,6 +33,7 @@ import {
FLAG
,
FLAG
,
}
from
'./cleanRules'
;
}
from
'./cleanRules'
;
import
{
ensureLandMask
,
offshoreShapes
,
type
NamedPolys
}
from
'../geo/districtShapes'
;
import
{
ensureLandMask
,
offshoreShapes
,
type
NamedPolys
}
from
'../geo/districtShapes'
;
import
{
ensureLegalCorridors
,
legalCorridors
,
type
CorridorFeature
}
from
'../geo/offshoreCorridors'
;
import
{
import
{
classifyOperating
,
classifyOperating
,
OPERATING_SEGMENTS
,
OPERATING_SEGMENTS
,
...
@@ -609,10 +610,20 @@ export async function ingestBytes(
...
@@ -609,10 +610,20 @@ export async function ingestBytes(
* 也不假装「全深圳没边界」。测试里传一份现成几何则是为了绕开 Worker 的 fetch。
* 也不假装「全深圳没边界」。测试里传一份现成几何则是为了绕开 Worker 的 fetch。
*/
*/
let
cleanShapes
:
NamedPolys
[]
|
null
=
districtShapes
??
null
;
let
cleanShapes
:
NamedPolys
[]
|
null
=
districtShapes
??
null
;
// 陆地掩膜是否就绪:false 时 offshoreShapes() 会降级到行政区边界(后者抓不到海上点)。
// 先记下来,等 report 建好后再把这条提示写进去(见下方 report.warnings 那段)。
let
landMaskOk
=
true
;
// 海上合法走廊(深中通道 / 盐田港 …)是否就绪:这层是 H 类的「豁免」增强,拉不到就静默跳过,
// 退化成只用陆地掩膜(S1/S3 行为),不卡导入。
let
corridors
:
CorridorFeature
[]
|
null
=
null
;
// 被走廊豁免、从而没进落水清单的点数(仅用于报告提示,不改变「默认不剔除」语义)
let
offshoreCorridorExempt
=
0
;
if
(
districtShapes
===
undefined
)
{
if
(
districtShapes
===
undefined
)
{
// 生产路径:拉陆地掩膜(优先)/ 行政区边界(降级)
// 生产路径:拉陆地掩膜(优先)/ 行政区边界(降级)
await
ensureLandMask
();
landMaskOk
=
await
ensureLandMask
();
cleanShapes
=
offshoreShapes
();
cleanShapes
=
offshoreShapes
();
// 走廊只在生产路径自动拉;测试里注入 districtShapes 时一并走离线,不触发 fetch
if
(
await
ensureLegalCorridors
())
corridors
=
legalCorridors
();
}
}
const
view
=
new
Uint8Array
(
bytes
);
const
view
=
new
Uint8Array
(
bytes
);
...
@@ -641,9 +652,18 @@ export async function ingestBytes(
...
@@ -641,9 +652,18 @@ export async function ingestBytes(
rejectedSamples
,
rejectedSamples
,
flags
:
new
Uint16Array
(
0
),
// 循环结束后按实际有效数重建
flags
:
new
Uint16Array
(
0
),
// 循环结束后按实际有效数重建
classes
:
[],
classes
:
[],
warnings
:
[],
sparseRoads
:
0
,
sparseRoads
:
0
,
sparseStreets
:
0
,
sparseStreets
:
0
,
};
};
// S3:陆地掩膜拉不到就静默降级到行政区边界,而行政区边界抓不到海上点(见 districtShapes 注释)。
// 降级等于「落水类整类失效」却没有任何提示,这里显式写出来,导入人才能在报告里看到为什么海上点没被标。
if
(
!
landMaskOk
)
{
report
.
warnings
?.
push
(
'陆地掩膜(海岸线)未就绪,落水判定已降级到行政区边界:行政区边界会把沿海水域划进区界,'
+
'无法识别落在海上 / 内湾的点,坐标落水类的标记可能不全。请检查 public/geo/shenzhen-land.geojson 是否可访问。'
,
);
}
/**
/**
* A 类拒收。坐标留原始字符串:拒收原因里有一条就是「经纬度非数值」,
* A 类拒收。坐标留原始字符串:拒收原因里有一条就是「经纬度非数值」,
* 转成数字后界面上看到的就不是源文件里那一格,导入人回源文件改会对不上。
* 转成数字后界面上看到的就不是源文件里那一格,导入人回源文件改会对不上。
...
@@ -969,16 +989,22 @@ export async function ingestBytes(
...
@@ -969,16 +989,22 @@ export async function ingestBytes(
// 邻市那几条已经有一条更强的结论(地址写明外市),不重复标,也避免把「坐标在东莞陆域」
// 邻市那几条已经有一条更强的结论(地址写明外市),不重复标,也避免把「坐标在东莞陆域」
// 的邻市案误算进落水类、造成两类数字重叠。判定见 classifyOffshore / geo/districtShapes.ts。
// 的邻市案误算进落水类、造成两类数字重叠。判定见 classifyOffshore / geo/districtShapes.ts。
if (!outside) {
if (!outside) {
const off = classifyOffshore(lngDeg, latDeg, cleanShapes);
const off = classifyOffshore(lngDeg, latDeg, cleanShapes
, corridors
);
if (off.flag) {
if (off.flag) {
flags[i] |= off.flag;
flags[i] |= off.flag;
addSample('OFFSHORE', {
const offKey: CleanClassKey =
off.flag === FLAG.OFFSHORE_NEAR ? 'OFFSHORE_NEAR' : 'OFFSHORE_FAR';
addSample(offKey, {
caseNo,
caseNo,
address,
address,
lng: lngDeg,
lng: lngDeg,
lat: latDeg,
lat: latDeg,
note: off.note,
note: off.note,
});
});
} else if (off.corridor) {
// 命中海上合法走廊:本该被标落水,但属合法跨海构筑物(深中通道 / 盐田港 …),豁免标记。
// 与「onLand / 无法判定」区分开:只有真正命中白名单才计入豁免数(用于报告提示)。
offshoreCorridorExempt += 1;
}
}
}
}
...
@@ -1014,6 +1040,15 @@ export async function ingestBytes(
...
@@ -1014,6 +1040,15 @@ export async function ingestBytes(
if ((r & 0xffff) === 0) onProgress?.('normalize', 0.5 + (r / rows.length) * 0.5);
if ((r & 0xffff) === 0) onProgress?.('normalize', 0.5 + (r / rows.length) * 0.5);
}
}
// S2:被海上合法走廊豁免的落水点,在报告里显式说明(透明、可审计,不改变「默认不剔除」语义)
if (offshoreCorridorExempt > 0) {
report.warnings?.push(
`
海上合法走廊豁免了
$
{
offshoreCorridorExempt
}
条落水点:它们落在深中通道 / 深圳湾大桥 / 盐田港 / 大铲湾码头等`
+
`已知合法跨海构筑物上,已从落水清单移除。这些点仍是真实事故、地图上照常落点;`
+
`如要恢复其落水标记,从 public/geo/shenzhen-offshore-corridors.geojson 移除对应结构即可。`
,
);
}
if
(
report
.
count
===
0
)
{
if
(
report
.
count
===
0
)
{
throw
new
Error
(
`没有解析到任何有效记录(拒收
${
report
.
rejected
}
行)`
);
throw
new
Error
(
`没有解析到任何有效记录(拒收
${
report
.
rejected
}
行)`
);
}
}
...
@@ -1119,7 +1154,8 @@ export async function ingestBytes(
...
@@ -1119,7 +1154,8 @@ export async function ingestBytes(
MISSING
:
FLAG
.
MISSING
,
MISSING
:
FLAG
.
MISSING
,
MISSING_PARTIAL
:
FLAG
.
MISSING_PARTIAL
,
MISSING_PARTIAL
:
FLAG
.
MISSING_PARTIAL
,
OUTSIDE
:
FLAG
.
OUTSIDE
,
OUTSIDE
:
FLAG
.
OUTSIDE
,
OFFSHORE
:
FLAG
.
OFFSHORE
,
OFFSHORE_NEAR
:
FLAG
.
OFFSHORE_NEAR
,
OFFSHORE_FAR
:
FLAG
.
OFFSHORE_FAR
,
ISO_200
:
FLAG
.
ISO_200
,
ISO_200
:
FLAG
.
ISO_200
,
ISO_500
:
FLAG
.
ISO_500
,
ISO_500
:
FLAG
.
ISO_500
,
ISO_1000
:
FLAG
.
ISO_1000
,
ISO_1000
:
FLAG
.
ISO_1000
,
...
...
src/features/heatmap/data/offshore.test.ts
View file @
3d9e6f0
...
@@ -132,18 +132,21 @@ describe('ingestBytes · OFFSHORE 进清洗报告', () => {
...
@@ -132,18 +132,21 @@ describe('ingestBytes · OFFSHORE 进清洗报告', () => {
'90570000000000000000,福田区华富街道,2026-09-25 14:44:00,114.057,22.543,福田区,华富街道,'
,
'90570000000000000000,福田区华富街道,2026-09-25 14:44:00,114.057,22.543,福田区,华富街道,'
,
].
join
(
'\n'
);
].
join
(
'\n'
);
it
(
'注入陆地掩膜:两条海上点进 OFFSHORE
类
,内陆点不进'
,
async
()
=>
{
it
(
'注入陆地掩膜:两条海上点进 OFFSHORE
_NEAR / OFFSHORE_FAR 之一
,内陆点不进'
,
async
()
=>
{
const
bytes
=
new
TextEncoder
().
encode
(
csv
).
buffer
;
const
bytes
=
new
TextEncoder
().
encode
(
csv
).
buffer
;
// 直接注入真实陆地掩膜几何,绕开 Worker 里的 fetch
// 直接注入真实陆地掩膜几何,绕开 Worker 里的 fetch
const
res
=
await
ingestBytes
(
'probe.csv'
,
bytes
,
undefined
,
landShapes
);
const
res
=
await
ingestBytes
(
'probe.csv'
,
bytes
,
undefined
,
landShapes
);
const
offshore
=
res
.
report
.
classes
.
find
((
c
)
=>
c
.
key
===
'OFFSHORE'
);
const
near
=
res
.
report
.
classes
.
find
((
c
)
=>
c
.
key
===
'OFFSHORE_NEAR'
);
expect
(
offshore
).
toBeDefined
();
const
far
=
res
.
report
.
classes
.
find
((
c
)
=>
c
.
key
===
'OFFSHORE_FAR'
);
expect
(
offshore
?.
count
).
toBe
(
2
);
const
total
=
(
near
?.
count
??
0
)
+
(
far
?.
count
??
0
);
expect
(
offshore
?.
defaultOn
).
toBe
(
false
);
expect
(
total
).
toBe
(
2
);
// 内陆那条不进 OFFSHORE:OFFSHORE 标记位 = 1<<11,应当正好 2 行命中
// 两类都默认不勾选(默认保留、不剔除)
const
OFFSHORE_BIT
=
1
<<
11
;
expect
(
near
?.
defaultOn
??
false
).
toBe
(
false
);
expect
(
far
?.
defaultOn
??
false
).
toBe
(
false
);
// 内陆那条不进任何 offshore 类:OFFSHORE_NEAR=1<<11, OFFSHORE_FAR=1<<12,正好 2 行命中其一
const
OFFSHORE_BITS
=
(
1
<<
11
)
|
(
1
<<
12
);
const
offshoreRows
=
(
res
.
report
.
flags
as
Uint16Array
).
filter
(
const
offshoreRows
=
(
res
.
report
.
flags
as
Uint16Array
).
filter
(
(
f
)
=>
(
f
&
OFFSHORE_BIT
)
!==
0
,
(
f
)
=>
(
f
&
OFFSHORE_BIT
S
)
!==
0
,
).
length
;
).
length
;
expect
(
offshoreRows
).
toBe
(
2
);
expect
(
offshoreRows
).
toBe
(
2
);
});
});
...
@@ -151,8 +154,10 @@ describe('ingestBytes · OFFSHORE 进清洗报告', () => {
...
@@ -151,8 +154,10 @@ describe('ingestBytes · OFFSHORE 进清洗报告', () => {
it
(
'不注入边界时(离线)OFFSHORE 计数为 0,不误杀'
,
async
()
=>
{
it
(
'不注入边界时(离线)OFFSHORE 计数为 0,不误杀'
,
async
()
=>
{
const
bytes
=
new
TextEncoder
().
encode
(
csv
).
buffer
;
const
bytes
=
new
TextEncoder
().
encode
(
csv
).
buffer
;
const
res
=
await
ingestBytes
(
'probe.csv'
,
bytes
,
undefined
,
null
);
const
res
=
await
ingestBytes
(
'probe.csv'
,
bytes
,
undefined
,
null
);
const
offshore
=
res
.
report
.
classes
.
find
((
c
)
=>
c
.
key
===
'OFFSHORE'
);
const
total
=
(
res
.
report
.
classes
??
[])
expect
(
offshore
?.
count
??
0
).
toBe
(
0
);
.
filter
((
c
)
=>
c
.
key
===
'OFFSHORE_NEAR'
||
c
.
key
===
'OFFSHORE_FAR'
)
.
reduce
((
s
,
c
)
=>
s
+
c
.
count
,
0
);
expect
(
total
).
toBe
(
0
);
expect
(
res
.
report
.
count
).
toBe
(
3
);
expect
(
res
.
report
.
count
).
toBe
(
3
);
});
});
});
});
src/features/heatmap/geo/districtShapes.ts
View file @
3d9e6f0
...
@@ -449,15 +449,16 @@ export function offshoreVerdict(
...
@@ -449,15 +449,16 @@ export function offshoreVerdict(
lng
:
number
,
lng
:
number
,
lat
:
number
,
lat
:
number
,
shapes
:
NamedPolys
[],
shapes
:
NamedPolys
[],
):
{
onLand
:
boolean
;
distM
:
number
}
{
):
{
onLand
:
boolean
;
distM
:
number
;
judged
:
boolean
}
{
const
{
polys
,
ob
}
=
prepShapes
(
shapes
);
const
{
polys
,
ob
}
=
prepShapes
(
shapes
);
// bbox 守卫:点落在掩膜覆盖区外时无法判定为海上,按陆地处理(不误杀市域北缘 / 边界附近的合法点)
// bbox 守卫:点落在掩膜覆盖区外时**无法判定** —— 既不判海上也不假装陆地,
// 交回上层「不标不剔」(旧版在这里按陆地处理,会漏判南边 22.25 以下、或掩膜换成只盖深圳后的海域)。
if
(
lng
<
ob
.
minLng
||
lng
>
ob
.
maxLng
||
lat
<
ob
.
minLat
||
lat
>
ob
.
maxLat
)
{
if
(
lng
<
ob
.
minLng
||
lng
>
ob
.
maxLng
||
lat
<
ob
.
minLat
||
lat
>
ob
.
maxLat
)
{
return
{
onLand
:
true
,
distM
:
0
};
return
{
onLand
:
true
,
distM
:
0
,
judged
:
false
};
}
}
for
(
const
{
p
,
b
}
of
polys
)
{
for
(
const
{
p
,
b
}
of
polys
)
{
if
(
lng
<
b
.
minLng
||
lng
>
b
.
maxLng
||
lat
<
b
.
minLat
||
lat
>
b
.
maxLat
)
continue
;
if
(
lng
<
b
.
minLng
||
lng
>
b
.
maxLng
||
lat
<
b
.
minLat
||
lat
>
b
.
maxLat
)
continue
;
if
(
pointInPolygon
(
lng
,
lat
,
p
))
return
{
onLand
:
true
,
distM
:
0
};
if
(
pointInPolygon
(
lng
,
lat
,
p
))
return
{
onLand
:
true
,
distM
:
0
,
judged
:
true
};
}
}
// 落在所有陆块之外:算到最近陆界的距离,交给导入人判断(码头 / 跨海大桥等合法点会靠距离分辨)
// 落在所有陆块之外:算到最近陆界的距离,交给导入人判断(码头 / 跨海大桥等合法点会靠距离分辨)
const
distM
=
distanceToBoundaryM
(
const
distM
=
distanceToBoundaryM
(
...
@@ -465,7 +466,7 @@ export function offshoreVerdict(
...
@@ -465,7 +466,7 @@ export function offshoreVerdict(
lat
,
lat
,
polys
.
map
((
x
)
=>
x
.
p
),
polys
.
map
((
x
)
=>
x
.
p
),
);
);
return
{
onLand
:
false
,
distM
};
return
{
onLand
:
false
,
distM
,
judged
:
true
};
}
}
/**
/**
...
...
src/features/heatmap/geo/offshoreCorridors.test.ts
0 → 100644
View file @
3d9e6f0
/**
* 海上合法走廊(S2)的判定测试。
*
* 走廊是离线、随仓库提交的静态 GeoJSON(public/geo/shenzhen-offshore-corridors.geojson),
* 这里用合成几何测「解析 + 命中判定 + 容灾」,落水判定本身复用真实的 shenzhen-land.geojson。
*/
import
{
readFileSync
}
from
'node:fs'
;
import
{
resolve
}
from
'node:path'
;
import
{
describe
,
expect
,
it
}
from
'vitest'
;
import
{
parseCorridors
,
pointInLegalCorridor
,
type
CorridorFeature
}
from
'./offshoreCorridors'
;
import
{
parseDistrictGeometry
}
from
'./districtShapes'
;
import
{
gcj02ToWgs84
}
from
'./coord'
;
import
{
classifyOffshore
}
from
'../data/cleanRules'
;
const
LAND
=
JSON
.
parse
(
readFileSync
(
resolve
(
__dirname
,
'../../../../public/geo/shenzhen-land.geojson'
),
'utf8'
),
)
as
unknown
;
const
landShapes
=
parseDistrictGeometry
(
LAND
);
const
GEOJSON
=
JSON
.
parse
(
readFileSync
(
resolve
(
__dirname
,
'../../../../public/geo/shenzhen-offshore-corridors.geojson'
),
'utf8'
,
),
)
as
unknown
;
describe
(
'parseCorridors'
,
()
=>
{
it
(
'解析 LineString / Point / MultiLineString / Polygon 四种几何'
,
()
=>
{
const
fc
=
{
type
:
'FeatureCollection'
,
features
:
[
{
type
:
'Feature'
,
properties
:
{
name
:
'桥'
,
bufferM
:
500
},
geometry
:
{
type
:
'LineString'
,
coordinates
:
[[
113.8
,
22.6
],
[
113.9
,
22.6
]]
},
},
{
type
:
'Feature'
,
properties
:
{
name
:
'岛'
,
bufferM
:
1200
},
geometry
:
{
type
:
'Point'
,
coordinates
:
[
114.0
,
22.5
]
},
},
{
type
:
'Feature'
,
properties
:
{
name
:
'多线'
,
bufferM
:
300
},
geometry
:
{
type
:
'MultiLineString'
,
coordinates
:
[[[
114.1
,
22.5
],
[
114.2
,
22.5
]]]
},
},
{
type
:
'Feature'
,
properties
:
{
name
:
'港区'
,
bufferM
:
800
},
geometry
:
{
type
:
'Polygon'
,
coordinates
:
[[[
114.3
,
22.5
],
[
114.31
,
22.5
],
[
114.31
,
22.51
],
[
114.3
,
22.51
],
[
114.3
,
22.5
]]]
},
},
],
};
const
c
=
parseCorridors
(
fc
);
expect
(
c
).
toHaveLength
(
4
);
expect
(
c
[
0
].
name
).
toBe
(
'桥'
);
expect
(
c
[
0
].
bufferM
).
toBe
(
500
);
expect
(
c
[
0
].
paths
[
0
]).
toEqual
([[
113.8
,
22.6
],
[
113.9
,
22.6
]]);
expect
(
c
[
1
].
paths
[
0
]).
toEqual
([[
114.0
,
22.5
]]);
expect
(
c
[
2
].
paths
).
toHaveLength
(
1
);
expect
(
c
[
3
].
polygon
).
toBeDefined
();
});
it
(
'缺省 bufferM 用 200,忽略不支持的几何与缺坐标的要素'
,
()
=>
{
const
fc
=
{
type
:
'FeatureCollection'
,
features
:
[
{
type
:
'Feature'
,
properties
:
{
name
:
'无缓冲'
},
geometry
:
{
type
:
'Point'
,
coordinates
:
[
114.0
,
22.5
]
}
},
{
type
:
'Feature'
,
properties
:
{
name
:
'坏点'
},
geometry
:
{
type
:
'Point'
,
coordinates
:
[
114.0
]
}
},
{
type
:
'Feature'
,
properties
:
{
name
:
'不支持'
},
geometry
:
{
type
:
'MultiPolygon'
,
coordinates
:
[]
}
},
],
};
const
c
=
parseCorridors
(
fc
);
expect
(
c
).
toHaveLength
(
1
);
expect
(
c
[
0
].
bufferM
).
toBe
(
200
);
});
it
(
'真实走廊文件能解析出 7 条结构'
,
()
=>
{
const
c
=
parseCorridors
(
GEOJSON
);
expect
(
c
.
length
).
toBe
(
7
);
expect
(
c
.
map
((
x
)
=>
x
.
name
)).
toContain
(
'深中通道(含西人工岛 / 深中隧道)'
);
});
});
describe
(
'pointInLegalCorridor'
,
()
=>
{
const
corridors
:
CorridorFeature
[]
=
[
{
name
:
'桥'
,
bufferM
:
500
,
paths
:
[[[
113.8
,
22.6
],
[
113.9
,
22.6
]]]
},
{
name
:
'岛'
,
bufferM
:
1200
,
paths
:
[[[
114.0
,
22.5
]]]
},
{
name
:
'港区'
,
bufferM
:
300
,
paths
:
[],
polygon
:
[[[
114.3
,
22.5
],
[
114.31
,
22.5
],
[
114.31
,
22.51
],
[
114.3
,
22.51
],
[
114.3
,
22.5
]]],
},
];
it
(
'null 走廊直接返回未命中(容灾:数据没就绪时交回上层按陆地掩膜处理)'
,
()
=>
{
expect
(
pointInLegalCorridor
(
113.85
,
22.6
,
null
).
hit
).
toBe
(
false
);
});
it
(
'离折线 0.001° 内的点命中(约百米级,< 500m 缓冲)'
,
()
=>
{
const
m
=
pointInLegalCorridor
(
113.85
,
22.601
,
corridors
);
expect
(
m
.
hit
).
toBe
(
true
);
expect
(
m
.
name
).
toBe
(
'桥'
);
});
it
(
'离折线很远的点不命中'
,
()
=>
{
expect
(
pointInLegalCorridor
(
113.85
,
22.9
,
corridors
).
hit
).
toBe
(
false
);
});
it
(
'Point 走廊:半径内的点命中、半径外不命中'
,
()
=>
{
expect
(
pointInLegalCorridor
(
114.0
,
22.501
,
corridors
).
name
).
toBe
(
'岛'
);
expect
(
pointInLegalCorridor
(
114.0
,
22.52
,
corridors
).
hit
).
toBe
(
false
);
// 约 2.2km,超 1200m
});
it
(
'Polygon 走廊:面内与面边界缓冲内都命中'
,
()
=>
{
expect
(
pointInLegalCorridor
(
114.305
,
22.505
,
corridors
).
name
).
toBe
(
'港区'
);
// 面内
expect
(
pointInLegalCorridor
(
114.302
,
22.5
,
corridors
).
name
).
toBe
(
'港区'
);
// 面边界外 ~220m,< 300m
expect
(
pointInLegalCorridor
(
114.5
,
22.5
,
corridors
).
hit
).
toBe
(
false
);
});
});
describe
(
'classifyOffshore · 走廊豁免'
,
()
=>
{
const
SEA_A
=
{
lng
:
114.563342
,
lat
:
22.600221
};
// 大鹏外海,GCJ-02
it
(
'不加走廊:海上点被标落水'
,
()
=>
{
const
r
=
classifyOffshore
(
SEA_A
.
lng
,
SEA_A
.
lat
,
landShapes
);
expect
(
r
.
flag
).
toBeTruthy
();
expect
(
r
.
corridor
).
toBe
(
''
);
});
it
(
'加一条覆盖该点(WGS-84)的走廊:豁免标记,corridor 字段回写结构名'
,
()
=>
{
const
[
wlng
,
wlat
]
=
gcj02ToWgs84
(
SEA_A
.
lng
,
SEA_A
.
lat
);
const
corridors
:
CorridorFeature
[]
=
[
{
name
:
'测试合法岛'
,
bufferM
:
5000
,
paths
:
[[[
wlng
,
wlat
]]]
},
];
const
r
=
classifyOffshore
(
SEA_A
.
lng
,
SEA_A
.
lat
,
landShapes
,
corridors
);
expect
(
r
.
flag
).
toBe
(
0
);
expect
(
r
.
corridor
).
toBe
(
'测试合法岛'
);
expect
(
r
.
note
).
toContain
(
'海上合法走廊'
);
});
it
(
'陆域点即使有走廊也不受影响(走廊只豁免海上点)'
,
()
=>
{
const
LAND_PT
=
{
lng
:
114.057
,
lat
:
22.543
};
const
[
wlng
,
wlat
]
=
gcj02ToWgs84
(
LAND_PT
.
lng
,
LAND_PT
.
lat
);
const
corridors
:
CorridorFeature
[]
=
[
{
name
:
'覆盖市区的假走廊'
,
bufferM
:
50000
,
paths
:
[[[
wlng
,
wlat
]]]
},
];
const
r
=
classifyOffshore
(
LAND_PT
.
lng
,
LAND_PT
.
lat
,
landShapes
,
corridors
);
expect
(
r
.
flag
).
toBe
(
0
);
expect
(
r
.
corridor
).
toBe
(
''
);
});
});
src/features/heatmap/geo/offshoreCorridors.ts
0 → 100644
View file @
3d9e6f0
/**
* 海上合法走廊(offshore legal corridors)。
*
* 这是 H 类「坐标落水 / 域外」的第二道防线:**第一道**用陆地掩膜把所有海上点标出来
* (见 districtShapes.offshoreVerdict),**这一道**再把其中「落在已知合法跨海构筑物上」的
* 点豁免掉 —— 不让深中通道、深圳湾大桥、盐田港、大铲湾码头这类点混进「疑似漂移」清单里
* 让导入人逐条复核。距离阈值救不了它们(深中通道西人工岛离岸 6km、孖洲岛 2.3km,
* 1000m 拐点只会把它们全判成远海),必须按几何命中。
*
* 数据是一份**离线、随仓库提交**的 GeoJSON(`public/geo/shenzhen-offshore-corridors.geojson`),
* 不依赖任何在线服务:运行期只是同源静态文件 fetch 一次。原因:
* - OSM / Overpass 在本机沙箱不可达、在浏览器里还有 CORS / 限流 / 宕机,不能让导入链路
* 依赖一个不稳定外源;
* - 走廊是「已知合法结构」的白名单,本就该是有据可查、可审计的静态资产,而不是每次导入
* 现拉的快照。要增删结构,改这份 GeoJSON(或让超人在能联网的机器上用 OSM 产出后提交)即可。
*
* 几何口径与全项目一致:本地等距圆柱近似(经度按该点纬度换算米数,见 hotspotGeometry)。
* 走廊以 **WGS-84** 存储(与陆地掩膜同一套系),而案件点在 classifyOffshore 里已经归一化到
* WGS-84 才来比,所以命中判定直接在同系坐标下做,不引入第二套偏移。
*
* 容灾:拉不到 / 解析失败 → `legalCorridors()` 返回 null,classifyOffshore 收 null 时整道跳过,
* 退化成「只用陆地掩膜」(即 S1/S3 的行为),不会误杀也不会卡住导入。
*/
import
{
M_PER_DEG_LAT
,
M_PER_EQUATOR
}
from
'../map/hotspotGeometry'
;
import
{
pointInPolygon
,
type
LngLat
,
type
ShapePolygon
}
from
'./polygon'
;
/** 一条海上合法走廊:线(path)或面(polygon,用于岛/港区整体),外加缓冲半径 */
export
interface
CorridorFeature
{
/** 可读名,写进报告给人审计(深中通道 / 盐田国际集装箱码头 …) */
name
:
string
;
/** 缓冲半径(米):点到线 / 面边界 ≤ 此值即视为落在合法构筑物上 */
bufferM
:
number
;
/** 折线集合,每条折线是一串 WGS-84 [lng,lat]。单点(Point)就是一条退化成点的折线 */
paths
:
LngLat
[][];
/** 可选面(Polygon 的环数组),整片视为合法(岛 / 港区陆域)。点在面内或距边界 ≤ bufferM 即命中 */
polygon
?:
LngLat
[][];
}
export
interface
CorridorMatch
{
hit
:
boolean
;
name
:
string
;
}
/* ------------------------------- 解析 GeoJSON ------------------------------- */
/**
* 把离线 GeoJSON 解析成 CorridorFeature[]。
*
* 支持三种几何:LineString / MultiLineString(缓冲沿线)、Point(退化为单点 + 缓冲)、
* Polygon(整片合法,点在面内或距边界 ≤ bufferM)。每条 feature 用 properties.name 命名、
* properties.bufferM 覆盖默认缓冲(缺省 200m)。
*/
export
function
parseCorridors
(
raw
:
unknown
):
CorridorFeature
[]
{
const
fc
=
raw
as
{
type
?:
string
;
features
?:
unknown
[]
};
if
(
!
fc
||
fc
.
type
!==
'FeatureCollection'
||
!
Array
.
isArray
(
fc
.
features
))
{
throw
new
Error
(
'走廊数据不是 FeatureCollection'
);
}
const
out
:
CorridorFeature
[]
=
[];
for
(
const
f
of
fc
.
features
)
{
const
feature
=
f
as
{
properties
?:
Record
<
string
,
unknown
>
;
geometry
?:
{
type
?:
string
;
coordinates
?:
unknown
};
};
const
props
=
feature
.
properties
??
{};
const
name
=
typeof
props
.
name
===
'string'
&&
props
.
name
?
props
.
name
:
'海上合法构筑物'
;
const
bufferM
=
Number
.
isFinite
(
Number
(
props
.
bufferM
))
?
Number
(
props
.
bufferM
)
:
200
;
const
geom
=
feature
.
geometry
;
if
(
!
geom
||
!
geom
.
type
||
!
Array
.
isArray
(
geom
.
coordinates
))
continue
;
const
paths
:
LngLat
[][]
=
[];
let
polygon
:
LngLat
[][]
|
undefined
;
if
(
geom
.
type
===
'LineString'
)
{
paths
.
push
(
coordsToLngLat
(
geom
.
coordinates
));
}
else
if
(
geom
.
type
===
'MultiLineString'
)
{
for
(
const
line
of
geom
.
coordinates
as
unknown
[])
paths
.
push
(
coordsToLngLat
(
line
));
}
else
if
(
geom
.
type
===
'Point'
)
{
// Point 的 coordinates 是单个位置 [lng,lat](不是位置数组),单独处理
const
c
=
geom
.
coordinates
as
unknown
[];
if
(
Array
.
isArray
(
c
)
&&
c
.
length
>=
2
)
{
const
lng
=
Number
(
c
[
0
]);
const
lat
=
Number
(
c
[
1
]);
if
(
Number
.
isFinite
(
lng
)
&&
Number
.
isFinite
(
lat
))
paths
.
push
([[
lng
,
lat
]]);
}
}
else
if
(
geom
.
type
===
'Polygon'
)
{
polygon
=
(
geom
.
coordinates
as
unknown
[]).
map
((
ring
)
=>
coordsToLngLat
(
ring
));
}
else
{
continue
;
// 其余类型(MultiPolygon 等)暂时不支持,跳过这条不影响其它
}
if
(
paths
.
length
===
0
&&
!
polygon
)
continue
;
out
.
push
({
name
,
bufferM
,
paths
,
polygon
});
}
return
out
;
}
function
coordsToLngLat
(
raw
:
unknown
):
LngLat
[]
{
if
(
!
Array
.
isArray
(
raw
))
return
[];
const
out
:
LngLat
[]
=
[];
for
(
const
pos
of
raw
)
{
if
(
!
Array
.
isArray
(
pos
)
||
pos
.
length
<
2
)
continue
;
const
lng
=
Number
(
pos
[
0
]);
const
lat
=
Number
(
pos
[
1
]);
if
(
!
Number
.
isFinite
(
lng
)
||
!
Number
.
isFinite
(
lat
))
continue
;
out
.
push
([
lng
,
lat
]);
}
return
out
;
}
/* ------------------------------- 命中判定 ------------------------------- */
/**
* 一个 WGS-84 点是否落在任一合法走廊内(含缓冲)。
*
* 距离用本地等距圆柱近似:把经纬度按「该点纬度」投影成米,再算点到折线 / 面边界的欧氏距离。
* 与全项目米↔度换算同一套口径(见 polygon.ts / hotspotGeometry),短距离(≤ 几 km)下
* 椭球与平面的差远小于掩膜自身精度,不值得为此起一套投影库。
*
* @param lng 已归一化到 WGS-84 的经度(案件点请先 gcj02ToWgs84)
* @param lat 已归一化到 WGS-84 的纬度
* @param corridors null 时(数据未就绪)直接返回未命中,交回上层按陆地掩膜处理
*/
export
function
pointInLegalCorridor
(
lng
:
number
,
lat
:
number
,
corridors
:
CorridorFeature
[]
|
null
,
):
CorridorMatch
{
if
(
!
corridors
)
return
{
hit
:
false
,
name
:
''
};
// 该点所在纬度下的经线米数(随纬度收缩)
const
kx
=
M_PER_EQUATOR
*
Math
.
cos
((
lat
*
Math
.
PI
)
/
180
);
const
ky
=
M_PER_DEG_LAT
;
const
px
=
lng
*
kx
;
const
py
=
lat
*
ky
;
for
(
const
c
of
corridors
)
{
// 面:点在面内即命中(整片合法),否则看距边界多近
if
(
c
.
polygon
)
{
const
poly
:
ShapePolygon
=
{
rings
:
c
.
polygon
};
if
(
pointInPolygon
(
lng
,
lat
,
poly
))
return
{
hit
:
true
,
name
:
c
.
name
};
if
(
distToPolygonBoundaryM
(
px
,
py
,
c
.
polygon
,
kx
,
ky
)
<=
c
.
bufferM
)
{
return
{
hit
:
true
,
name
:
c
.
name
};
}
}
// 线(含 Point 退化成的单点):距任一折线段 ≤ bufferM 即命中
for
(
const
path
of
c
.
paths
)
{
if
(
distToPathM
(
px
,
py
,
path
,
kx
,
ky
)
<=
c
.
bufferM
)
return
{
hit
:
true
,
name
:
c
.
name
};
}
}
return
{
hit
:
false
,
name
:
''
};
}
/** 点到一条折线的距离(米),投影后逐段取最短 */
function
distToPathM
(
px
:
number
,
py
:
number
,
path
:
LngLat
[],
kx
:
number
,
ky
:
number
,
):
number
{
if
(
path
.
length
===
0
||
!
path
[
0
])
return
Infinity
;
if
(
path
.
length
===
1
)
{
const
ax
=
path
[
0
][
0
]
*
kx
;
const
ay
=
path
[
0
][
1
]
*
ky
;
return
Math
.
hypot
(
px
-
ax
,
py
-
ay
);
}
let
best
=
Infinity
;
for
(
let
i
=
1
;
i
<
path
.
length
;
i
+=
1
)
{
const
ax
=
path
[
i
-
1
][
0
]
*
kx
;
const
ay
=
path
[
i
-
1
][
1
]
*
ky
;
const
bx
=
path
[
i
][
0
]
*
kx
;
const
by
=
path
[
i
][
1
]
*
ky
;
const
d
=
distToSegmentM
(
px
,
py
,
ax
,
ay
,
bx
,
by
);
if
(
d
<
best
)
best
=
d
;
}
return
best
;
}
/** 点到一个 Polygon(所有环的线段)的距离(米) */
function
distToPolygonBoundaryM
(
px
:
number
,
py
:
number
,
rings
:
LngLat
[][],
kx
:
number
,
ky
:
number
,
):
number
{
let
best
=
Infinity
;
for
(
const
ring
of
rings
)
{
const
d
=
distToPathM
(
px
,
py
,
ring
,
kx
,
ky
);
if
(
d
<
best
)
best
=
d
;
}
return
best
;
}
/** 点到线段的最短距离(投影空间,米) */
function
distToSegmentM
(
px
:
number
,
py
:
number
,
ax
:
number
,
ay
:
number
,
bx
:
number
,
by
:
number
,
):
number
{
const
dx
=
bx
-
ax
;
const
dy
=
by
-
ay
;
const
len2
=
dx
*
dx
+
dy
*
dy
;
let
t
=
len2
>
0
?
((
px
-
ax
)
*
dx
+
(
py
-
ay
)
*
dy
)
/
len2
:
0
;
if
(
t
<
0
)
t
=
0
;
else
if
(
t
>
1
)
t
=
1
;
const
cx
=
ax
+
t
*
dx
;
const
cy
=
ay
+
t
*
dy
;
return
Math
.
hypot
(
px
-
cx
,
py
-
cy
);
}
/* ------------------------------- 加载与缓存 ------------------------------- */
const
BASE
=
import
.
meta
.
env
.
BASE_URL
??
'/'
;
let
corridorRaw
:
unknown
|
null
=
null
;
let
corridorPending
:
Promise
<
boolean
>
|
null
=
null
;
let
parsedCorridors
:
CorridorFeature
[]
|
null
=
null
;
/**
* 预热走廊数据。返回是否可用(拉到并解析成功)。
* 失败不当致命错误处理:这层只是 H 类的「豁免」增强,拿不到就退回到只用陆地掩膜,
* 绝不让导入因为一份可选白名单拉不到而卡住。
*/
export
function
ensureLegalCorridors
():
Promise
<
boolean
>
{
if
(
corridorRaw
)
return
Promise
.
resolve
(
true
);
if
(
!
corridorPending
)
{
corridorPending
=
(
async
()
=>
{
const
res
=
await
fetch
(
`
${
BASE
}
geo/shenzhen-offshore-corridors.geojson`
,
{
credentials
:
'same-origin'
,
});
if
(
!
res
.
ok
)
throw
new
Error
(
`加载海上合法走廊失败:HTTP
${
res
.
status
}
`
);
const
json
=
(
await
res
.
json
())
as
unknown
;
parsedCorridors
=
parseCorridors
(
json
);
// 先验一次格式
corridorRaw
=
json
;
return
true
;
})().
catch
((
err
)
=>
{
console
.
warn
(
'[geo] 海上合法走廊未就绪,H 类不豁免(按陆地掩膜原样标记):'
,
err
);
corridorPending
=
null
;
return
false
;
});
}
return
corridorPending
;
}
/** 走廊是否已可用(classifyOffshore 据此决定要不要做豁免判定) */
export
function
hasLegalCorridors
():
boolean
{
return
corridorRaw
!==
null
;
}
/** 给清洗用的几何;没就绪返回 null —— 不返回空数组冒充「就是没有走廊」 */
export
function
legalCorridors
():
CorridorFeature
[]
|
null
{
return
parsedCorridors
;
}
src/layout/ImportControl.tsx
View file @
3d9e6f0
...
@@ -64,7 +64,7 @@ const ISO_SHORT: Record<string, string> = {
...
@@ -64,7 +64,7 @@ const ISO_SHORT: Record<string, string> = {
};
};
/** 自动判定段的类目,顺序即界面行序。A 类(拒收)不在 flags 里,单独一行 */
/** 自动判定段的类目,顺序即界面行序。A 类(拒收)不在 flags 里,单独一行 */
const AUTO_KEYS: CleanClassKey[] = ['MISSING', 'MISSING_PARTIAL', 'OUTSIDE', 'OFFSHORE'];
const AUTO_KEYS: CleanClassKey[] = ['MISSING', 'MISSING_PARTIAL', 'OUTSIDE', 'OFFSHORE
_NEAR', 'OFFSHORE_FAR
'];
/** 道路低频阈值的取值范围:0 = 关闭这一类,上限 999 只是防手滑输进一个荒唐值 */
/** 道路低频阈值的取值范围:0 = 关闭这一类,上限 999 只是防手滑输进一个荒唐值 */
const SPARSE_MIN = 0;
const SPARSE_MIN = 0;
...
@@ -631,6 +631,15 @@ function ReportBody({
...
@@ -631,6 +631,15 @@ function ReportBody({
</div>
</div>
</div>
</div>
{/* ---------- 非致命提示(掩膜降级等):不影响解析,但导入人应看到 ---------- */}
{r.warnings && r.warnings.length > 0 && (
<div className="hm-ic__opt-warn" style={{ marginBottom: 12 }}>
{r.warnings.map((w, i) => (
<div key={i}>{w}</div>
))}
</div>
)}
{/* ---------- 自动判定:A 拒收 + B 字段缺失(分两档)+ C 辖区归属 ---------- */}
{/* ---------- 自动判定:A 拒收 + B 字段缺失(分两档)+ C 辖区归属 ---------- */}
<section className="hm-ic__sec">
<section className="hm-ic__sec">
<div className="hm-ic__sec-head">
<div className="hm-ic__sec-head">
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment