@caoguo/maplibre-ai 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,212 @@
1
+ /**
2
+ * GeoAI 中文地址解析(PRD phase-0 §5.6 G-2)
3
+ *
4
+ * 将非标准中文地址(含口语化、简称)解析为标准化结构:
5
+ * province / city / district / street / poi / number
6
+ *
7
+ * 采用「词典匹配 + 规则」的传统 NLP 方案(不依赖大模型),保证速度与可控性。
8
+ */
9
+ interface ParsedAddress {
10
+ /** 原始输入 */
11
+ raw: string;
12
+ /** 省 */
13
+ province?: string;
14
+ /** 市 */
15
+ city?: string;
16
+ /** 区/县 */
17
+ district?: string;
18
+ /** 街道/路/道 */
19
+ street?: string;
20
+ /** 门牌号 */
21
+ number?: string;
22
+ /** 地标/POI(如"光谷""汉口火车站") */
23
+ poi?: string;
24
+ /** 标准化地址(可读拼接) */
25
+ normalized: string;
26
+ /** 解析置信度 0-1 */
27
+ confidence: number;
28
+ }
29
+ /**
30
+ * 解析中文地址。
31
+ *
32
+ * 覆盖:
33
+ * - 完整地址:"湖北省武汉市洪山区光谷大道 1 号"
34
+ * - 简称:"武汉光谷"、"洪山区"
35
+ * - 口语化:"光谷那边"、"汉口火车站附近"
36
+ */
37
+ declare function parseAddress(raw: string): ParsedAddress;
38
+ /** 判断是否为有效地址(至少命中省/市/区/POI 之一) */
39
+ declare function isValidAddress(parsed: ParsedAddress): boolean;
40
+
41
+ /**
42
+ * GeoAI 表头自动识别(PRD phase-0 §5.6 G-1)
43
+ *
44
+ * 从 CSV/Excel 表头中自动识别:
45
+ * - 地址列(addressCol)
46
+ * - 名称列(nameCol)
47
+ * - 分类列(categoryCol)
48
+ * - 经度列(lngCol)/ 纬度列(latCol)
49
+ *
50
+ * 采用「列名语义 + 正则匹配」方案,命中率目标 ≥ 90%。
51
+ */
52
+ interface HeaderDetection {
53
+ /** 地址列索引(-1 表示未识别) */
54
+ addressCol: number;
55
+ /** 名称列索引 */
56
+ nameCol: number;
57
+ /** 分类列索引 */
58
+ categoryCol: number;
59
+ /** 经度列索引 */
60
+ lngCol: number;
61
+ /** 纬度列索引 */
62
+ latCol: number;
63
+ /** 识别详情(供上层展示/纠错) */
64
+ detail: Record<string, string>;
65
+ }
66
+ /**
67
+ * 识别表头。
68
+ * @param headers 表头数组(CSV 首行 / Excel 首行)
69
+ */
70
+ declare function detectHeaders(headers: string[]): HeaderDetection;
71
+
72
+ /**
73
+ * GeoAI 坐标系判断(PRD phase-0 §5.6 G-3)
74
+ *
75
+ * 判断数据坐标所属坐标系:WGS84 / GCJ-02 / CGCS2000。
76
+ *
77
+ * 说明:单点无法 100% 判定坐标系(GCJ-02 偏移仅数百米),
78
+ * 本模块采用「范围校验 + 数据来源推断 + 中国境外判定」的组合启发式,
79
+ * 并提供 GCJ-02 ↔ WGS84 双向纠偏转换。
80
+ */
81
+ type DetectedCRS = 'wgs84' | 'gcj02' | 'cgcs2000' | 'unknown';
82
+ /** 中国经纬度范围(粗判) */
83
+ declare const CHINA_BOUNDS: {
84
+ lngMin: number;
85
+ lngMax: number;
86
+ latMin: number;
87
+ latMax: number;
88
+ };
89
+ /** WGS84 → GCJ-02(加密偏移) */
90
+ declare function wgs84ToGcj02(lng: number, lat: number): [number, number];
91
+ /** GCJ-02 → WGS84(纠偏,迭代逼近) */
92
+ declare function gcj02ToWgs84(lng: number, lat: number): [number, number];
93
+ /** 坐标是否在中国境内 */
94
+ declare function isInChina(lng: number, lat: number): boolean;
95
+ /**
96
+ * 判断坐标系。
97
+ * @param source 数据来源标注(如 '高德' / '腾讯' / '天地图' / 'GPS' / undefined)
98
+ * @param sample 抽样坐标对
99
+ */
100
+ declare function detectCRS(source: string | undefined, sample?: Array<[number, number]>): DetectedCRS;
101
+
102
+ /**
103
+ * GeoAI 批量地理编码(PRD phase-0 §5.6 G-4)
104
+ *
105
+ * 将解析后的中文地址编码为坐标 [lng, lat]。
106
+ * v1 使用「本地坐标库 + 模糊匹配」(离线、不依赖天地图/高德 API),
107
+ * 命中率目标:标准地址 ≥ 90%,口语化地址 ≥ 60%。
108
+ */
109
+
110
+ /** 本地地理坐标库:地名 → [lng, lat](WGS84) */
111
+ declare const LOCAL_GEO_DB: Record<string, [number, number]>;
112
+ interface GeocodeResult {
113
+ lng: number;
114
+ lat: number;
115
+ /** 匹配到的地名 */
116
+ matched: string;
117
+ /** 置信度 0-1 */
118
+ confidence: number;
119
+ }
120
+ /**
121
+ * 地理编码:地址 → 坐标。
122
+ *
123
+ * 匹配优先级:
124
+ * 1. POI(最精确)
125
+ * 2. 区/县
126
+ * 3. 城市
127
+ * 4. 省(降级)
128
+ *
129
+ * 无法匹配返回 null。
130
+ */
131
+ declare function geocode(parsed: ParsedAddress): GeocodeResult | null;
132
+ /** 查询本地库是否存在某地名 */
133
+ declare function hasLocalGeo(name: string): boolean;
134
+ interface BatchGeocodeInput {
135
+ /** 原始地址字符串 */
136
+ address: string;
137
+ /** 已有经度(可选,优先级最高) */
138
+ lng?: number;
139
+ /** 已有纬度(可选) */
140
+ lat?: number;
141
+ }
142
+ interface BatchGeocodeOutput {
143
+ lng: number;
144
+ lat: number;
145
+ /** 坐标来源:'provided' | 'geocoded' | 'failed' */
146
+ source: 'provided' | 'geocoded' | 'failed';
147
+ matched?: string;
148
+ confidence: number;
149
+ }
150
+ /**
151
+ * 批量地理编码:对一批记录并行编码。
152
+ *
153
+ * 优先级:已有经纬度 > 地址解析 + 本地库编码。
154
+ */
155
+ declare function batchGeocode(rows: BatchGeocodeInput[], parse: (raw: string) => ParsedAddress): BatchGeocodeOutput[];
156
+
157
+ /**
158
+ * GeoAI 数据入图主入口(PRD phase-0 §5.6)
159
+ *
160
+ * 完整管线:
161
+ * CSV/Excel 表头 → 表头识别 → 逐行地址解析 → 地理编码 / 坐标纠偏 → GeoJSON
162
+ *
163
+ * 用法:
164
+ * const result = importToGeoJSON(headers, rows);
165
+ * result.features // GeoJSON FeatureCollection
166
+ * result.stats // 命中率 / 编码耗时等
167
+ */
168
+
169
+ interface ImportedFeature {
170
+ type: 'Feature';
171
+ geometry: {
172
+ type: 'Point';
173
+ coordinates: [number, number];
174
+ } | {
175
+ type: 'Point';
176
+ coordinates: [];
177
+ };
178
+ properties: Record<string, unknown>;
179
+ }
180
+ interface ImportStats {
181
+ /** 总记录数 */
182
+ total: number;
183
+ /** 成功编码数 */
184
+ success: number;
185
+ /** 失败数 */
186
+ failed: number;
187
+ /** 成功率 0-1 */
188
+ successRate: number;
189
+ /** 识别出的表头 */
190
+ headers: HeaderDetection;
191
+ /** 编码耗时(ms) */
192
+ durationMs: number;
193
+ }
194
+ interface ImportResult {
195
+ type: 'FeatureCollection';
196
+ features: ImportedFeature[];
197
+ stats: ImportStats;
198
+ }
199
+ interface ImportOptions {
200
+ /** 数据来源标注(用于坐标系判断,如 '高德'/'GPS') */
201
+ source?: string;
202
+ /** 自定义地址解析函数(默认内置 parseAddress) */
203
+ parse?: (raw: string) => ParsedAddress;
204
+ }
205
+ /**
206
+ * 表格式数据 → GeoJSON。
207
+ * @param headers 表头数组
208
+ * @param rows 数据行(二维数组,与 headers 对齐)
209
+ */
210
+ declare function importToGeoJSON(headers: string[], rows: Array<Array<string | number>>, opts?: ImportOptions): ImportResult;
211
+
212
+ export { type BatchGeocodeInput, type BatchGeocodeOutput, CHINA_BOUNDS, type DetectedCRS, type GeocodeResult, type HeaderDetection, type ImportOptions, type ImportResult, type ImportStats, type ImportedFeature, LOCAL_GEO_DB, type ParsedAddress, batchGeocode, detectCRS, detectHeaders, gcj02ToWgs84, geocode, hasLocalGeo, importToGeoJSON, isInChina, isValidAddress, parseAddress, wgs84ToGcj02 };
@@ -0,0 +1,212 @@
1
+ /**
2
+ * GeoAI 中文地址解析(PRD phase-0 §5.6 G-2)
3
+ *
4
+ * 将非标准中文地址(含口语化、简称)解析为标准化结构:
5
+ * province / city / district / street / poi / number
6
+ *
7
+ * 采用「词典匹配 + 规则」的传统 NLP 方案(不依赖大模型),保证速度与可控性。
8
+ */
9
+ interface ParsedAddress {
10
+ /** 原始输入 */
11
+ raw: string;
12
+ /** 省 */
13
+ province?: string;
14
+ /** 市 */
15
+ city?: string;
16
+ /** 区/县 */
17
+ district?: string;
18
+ /** 街道/路/道 */
19
+ street?: string;
20
+ /** 门牌号 */
21
+ number?: string;
22
+ /** 地标/POI(如"光谷""汉口火车站") */
23
+ poi?: string;
24
+ /** 标准化地址(可读拼接) */
25
+ normalized: string;
26
+ /** 解析置信度 0-1 */
27
+ confidence: number;
28
+ }
29
+ /**
30
+ * 解析中文地址。
31
+ *
32
+ * 覆盖:
33
+ * - 完整地址:"湖北省武汉市洪山区光谷大道 1 号"
34
+ * - 简称:"武汉光谷"、"洪山区"
35
+ * - 口语化:"光谷那边"、"汉口火车站附近"
36
+ */
37
+ declare function parseAddress(raw: string): ParsedAddress;
38
+ /** 判断是否为有效地址(至少命中省/市/区/POI 之一) */
39
+ declare function isValidAddress(parsed: ParsedAddress): boolean;
40
+
41
+ /**
42
+ * GeoAI 表头自动识别(PRD phase-0 §5.6 G-1)
43
+ *
44
+ * 从 CSV/Excel 表头中自动识别:
45
+ * - 地址列(addressCol)
46
+ * - 名称列(nameCol)
47
+ * - 分类列(categoryCol)
48
+ * - 经度列(lngCol)/ 纬度列(latCol)
49
+ *
50
+ * 采用「列名语义 + 正则匹配」方案,命中率目标 ≥ 90%。
51
+ */
52
+ interface HeaderDetection {
53
+ /** 地址列索引(-1 表示未识别) */
54
+ addressCol: number;
55
+ /** 名称列索引 */
56
+ nameCol: number;
57
+ /** 分类列索引 */
58
+ categoryCol: number;
59
+ /** 经度列索引 */
60
+ lngCol: number;
61
+ /** 纬度列索引 */
62
+ latCol: number;
63
+ /** 识别详情(供上层展示/纠错) */
64
+ detail: Record<string, string>;
65
+ }
66
+ /**
67
+ * 识别表头。
68
+ * @param headers 表头数组(CSV 首行 / Excel 首行)
69
+ */
70
+ declare function detectHeaders(headers: string[]): HeaderDetection;
71
+
72
+ /**
73
+ * GeoAI 坐标系判断(PRD phase-0 §5.6 G-3)
74
+ *
75
+ * 判断数据坐标所属坐标系:WGS84 / GCJ-02 / CGCS2000。
76
+ *
77
+ * 说明:单点无法 100% 判定坐标系(GCJ-02 偏移仅数百米),
78
+ * 本模块采用「范围校验 + 数据来源推断 + 中国境外判定」的组合启发式,
79
+ * 并提供 GCJ-02 ↔ WGS84 双向纠偏转换。
80
+ */
81
+ type DetectedCRS = 'wgs84' | 'gcj02' | 'cgcs2000' | 'unknown';
82
+ /** 中国经纬度范围(粗判) */
83
+ declare const CHINA_BOUNDS: {
84
+ lngMin: number;
85
+ lngMax: number;
86
+ latMin: number;
87
+ latMax: number;
88
+ };
89
+ /** WGS84 → GCJ-02(加密偏移) */
90
+ declare function wgs84ToGcj02(lng: number, lat: number): [number, number];
91
+ /** GCJ-02 → WGS84(纠偏,迭代逼近) */
92
+ declare function gcj02ToWgs84(lng: number, lat: number): [number, number];
93
+ /** 坐标是否在中国境内 */
94
+ declare function isInChina(lng: number, lat: number): boolean;
95
+ /**
96
+ * 判断坐标系。
97
+ * @param source 数据来源标注(如 '高德' / '腾讯' / '天地图' / 'GPS' / undefined)
98
+ * @param sample 抽样坐标对
99
+ */
100
+ declare function detectCRS(source: string | undefined, sample?: Array<[number, number]>): DetectedCRS;
101
+
102
+ /**
103
+ * GeoAI 批量地理编码(PRD phase-0 §5.6 G-4)
104
+ *
105
+ * 将解析后的中文地址编码为坐标 [lng, lat]。
106
+ * v1 使用「本地坐标库 + 模糊匹配」(离线、不依赖天地图/高德 API),
107
+ * 命中率目标:标准地址 ≥ 90%,口语化地址 ≥ 60%。
108
+ */
109
+
110
+ /** 本地地理坐标库:地名 → [lng, lat](WGS84) */
111
+ declare const LOCAL_GEO_DB: Record<string, [number, number]>;
112
+ interface GeocodeResult {
113
+ lng: number;
114
+ lat: number;
115
+ /** 匹配到的地名 */
116
+ matched: string;
117
+ /** 置信度 0-1 */
118
+ confidence: number;
119
+ }
120
+ /**
121
+ * 地理编码:地址 → 坐标。
122
+ *
123
+ * 匹配优先级:
124
+ * 1. POI(最精确)
125
+ * 2. 区/县
126
+ * 3. 城市
127
+ * 4. 省(降级)
128
+ *
129
+ * 无法匹配返回 null。
130
+ */
131
+ declare function geocode(parsed: ParsedAddress): GeocodeResult | null;
132
+ /** 查询本地库是否存在某地名 */
133
+ declare function hasLocalGeo(name: string): boolean;
134
+ interface BatchGeocodeInput {
135
+ /** 原始地址字符串 */
136
+ address: string;
137
+ /** 已有经度(可选,优先级最高) */
138
+ lng?: number;
139
+ /** 已有纬度(可选) */
140
+ lat?: number;
141
+ }
142
+ interface BatchGeocodeOutput {
143
+ lng: number;
144
+ lat: number;
145
+ /** 坐标来源:'provided' | 'geocoded' | 'failed' */
146
+ source: 'provided' | 'geocoded' | 'failed';
147
+ matched?: string;
148
+ confidence: number;
149
+ }
150
+ /**
151
+ * 批量地理编码:对一批记录并行编码。
152
+ *
153
+ * 优先级:已有经纬度 > 地址解析 + 本地库编码。
154
+ */
155
+ declare function batchGeocode(rows: BatchGeocodeInput[], parse: (raw: string) => ParsedAddress): BatchGeocodeOutput[];
156
+
157
+ /**
158
+ * GeoAI 数据入图主入口(PRD phase-0 §5.6)
159
+ *
160
+ * 完整管线:
161
+ * CSV/Excel 表头 → 表头识别 → 逐行地址解析 → 地理编码 / 坐标纠偏 → GeoJSON
162
+ *
163
+ * 用法:
164
+ * const result = importToGeoJSON(headers, rows);
165
+ * result.features // GeoJSON FeatureCollection
166
+ * result.stats // 命中率 / 编码耗时等
167
+ */
168
+
169
+ interface ImportedFeature {
170
+ type: 'Feature';
171
+ geometry: {
172
+ type: 'Point';
173
+ coordinates: [number, number];
174
+ } | {
175
+ type: 'Point';
176
+ coordinates: [];
177
+ };
178
+ properties: Record<string, unknown>;
179
+ }
180
+ interface ImportStats {
181
+ /** 总记录数 */
182
+ total: number;
183
+ /** 成功编码数 */
184
+ success: number;
185
+ /** 失败数 */
186
+ failed: number;
187
+ /** 成功率 0-1 */
188
+ successRate: number;
189
+ /** 识别出的表头 */
190
+ headers: HeaderDetection;
191
+ /** 编码耗时(ms) */
192
+ durationMs: number;
193
+ }
194
+ interface ImportResult {
195
+ type: 'FeatureCollection';
196
+ features: ImportedFeature[];
197
+ stats: ImportStats;
198
+ }
199
+ interface ImportOptions {
200
+ /** 数据来源标注(用于坐标系判断,如 '高德'/'GPS') */
201
+ source?: string;
202
+ /** 自定义地址解析函数(默认内置 parseAddress) */
203
+ parse?: (raw: string) => ParsedAddress;
204
+ }
205
+ /**
206
+ * 表格式数据 → GeoJSON。
207
+ * @param headers 表头数组
208
+ * @param rows 数据行(二维数组,与 headers 对齐)
209
+ */
210
+ declare function importToGeoJSON(headers: string[], rows: Array<Array<string | number>>, opts?: ImportOptions): ImportResult;
211
+
212
+ export { type BatchGeocodeInput, type BatchGeocodeOutput, CHINA_BOUNDS, type DetectedCRS, type GeocodeResult, type HeaderDetection, type ImportOptions, type ImportResult, type ImportStats, type ImportedFeature, LOCAL_GEO_DB, type ParsedAddress, batchGeocode, detectCRS, detectHeaders, gcj02ToWgs84, geocode, hasLocalGeo, importToGeoJSON, isInChina, isValidAddress, parseAddress, wgs84ToGcj02 };
@@ -0,0 +1,3 @@
1
+ export { CHINA_BOUNDS, LOCAL_GEO_DB, batchGeocode, detectCRS, detectHeaders, gcj02ToWgs84, geocode, hasLocalGeo, importToGeoJSON, isInChina, isValidAddress, parseAddress, wgs84ToGcj02 } from '../chunk-HF3HJPXD.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}