simplify-geojson-visvalingam 1.2.3 → 1.2.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.
- package/README.md +111 -1
- package/package.json +11 -7
package/README.md
CHANGED
|
@@ -1,3 +1,113 @@
|
|
|
1
|
+
[![Version Badge][npm-img]][npm-url]
|
|
2
|
+
|
|
1
3
|
# simplify-geojson-visvalingam
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
[npm-img]: https://img.shields.io/npm/v/simplify-geojson-visvalingam.svg
|
|
6
|
+
[npm-url]: https://www.npmjs.com/package/simplify-geojson-visvalingam
|
|
7
|
+
|
|
8
|
+
Takes a [GeoJSON][1] object and returns a simplified version. Uses the [Visvalingam–Wyatt][2] algorithm with additional logic for stable simplification and preservation of common boundaries.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
```
|
|
12
|
+
npm i --save simplify-geojson-visvalingam
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
* `geojson` **[GeoJSON][1]** object to be simplified, should extends [GeoJsonObject][6] in TypeScript
|
|
18
|
+
* `options` **[Object][3]** Optional parameters (optional, default `{}`), should be of type [SimplifyOptions][7] in TypeScript
|
|
19
|
+
|
|
20
|
+
* `options.tolerance` **[number][4]** simplification tolerance, the minimum Cartesian area of a triangle formed by a point and its two neighbors to preserve that point (optional, default `undefined`, **disables simplification if not provided**)
|
|
21
|
+
* `options.mutate` **[boolean][5]** allows GeoJSON input to be mutated (optional, default `true`)
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
### JS
|
|
25
|
+
```javascript
|
|
26
|
+
import simplify from 'simplify-geojson-visvalingam'
|
|
27
|
+
|
|
28
|
+
// CommonJS
|
|
29
|
+
// const simplify = require('simplify-geojson-visvalingam').default
|
|
30
|
+
|
|
31
|
+
const geojson = {
|
|
32
|
+
"type": "Polygon",
|
|
33
|
+
"coordinates": [
|
|
34
|
+
[
|
|
35
|
+
[-70.603637, -33.399918],
|
|
36
|
+
[-70.614624, -33.395332],
|
|
37
|
+
[-70.639343, -33.392466],
|
|
38
|
+
[-70.659942, -33.394759],
|
|
39
|
+
[-70.683975, -33.404504],
|
|
40
|
+
[-70.697021, -33.419406],
|
|
41
|
+
[-70.701141, -33.434306],
|
|
42
|
+
[-70.700454, -33.446339],
|
|
43
|
+
[-70.694274, -33.458369],
|
|
44
|
+
[-70.682601, -33.465816],
|
|
45
|
+
[-70.668869, -33.472117],
|
|
46
|
+
[-70.646209, -33.473835],
|
|
47
|
+
[-70.624923, -33.472117],
|
|
48
|
+
[-70.609817, -33.468107],
|
|
49
|
+
[-70.595397, -33.458369],
|
|
50
|
+
[-70.587158, -33.442901],
|
|
51
|
+
[-70.587158, -33.426283],
|
|
52
|
+
[-70.590591, -33.414248],
|
|
53
|
+
[-70.594711, -33.406224],
|
|
54
|
+
[-70.603637, -33.399918]
|
|
55
|
+
]
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
const options = {
|
|
59
|
+
tolerance: 0.00008,
|
|
60
|
+
}
|
|
61
|
+
const result = simplify(geojson, options)
|
|
62
|
+
```
|
|
63
|
+
### TS
|
|
64
|
+
```typescript
|
|
65
|
+
import { type Polygon } from 'geojson'
|
|
66
|
+
import simplify, { type SimplifyOptions } from 'simplify-geojson-visvalingam'
|
|
67
|
+
|
|
68
|
+
const geojson: Polygon = {
|
|
69
|
+
"type": "Polygon",
|
|
70
|
+
"coordinates": [
|
|
71
|
+
[
|
|
72
|
+
[-70.603637, -33.399918],
|
|
73
|
+
[-70.614624, -33.395332],
|
|
74
|
+
[-70.639343, -33.392466],
|
|
75
|
+
[-70.659942, -33.394759],
|
|
76
|
+
[-70.683975, -33.404504],
|
|
77
|
+
[-70.697021, -33.419406],
|
|
78
|
+
[-70.701141, -33.434306],
|
|
79
|
+
[-70.700454, -33.446339],
|
|
80
|
+
[-70.694274, -33.458369],
|
|
81
|
+
[-70.682601, -33.465816],
|
|
82
|
+
[-70.668869, -33.472117],
|
|
83
|
+
[-70.646209, -33.473835],
|
|
84
|
+
[-70.624923, -33.472117],
|
|
85
|
+
[-70.609817, -33.468107],
|
|
86
|
+
[-70.595397, -33.458369],
|
|
87
|
+
[-70.587158, -33.442901],
|
|
88
|
+
[-70.587158, -33.426283],
|
|
89
|
+
[-70.590591, -33.414248],
|
|
90
|
+
[-70.594711, -33.406224],
|
|
91
|
+
[-70.603637, -33.399918]
|
|
92
|
+
]
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
const options: SimplifyOptions = {
|
|
96
|
+
tolerance: 0.00008,
|
|
97
|
+
}
|
|
98
|
+
const result = simplify(geojson, options)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
[1]: https://tools.ietf.org/html/rfc7946#section-3
|
|
102
|
+
|
|
103
|
+
[2]: https://en.wikipedia.org/wiki/Visvalingam%E2%80%93Whyatt_algorithm
|
|
104
|
+
|
|
105
|
+
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
106
|
+
|
|
107
|
+
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
108
|
+
|
|
109
|
+
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
110
|
+
|
|
111
|
+
[6]: https://www.npmjs.com/package/@types/geojson
|
|
112
|
+
|
|
113
|
+
[7]: https://github.com/iamaleko/simplify-geojson-visvalingam/blob/56aece32122cb38f2d1cfc2e23a2b366d1e8ae5b/src/index.ts#L15
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simplify-geojson-visvalingam",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "GeoJSON simplification library using the Visvalingam algorithm for efficient point reduction and geometry preservation.",
|
|
5
5
|
"author": "Alexander Kolobov",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,13 +21,17 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/iamaleko/simplify-geojson-visvalingam#readme",
|
|
23
23
|
"type": "module",
|
|
24
|
-
"main": "dist/index.
|
|
25
|
-
"module": "dist/index.
|
|
26
|
-
"types": "dist/index.d.ts",
|
|
24
|
+
"main": "./dist/index.cjs",
|
|
25
|
+
"module": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
27
|
"exports": {
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./dist/index.d.cts",
|
|
34
|
+
"require": "./dist/index.cjs"
|
|
31
35
|
}
|
|
32
36
|
},
|
|
33
37
|
"files": [
|