@idm-plugin/geo 2.1.6 → 2.1.7
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.
- package/dist/index.js +447 -307
- package/dist/index.umd.cjs +4 -4
- package/dist/json/src/index.d.ts +49 -1
- package/package.json +11 -1
package/dist/json/src/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
1
3
|
import * as turf from '@turf/turf';
|
|
2
4
|
export interface GeoJsonOptions {
|
|
3
5
|
/** 圆的边数,默认64 */
|
|
@@ -14,6 +16,14 @@ export interface GeoJsonOptions {
|
|
|
14
16
|
properties?: Record<string, any>;
|
|
15
17
|
}
|
|
16
18
|
export declare class GeoJsonHelper {
|
|
19
|
+
/**
|
|
20
|
+
* Buffer to ArrayBuffer
|
|
21
|
+
* 将 Node.js Buffer 转换为独立的 ArrayBuffer(byteOffset=0)。
|
|
22
|
+
* Node.js 的 Buffer.concat() 返回的 Buffer 共享内存池,直接用 .buffer 会读到错误偏移。
|
|
23
|
+
* @param buf
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
static toArrayBuffer(buf: Buffer): ArrayBuffer;
|
|
17
27
|
/**
|
|
18
28
|
* 基于turf画圆,返回GeoJSON Feature<Polygon>
|
|
19
29
|
* @param lng 圆心经度
|
|
@@ -84,11 +94,49 @@ export declare class GeoJsonHelper {
|
|
|
84
94
|
* 如果feature是多边形,则返回多边形的顶点和多边形Feature
|
|
85
95
|
*/
|
|
86
96
|
static parsePolygon(feature: turf.Feature<turf.Polygon>, options?: GeoJsonOptions): turf.FeatureCollection<any>;
|
|
97
|
+
/**
|
|
98
|
+
* 解压 DEFLATE raw 数据(ZIP compressionMethod=8)。
|
|
99
|
+
* Node.js 环境使用内置 zlib.inflateRawSync;浏览器环境抛出错误提示使用异步版本。
|
|
100
|
+
*/
|
|
101
|
+
private static _inflateRawSync;
|
|
102
|
+
/**
|
|
103
|
+
* 从 ZIP ArrayBuffer 中异步解析所有文件条目(浏览器 DecompressionStream)。
|
|
104
|
+
*/
|
|
105
|
+
private static _parseZipEntries;
|
|
87
106
|
/**
|
|
88
107
|
* 将KML转换为GeoJSON
|
|
89
108
|
* @param kml
|
|
90
109
|
* @param options
|
|
91
110
|
* @returns
|
|
92
111
|
*/
|
|
93
|
-
static convertKML2GeoJSON(kml: string, options?: GeoJsonOptions): turf.FeatureCollection<any
|
|
112
|
+
static convertKML2GeoJSON(kml: string, options?: GeoJsonOptions): Promise<turf.helpers.FeatureCollection<any, turf.helpers.Properties>>;
|
|
113
|
+
/**
|
|
114
|
+
* 将 KMZ(ZIP 内含 doc.kml 或首个 .kml 文件)异步转换为 GeoJSON。
|
|
115
|
+
* 浏览器环境通过 DecompressionStream 解压,Node.js 自动降级为同步 zlib。
|
|
116
|
+
* 典型用法:
|
|
117
|
+
* const buffer = await file.arrayBuffer() // 或 FileReader.readAsArrayBuffer()
|
|
118
|
+
* const geoJson = await GeoJsonHelper.convertKMZ2GeoJSONAsync(buffer)
|
|
119
|
+
* @param buffer KMZ 文件的 ArrayBuffer
|
|
120
|
+
* @param options
|
|
121
|
+
*/
|
|
122
|
+
static convertKMZ2GeoJSON(buffer: ArrayBuffer | Buffer, options?: GeoJsonOptions): Promise<turf.FeatureCollection<any>>;
|
|
123
|
+
/**
|
|
124
|
+
* 将 ZIP 文件中所有 .kml 文件合并转换为一个 GeoJSON FeatureCollection(异步)。
|
|
125
|
+
* 浏览器环境通过 DecompressionStream 解压,Node.js 自动降级为同步 zlib。
|
|
126
|
+
* 典型用法:
|
|
127
|
+
* const buffer = await file.arrayBuffer() // 或 FileReader.readAsArrayBuffer()
|
|
128
|
+
* const geoJson = await GeoJsonHelper.convertZIP2GeoJSONAsync(buffer)
|
|
129
|
+
* @param buffer ZIP 文件的 ArrayBuffer
|
|
130
|
+
* @param options
|
|
131
|
+
*/
|
|
132
|
+
static convertZIP2GeoJSON(buffer: ArrayBuffer | Buffer, options?: GeoJsonOptions): Promise<turf.FeatureCollection<any>>;
|
|
133
|
+
/**
|
|
134
|
+
* 将 Shapefile ZIP(含 .shp/.shx/.dbf/.prj)转换为 GeoJSON FeatureCollection。
|
|
135
|
+
* - ZIP 中可包含多组 shapefile(如 input1.shp + input2.shp)
|
|
136
|
+
* - .prj 投影文件会自动转换为 WGS84(由 shpjs + proj4 处理)
|
|
137
|
+
* - .dbf 属性字段会合并到每个 Feature 的 properties 中
|
|
138
|
+
* @param buffer ZIP 文件的 ArrayBuffer
|
|
139
|
+
* @param options
|
|
140
|
+
*/
|
|
141
|
+
static convertSHP2GeoJSON(buffer: ArrayBuffer | Buffer, options?: GeoJsonOptions): Promise<turf.FeatureCollection<any>>;
|
|
94
142
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idm-plugin/geo",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.7",
|
|
5
5
|
"description": "idm plugin for geo in browser",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [
|
|
@@ -33,9 +33,18 @@
|
|
|
33
33
|
"moment-timezone": "^0.5.45",
|
|
34
34
|
"tz-lookup": "^6.1.25"
|
|
35
35
|
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"shpjs": "^6.2.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"shpjs": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
36
44
|
"devDependencies": {
|
|
37
45
|
"@types/jest": "^25.2.2",
|
|
38
46
|
"@types/node": "^18.14.2",
|
|
47
|
+
"@types/shpjs": "^3.4.7",
|
|
39
48
|
"@types/tz-lookup": "^6.1.2",
|
|
40
49
|
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
41
50
|
"@typescript-eslint/parser": "^5.53.0",
|
|
@@ -48,6 +57,7 @@
|
|
|
48
57
|
"lint-staged": "^13.1.2",
|
|
49
58
|
"prettier": "^2.8.4",
|
|
50
59
|
"sass": "^1.58.3",
|
|
60
|
+
"shpjs": "6.2.0",
|
|
51
61
|
"simple-git-hooks": "^2.8.1",
|
|
52
62
|
"stylelint": "^15.2.0",
|
|
53
63
|
"supertest": "^4.0.2",
|