wkt-parse-and-geojson 1.0.0
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/README.md +656 -0
- package/dist/geojson-builder.d.ts +92 -0
- package/dist/geojson-to-wkt.d.ts +32 -0
- package/dist/index.cjs.js +673 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.esm.js +654 -0
- package/dist/index.umd.js +679 -0
- package/dist/types.d.ts +51 -0
- package/dist/wkt-builder.d.ts +17 -0
- package/dist/wkt-parser.d.ts +33 -0
- package/dist/wkt-to-geojson.d.ts +35 -0
- package/package.json +26 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Position, Geometry, Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, GeometryCollection } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* GeoJSON 几何对象构建器(类形式,方便组合使用)
|
|
4
|
+
*/
|
|
5
|
+
export declare class GeoJSONBuilder {
|
|
6
|
+
createPoint(x: number, y: number, z?: number): Point;
|
|
7
|
+
createLineString(coordinates: Position[]): LineString;
|
|
8
|
+
/**
|
|
9
|
+
* 创建 Polygon。
|
|
10
|
+
* - 传入 `Position[]`:视为单个外环,自动包装为 `[ring]`
|
|
11
|
+
* - 传入 `Position[][]`:视为完整的环列表(外环 + 内环/空洞)
|
|
12
|
+
*/
|
|
13
|
+
createPolygon(coordinates: Position[] | Position[][]): Polygon;
|
|
14
|
+
/**
|
|
15
|
+
* 创建 MultiPoint。
|
|
16
|
+
* - 传入 `Position`:视为单个点,自动包装为 `[point]`
|
|
17
|
+
* - 传入 `Position[]`:视为多个点
|
|
18
|
+
*/
|
|
19
|
+
createMultiPoint(coordinates: Position | Position[]): MultiPoint;
|
|
20
|
+
/**
|
|
21
|
+
* 创建 MultiLineString。
|
|
22
|
+
* - 传入 `Position[]`:视为单条线,自动包装为 `[line]`
|
|
23
|
+
* - 传入 `Position[][]`:视为多条线
|
|
24
|
+
*/
|
|
25
|
+
createMultiLineString(coordinates: Position[] | Position[][]): MultiLineString;
|
|
26
|
+
/**
|
|
27
|
+
* 创建 MultiPolygon。
|
|
28
|
+
* - 传入 `Position[][]`:视为单个多边形(环列表),自动包装为 `[polygon]`
|
|
29
|
+
* - 传入 `Position[][][]`:视为多个多边形
|
|
30
|
+
*/
|
|
31
|
+
createMultiPolygon(coordinates: Position[][] | Position[][][]): MultiPolygon;
|
|
32
|
+
/**
|
|
33
|
+
* 创建 GeometryCollection。
|
|
34
|
+
* - 传入单个 `Geometry`:自动包装为 `[geometry]`
|
|
35
|
+
* - 传入 `Geometry[]`:直接使用
|
|
36
|
+
*/
|
|
37
|
+
createGeometryCollection(geometries: Geometry | Geometry[]): GeometryCollection;
|
|
38
|
+
}
|
|
39
|
+
/** 创建 Point */
|
|
40
|
+
export declare function createPoint(x: number, y: number, z?: number): Point;
|
|
41
|
+
/** 创建 LineString */
|
|
42
|
+
export declare function createLineString(coordinates: Position[]): LineString;
|
|
43
|
+
/**
|
|
44
|
+
* 创建 Polygon。
|
|
45
|
+
* - 传入 `Position[]`:单个外环,自动包装
|
|
46
|
+
* - 传入 `Position[][]`:外环 + 内环(空洞)
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* createPolygon([[0,0],[1,0],[1,1],[0,1],[0,0]])
|
|
50
|
+
* createPolygon([[[0,0],[10,0],[10,10],[0,10],[0,0]], [[2,2],[4,2],[4,4],[2,4],[2,2]]])
|
|
51
|
+
*/
|
|
52
|
+
export declare function createPolygon(coordinates: Position[] | Position[][]): Polygon;
|
|
53
|
+
/**
|
|
54
|
+
* 创建 MultiPoint。
|
|
55
|
+
* - 传入 `Position`:单个点
|
|
56
|
+
* - 传入 `Position[]`:多个点
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* createMultiPoint([0, 0])
|
|
60
|
+
* createMultiPoint([[0,0],[1,1],[2,2]])
|
|
61
|
+
*/
|
|
62
|
+
export declare function createMultiPoint(coordinates: Position | Position[]): MultiPoint;
|
|
63
|
+
/**
|
|
64
|
+
* 创建 MultiLineString。
|
|
65
|
+
* - 传入 `Position[]`:单条线
|
|
66
|
+
* - 传入 `Position[][]`:多条线
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* createMultiLineString([[0,0],[1,1]])
|
|
70
|
+
* createMultiLineString([[[0,0],[1,1]], [[2,2],[3,3]]])
|
|
71
|
+
*/
|
|
72
|
+
export declare function createMultiLineString(coordinates: Position[] | Position[][]): MultiLineString;
|
|
73
|
+
/**
|
|
74
|
+
* 创建 MultiPolygon。
|
|
75
|
+
* - 传入 `Position[][]`:单个多边形(环列表)
|
|
76
|
+
* - 传入 `Position[][][]`:多个多边形
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* createMultiPolygon([[[0,0],[1,0],[1,1],[0,1],[0,0]]])
|
|
80
|
+
* createMultiPolygon([[[[0,0],[1,0],[1,1],[0,1],[0,0]]], [[[2,2],[3,2],[3,3],[2,3],[2,2]]]])
|
|
81
|
+
*/
|
|
82
|
+
export declare function createMultiPolygon(coordinates: Position[][] | Position[][][]): MultiPolygon;
|
|
83
|
+
/**
|
|
84
|
+
* 创建 GeometryCollection。
|
|
85
|
+
* - 传入单个 `Geometry`:自动包装
|
|
86
|
+
* - 传入 `Geometry[]`:直接使用
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* createGeometryCollection(createPoint(0, 0))
|
|
90
|
+
* createGeometryCollection([createPoint(0,0), createLineString([[0,0],[1,1]])])
|
|
91
|
+
*/
|
|
92
|
+
export declare function createGeometryCollection(geometries: Geometry | Geometry[]): GeometryCollection;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Geometry, Feature, FeatureCollection } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 将 GeoJSON Geometry 对象转换为 WKT 字符串。
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* geojsonToWkt({ type: 'Point', coordinates: [30.5, 40.5] })
|
|
7
|
+
* // → 'POINT (30.5 40.5)'
|
|
8
|
+
*
|
|
9
|
+
* geojsonToWkt({ type: 'Polygon', coordinates: [[[0,0],[1,0],[1,1],[0,1],[0,0]]] })
|
|
10
|
+
* // → 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))'
|
|
11
|
+
*/
|
|
12
|
+
export declare function geojsonToWkt(geojson: Geometry): string;
|
|
13
|
+
/**
|
|
14
|
+
* 将 GeoJSON Feature 对象转换为 WKT 字符串(取 geometry 部分)。
|
|
15
|
+
*
|
|
16
|
+
* @throws 若 Feature.geometry 为 null,则抛出错误
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* featureToWkt({ type: 'Feature', geometry: { type: 'Point', coordinates: [0, 0] }, properties: null })
|
|
20
|
+
* // → 'POINT (0 0)'
|
|
21
|
+
*/
|
|
22
|
+
export declare function featureToWkt(feature: Feature): string;
|
|
23
|
+
/**
|
|
24
|
+
* 将 GeoJSON FeatureCollection 中所有 Feature 转换为 WKT 字符串数组。
|
|
25
|
+
*
|
|
26
|
+
* geometry 为 null 的 Feature 会被跳过(返回数组中对应位置为 null)。
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* featureCollectionToWkt({ type: 'FeatureCollection', features: [...] })
|
|
30
|
+
* // → ['POINT (0 0)', 'LINESTRING (0 0, 1 1)', ...]
|
|
31
|
+
*/
|
|
32
|
+
export declare function featureCollectionToWkt(fc: FeatureCollection): Array<string | null>;
|