@idm-plugin/geo 2.1.5 → 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.
@@ -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 圆心经度
@@ -31,13 +41,12 @@ export declare class GeoJsonHelper {
31
41
  static drawRect(start: number[], end: number[], options?: GeoJsonOptions): turf.Feature<turf.Polygon>;
32
42
  /**
33
43
  * 基于turf画线,返回GeoJSON Feature<LineString>
34
- * 需要注意跨180度的情况
35
- * @param start
36
- * @param end
44
+ * 支持2个或以上的点,需要注意跨180度的情况
45
+ * @param coordinates 坐标点数组,每个元素为 [lng, lat],至少2个点
37
46
  * @param options
38
47
  * @returns
39
48
  */
40
- static drawLine(start: number[], end: number[], options?: GeoJsonOptions): turf.Feature<turf.LineString>;
49
+ static drawLine(coordinates: number[][], options?: GeoJsonOptions): turf.Feature<turf.LineString>;
41
50
  /**
42
51
  * 基于turf画多边形,返回GeoJSON Feature<Polygon>
43
52
  * @param coordinates
@@ -45,6 +54,14 @@ export declare class GeoJsonHelper {
45
54
  * @returns
46
55
  */
47
56
  static drawPolygon(coordinates: number[][], options?: GeoJsonOptions): turf.Feature<turf.Polygon>;
57
+ /**
58
+ * 基于turf画点,返回GeoJSON Feature<Point>
59
+ * @param lat
60
+ * @param lng
61
+ * @param options
62
+ * @returns
63
+ */
64
+ static drawPoint(lat: number, lng: number, options?: GeoJsonOptions): turf.Feature<turf.Point>;
48
65
  /**
49
66
  * 解析ORM GeoJSON Feature (圆), 返回FeatureCollection
50
67
  * @param feature
@@ -66,7 +83,7 @@ export declare class GeoJsonHelper {
66
83
  * @param feature
67
84
  * @param options
68
85
  * @returns
69
- * 如果feature是线,则返回线的起点和终点以及线Feature
86
+ * 如果feature是线,则返回所有坐标点(首为start、尾为end、中间为point_N)以及线Feature
70
87
  */
71
88
  static parseLine(feature: turf.Feature<turf.LineString>, options?: GeoJsonOptions): turf.FeatureCollection<any>;
72
89
  /**
@@ -77,4 +94,49 @@ export declare class GeoJsonHelper {
77
94
  * 如果feature是多边形,则返回多边形的顶点和多边形Feature
78
95
  */
79
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;
106
+ /**
107
+ * 将KML转换为GeoJSON
108
+ * @param kml
109
+ * @param options
110
+ * @returns
111
+ */
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>>;
80
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.5",
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",