@turf/simplify 7.0.0-alpha.2 → 7.1.0-alpha.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/README.md +5 -10
- package/dist/cjs/index.cjs +155 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +50 -0
- package/dist/esm/index.d.ts +50 -0
- package/dist/esm/index.js +155 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +37 -28
- package/dist/es/index.js +0 -300
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -308
- package/index.d.ts +0 -13
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## simplify
|
|
6
6
|
|
|
7
|
-
Takes a [GeoJSON][1] object and returns a simplified version. Internally uses
|
|
7
|
+
Takes a [GeoJSON][1] object and returns a simplified version. Internally uses the 2d version of
|
|
8
8
|
[simplify-js][2] to perform simplification using the Ramer-Douglas-Peucker algorithm.
|
|
9
9
|
|
|
10
10
|
### Parameters
|
|
@@ -62,26 +62,21 @@ Returns **[GeoJSON][3]** a simplified GeoJSON
|
|
|
62
62
|
|
|
63
63
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
64
64
|
|
|
65
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
66
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
67
|
-
./scripts/generate-readmes in the turf project. -->
|
|
65
|
+
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
|
|
68
66
|
|
|
69
67
|
---
|
|
70
68
|
|
|
71
|
-
This module is part of the [Turfjs project](
|
|
72
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
73
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
74
|
-
PRs and issues.
|
|
69
|
+
This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
|
|
75
70
|
|
|
76
71
|
### Installation
|
|
77
72
|
|
|
78
|
-
Install this module individually:
|
|
73
|
+
Install this single module individually:
|
|
79
74
|
|
|
80
75
|
```sh
|
|
81
76
|
$ npm install @turf/simplify
|
|
82
77
|
```
|
|
83
78
|
|
|
84
|
-
Or install the
|
|
79
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
85
80
|
|
|
86
81
|
```sh
|
|
87
82
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
|
|
2
|
+
var _cleancoords = require('@turf/clean-coords');
|
|
3
|
+
var _clone = require('@turf/clone');
|
|
4
|
+
var _meta = require('@turf/meta');
|
|
5
|
+
var _helpers = require('@turf/helpers');
|
|
6
|
+
|
|
7
|
+
// lib/simplify.js
|
|
8
|
+
function getSqDist(p1, p2) {
|
|
9
|
+
var dx = p1[0] - p2[0], dy = p1[1] - p2[1];
|
|
10
|
+
return dx * dx + dy * dy;
|
|
11
|
+
}
|
|
12
|
+
function getSqSegDist(p, p1, p2) {
|
|
13
|
+
var x = p1[0], y = p1[1], dx = p2[0] - x, dy = p2[1] - y;
|
|
14
|
+
if (dx !== 0 || dy !== 0) {
|
|
15
|
+
var t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy);
|
|
16
|
+
if (t > 1) {
|
|
17
|
+
x = p2[0];
|
|
18
|
+
y = p2[1];
|
|
19
|
+
} else if (t > 0) {
|
|
20
|
+
x += dx * t;
|
|
21
|
+
y += dy * t;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
dx = p[0] - x;
|
|
25
|
+
dy = p[1] - y;
|
|
26
|
+
return dx * dx + dy * dy;
|
|
27
|
+
}
|
|
28
|
+
function simplifyRadialDist(points, sqTolerance) {
|
|
29
|
+
var prevPoint = points[0], newPoints = [prevPoint], point;
|
|
30
|
+
for (var i = 1, len = points.length; i < len; i++) {
|
|
31
|
+
point = points[i];
|
|
32
|
+
if (getSqDist(point, prevPoint) > sqTolerance) {
|
|
33
|
+
newPoints.push(point);
|
|
34
|
+
prevPoint = point;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (prevPoint !== point)
|
|
38
|
+
newPoints.push(point);
|
|
39
|
+
return newPoints;
|
|
40
|
+
}
|
|
41
|
+
function simplifyDPStep(points, first, last, sqTolerance, simplified) {
|
|
42
|
+
var maxSqDist = sqTolerance, index;
|
|
43
|
+
for (var i = first + 1; i < last; i++) {
|
|
44
|
+
var sqDist = getSqSegDist(points[i], points[first], points[last]);
|
|
45
|
+
if (sqDist > maxSqDist) {
|
|
46
|
+
index = i;
|
|
47
|
+
maxSqDist = sqDist;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (maxSqDist > sqTolerance) {
|
|
51
|
+
if (index - first > 1)
|
|
52
|
+
simplifyDPStep(points, first, index, sqTolerance, simplified);
|
|
53
|
+
simplified.push(points[index]);
|
|
54
|
+
if (last - index > 1)
|
|
55
|
+
simplifyDPStep(points, index, last, sqTolerance, simplified);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function simplifyDouglasPeucker(points, sqTolerance) {
|
|
59
|
+
var last = points.length - 1;
|
|
60
|
+
var simplified = [points[0]];
|
|
61
|
+
simplifyDPStep(points, 0, last, sqTolerance, simplified);
|
|
62
|
+
simplified.push(points[last]);
|
|
63
|
+
return simplified;
|
|
64
|
+
}
|
|
65
|
+
function simplify(points, tolerance, highestQuality) {
|
|
66
|
+
if (points.length <= 2)
|
|
67
|
+
return points;
|
|
68
|
+
var sqTolerance = tolerance !== void 0 ? tolerance * tolerance : 1;
|
|
69
|
+
points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);
|
|
70
|
+
points = simplifyDouglasPeucker(points, sqTolerance);
|
|
71
|
+
return points;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// index.ts
|
|
75
|
+
function simplify2(geojson, options = {}) {
|
|
76
|
+
var _a, _b, _c;
|
|
77
|
+
options = options != null ? options : {};
|
|
78
|
+
if (!_helpers.isObject.call(void 0, options))
|
|
79
|
+
throw new Error("options is invalid");
|
|
80
|
+
const tolerance = (_a = options.tolerance) != null ? _a : 1;
|
|
81
|
+
const highQuality = (_b = options.highQuality) != null ? _b : false;
|
|
82
|
+
const mutate = (_c = options.mutate) != null ? _c : false;
|
|
83
|
+
if (!geojson)
|
|
84
|
+
throw new Error("geojson is required");
|
|
85
|
+
if (tolerance && tolerance < 0)
|
|
86
|
+
throw new Error("invalid tolerance");
|
|
87
|
+
if (mutate !== true)
|
|
88
|
+
geojson = _clone.clone.call(void 0, geojson);
|
|
89
|
+
_meta.geomEach.call(void 0, geojson, function(geom) {
|
|
90
|
+
simplifyGeom(geom, tolerance, highQuality);
|
|
91
|
+
});
|
|
92
|
+
return geojson;
|
|
93
|
+
}
|
|
94
|
+
function simplifyGeom(geometry, tolerance, highQuality) {
|
|
95
|
+
const type = geometry.type;
|
|
96
|
+
if (type === "Point" || type === "MultiPoint")
|
|
97
|
+
return geometry;
|
|
98
|
+
_cleancoords.cleanCoords.call(void 0, geometry, { mutate: true });
|
|
99
|
+
if (type !== "GeometryCollection") {
|
|
100
|
+
switch (type) {
|
|
101
|
+
case "LineString":
|
|
102
|
+
geometry.coordinates = simplify(
|
|
103
|
+
geometry.coordinates,
|
|
104
|
+
tolerance,
|
|
105
|
+
highQuality
|
|
106
|
+
);
|
|
107
|
+
break;
|
|
108
|
+
case "MultiLineString":
|
|
109
|
+
geometry.coordinates = geometry.coordinates.map(
|
|
110
|
+
(lines) => simplify(lines, tolerance, highQuality)
|
|
111
|
+
);
|
|
112
|
+
break;
|
|
113
|
+
case "Polygon":
|
|
114
|
+
geometry.coordinates = simplifyPolygon(
|
|
115
|
+
geometry.coordinates,
|
|
116
|
+
tolerance,
|
|
117
|
+
highQuality
|
|
118
|
+
);
|
|
119
|
+
break;
|
|
120
|
+
case "MultiPolygon":
|
|
121
|
+
geometry.coordinates = geometry.coordinates.map(
|
|
122
|
+
(rings) => simplifyPolygon(rings, tolerance, highQuality)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return geometry;
|
|
127
|
+
}
|
|
128
|
+
function simplifyPolygon(coordinates, tolerance, highQuality) {
|
|
129
|
+
return coordinates.map(function(ring) {
|
|
130
|
+
if (ring.length < 4) {
|
|
131
|
+
throw new Error("invalid polygon");
|
|
132
|
+
}
|
|
133
|
+
let ringTolerance = tolerance;
|
|
134
|
+
let simpleRing = simplify(ring, ringTolerance, highQuality);
|
|
135
|
+
while (!checkValidity(simpleRing)) {
|
|
136
|
+
ringTolerance -= ringTolerance * 0.01;
|
|
137
|
+
simpleRing = simplify(ring, ringTolerance, highQuality);
|
|
138
|
+
}
|
|
139
|
+
if (simpleRing[simpleRing.length - 1][0] !== simpleRing[0][0] || simpleRing[simpleRing.length - 1][1] !== simpleRing[0][1]) {
|
|
140
|
+
simpleRing.push(simpleRing[0]);
|
|
141
|
+
}
|
|
142
|
+
return simpleRing;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function checkValidity(ring) {
|
|
146
|
+
if (ring.length < 3)
|
|
147
|
+
return false;
|
|
148
|
+
return !(ring.length === 3 && ring[2][0] === ring[0][0] && ring[2][1] === ring[0][1]);
|
|
149
|
+
}
|
|
150
|
+
var turf_simplify_default = simplify2;
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
exports.default = turf_simplify_default; exports.simplify = simplify2;
|
|
155
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts","../../lib/simplify.js"],"names":["simplify"],"mappings":";AACA,SAAS,mBAAmB;AAC5B,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB,SAAqB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,MAAI,KAAK,SAAS;AAAG,WAAO;AAE5B,SAAO,EACL,KAAK,WAAW,KAChB,KAAK,CAAC,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC,KACxB,KAAK,CAAC,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;AAE5B;AAGA,IAAO,wBAAQA","sourcesContent":["import { Geometry, Position } from \"geojson\";\nimport { cleanCoords } from \"@turf/clean-coords\";\nimport { clone } from \"@turf/clone\";\nimport { geomEach } from \"@turf/meta\";\nimport { AllGeoJSON, isObject } from \"@turf/helpers\";\nimport { simplify as simplifyJS } from \"./lib/simplify.js\";\n\n/**\n * Takes a {@link GeoJSON} object and returns a simplified version. Internally uses the 2d version of\n * [simplify-js](http://mourner.github.io/simplify-js/) to perform simplification using the Ramer-Douglas-Peucker algorithm.\n *\n *\n * @name simplify\n * @param {GeoJSON} geojson object to be simplified\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.tolerance=1] simplification tolerance\n * @param {boolean} [options.highQuality=false] whether or not to spend more time to create a higher-quality simplification with a different algorithm\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} a simplified GeoJSON\n * @example\n * var geojson = turf.polygon([[\n * [-70.603637, -33.399918],\n * [-70.614624, -33.395332],\n * [-70.639343, -33.392466],\n * [-70.659942, -33.394759],\n * [-70.683975, -33.404504],\n * [-70.697021, -33.419406],\n * [-70.701141, -33.434306],\n * [-70.700454, -33.446339],\n * [-70.694274, -33.458369],\n * [-70.682601, -33.465816],\n * [-70.668869, -33.472117],\n * [-70.646209, -33.473835],\n * [-70.624923, -33.472117],\n * [-70.609817, -33.468107],\n * [-70.595397, -33.458369],\n * [-70.587158, -33.442901],\n * [-70.587158, -33.426283],\n * [-70.590591, -33.414248],\n * [-70.594711, -33.406224],\n * [-70.603637, -33.399918]\n * ]]);\n * var options = {tolerance: 0.01, highQuality: false};\n * var simplified = turf.simplify(geojson, options);\n *\n * //addToMap\n * var addToMap = [geojson, simplified]\n */\nfunction simplify<T extends AllGeoJSON>(\n geojson: T,\n options: {\n tolerance?: number;\n highQuality?: boolean;\n mutate?: boolean;\n } = {}\n): T {\n // Optional parameters\n options = options ?? {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const tolerance = options.tolerance ?? 1;\n const highQuality = options.highQuality ?? false;\n const mutate = options.mutate ?? false;\n\n if (!geojson) throw new Error(\"geojson is required\");\n if (tolerance && tolerance < 0) throw new Error(\"invalid tolerance\");\n\n // Clone geojson to avoid side effects\n if (mutate !== true) geojson = clone(geojson);\n\n geomEach(geojson, function (geom) {\n simplifyGeom(geom, tolerance, highQuality);\n });\n return geojson;\n}\n\n/**\n * Simplifies a feature's coordinates\n *\n * @private\n * @param {Geometry} geometry to be simplified\n * @param {number} [tolerance=1] simplification tolerance\n * @param {boolean} [highQuality=false] whether or not to spend more time to create a higher-quality simplification with a different algorithm\n * @returns {Geometry} output\n */\nfunction simplifyGeom(\n geometry: Geometry,\n tolerance: number,\n highQuality: boolean\n) {\n const type = geometry.type;\n\n // \"unsimplyfiable\" geometry types\n if (type === \"Point\" || type === \"MultiPoint\") return geometry;\n\n // Remove any extra coordinates\n cleanCoords(geometry, { mutate: true });\n\n if (type !== \"GeometryCollection\") {\n // TODO should this cater for GeometryCollections too?\n switch (type) {\n case \"LineString\":\n geometry.coordinates = simplifyJS(\n geometry.coordinates,\n tolerance,\n highQuality\n );\n break;\n case \"MultiLineString\":\n geometry.coordinates = geometry.coordinates.map((lines) =>\n simplifyJS(lines, tolerance, highQuality)\n );\n break;\n case \"Polygon\":\n geometry.coordinates = simplifyPolygon(\n geometry.coordinates,\n tolerance,\n highQuality\n );\n break;\n case \"MultiPolygon\":\n geometry.coordinates = geometry.coordinates.map((rings) =>\n simplifyPolygon(rings, tolerance, highQuality)\n );\n }\n }\n\n return geometry;\n}\n\n/**\n * Simplifies the coordinates of a Polygon with simplify-js\n *\n * @private\n * @param {Array<number>} coordinates to be processed\n * @param {number} tolerance simplification tolerance\n * @param {boolean} highQuality whether or not to spend more time to create a higher-quality\n * @returns {Array<Array<Array<number>>>} simplified coords\n */\nfunction simplifyPolygon(\n coordinates: Position[][],\n tolerance: number,\n highQuality: boolean\n) {\n return coordinates.map(function (ring) {\n if (ring.length < 4) {\n throw new Error(\"invalid polygon\");\n }\n let ringTolerance = tolerance;\n let simpleRing = simplifyJS(ring, ringTolerance, highQuality);\n // remove 1 percent of tolerance until enough points to make a triangle\n while (!checkValidity(simpleRing)) {\n ringTolerance -= ringTolerance * 0.01;\n simpleRing = simplifyJS(ring, ringTolerance, highQuality);\n }\n if (\n simpleRing[simpleRing.length - 1][0] !== simpleRing[0][0] ||\n simpleRing[simpleRing.length - 1][1] !== simpleRing[0][1]\n ) {\n simpleRing.push(simpleRing[0]);\n }\n return simpleRing;\n });\n}\n\n/**\n * Returns true if ring has at least 3 coordinates and its first coordinate is the same as its last\n *\n * @private\n * @param {Array<number>} ring coordinates to be checked\n * @returns {boolean} true if valid\n */\nfunction checkValidity(ring: Position[]) {\n if (ring.length < 3) return false;\n //if the last point is the same as the first, it's not a triangle\n return !(\n ring.length === 3 &&\n ring[2][0] === ring[0][0] &&\n ring[2][1] === ring[0][1]\n );\n}\n\nexport { simplify };\nexport default simplify;\n","/*\n (c) 2013, Vladimir Agafonkin\n Simplify.js, a high-performance JS polyline simplification library\n mourner.github.io/simplify-js\n*/\n\n// to suit your point format, run search/replace for '.x' and '.y';\n// for 3D version, see 3d branch (configurability would draw significant performance overhead)\n\n// square distance between 2 points\nfunction getSqDist(p1, p2) {\n var dx = p1[0] - p2[0],\n dy = p1[1] - p2[1];\n\n return dx * dx + dy * dy;\n}\n\n// square distance from a point to a segment\nfunction getSqSegDist(p, p1, p2) {\n var x = p1[0],\n y = p1[1],\n dx = p2[0] - x,\n dy = p2[1] - y;\n\n if (dx !== 0 || dy !== 0) {\n var t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy);\n\n if (t > 1) {\n x = p2[0];\n y = p2[1];\n } else if (t > 0) {\n x += dx * t;\n y += dy * t;\n }\n }\n\n dx = p[0] - x;\n dy = p[1] - y;\n\n return dx * dx + dy * dy;\n}\n// rest of the code doesn't care about point format\n\n// basic distance-based simplification\nfunction simplifyRadialDist(points, sqTolerance) {\n var prevPoint = points[0],\n newPoints = [prevPoint],\n point;\n\n for (var i = 1, len = points.length; i < len; i++) {\n point = points[i];\n\n if (getSqDist(point, prevPoint) > sqTolerance) {\n newPoints.push(point);\n prevPoint = point;\n }\n }\n\n if (prevPoint !== point) newPoints.push(point);\n\n return newPoints;\n}\n\nfunction simplifyDPStep(points, first, last, sqTolerance, simplified) {\n var maxSqDist = sqTolerance,\n index;\n\n for (var i = first + 1; i < last; i++) {\n var sqDist = getSqSegDist(points[i], points[first], points[last]);\n\n if (sqDist > maxSqDist) {\n index = i;\n maxSqDist = sqDist;\n }\n }\n\n if (maxSqDist > sqTolerance) {\n if (index - first > 1)\n simplifyDPStep(points, first, index, sqTolerance, simplified);\n simplified.push(points[index]);\n if (last - index > 1)\n simplifyDPStep(points, index, last, sqTolerance, simplified);\n }\n}\n\n// simplification using Ramer-Douglas-Peucker algorithm\nfunction simplifyDouglasPeucker(points, sqTolerance) {\n var last = points.length - 1;\n\n var simplified = [points[0]];\n simplifyDPStep(points, 0, last, sqTolerance, simplified);\n simplified.push(points[last]);\n\n return simplified;\n}\n\n// both algorithms combined for awesome performance\nfunction simplify(points, tolerance, highestQuality) {\n if (points.length <= 2) return points;\n\n var sqTolerance = tolerance !== undefined ? tolerance * tolerance : 1;\n\n points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);\n points = simplifyDouglasPeucker(points, sqTolerance);\n\n return points;\n}\n\nexport { simplify };\nexport default simplify;\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AllGeoJSON } from '@turf/helpers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Takes a {@link GeoJSON} object and returns a simplified version. Internally uses the 2d version of
|
|
5
|
+
* [simplify-js](http://mourner.github.io/simplify-js/) to perform simplification using the Ramer-Douglas-Peucker algorithm.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @name simplify
|
|
9
|
+
* @param {GeoJSON} geojson object to be simplified
|
|
10
|
+
* @param {Object} [options={}] Optional parameters
|
|
11
|
+
* @param {number} [options.tolerance=1] simplification tolerance
|
|
12
|
+
* @param {boolean} [options.highQuality=false] whether or not to spend more time to create a higher-quality simplification with a different algorithm
|
|
13
|
+
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
|
|
14
|
+
* @returns {GeoJSON} a simplified GeoJSON
|
|
15
|
+
* @example
|
|
16
|
+
* var geojson = turf.polygon([[
|
|
17
|
+
* [-70.603637, -33.399918],
|
|
18
|
+
* [-70.614624, -33.395332],
|
|
19
|
+
* [-70.639343, -33.392466],
|
|
20
|
+
* [-70.659942, -33.394759],
|
|
21
|
+
* [-70.683975, -33.404504],
|
|
22
|
+
* [-70.697021, -33.419406],
|
|
23
|
+
* [-70.701141, -33.434306],
|
|
24
|
+
* [-70.700454, -33.446339],
|
|
25
|
+
* [-70.694274, -33.458369],
|
|
26
|
+
* [-70.682601, -33.465816],
|
|
27
|
+
* [-70.668869, -33.472117],
|
|
28
|
+
* [-70.646209, -33.473835],
|
|
29
|
+
* [-70.624923, -33.472117],
|
|
30
|
+
* [-70.609817, -33.468107],
|
|
31
|
+
* [-70.595397, -33.458369],
|
|
32
|
+
* [-70.587158, -33.442901],
|
|
33
|
+
* [-70.587158, -33.426283],
|
|
34
|
+
* [-70.590591, -33.414248],
|
|
35
|
+
* [-70.594711, -33.406224],
|
|
36
|
+
* [-70.603637, -33.399918]
|
|
37
|
+
* ]]);
|
|
38
|
+
* var options = {tolerance: 0.01, highQuality: false};
|
|
39
|
+
* var simplified = turf.simplify(geojson, options);
|
|
40
|
+
*
|
|
41
|
+
* //addToMap
|
|
42
|
+
* var addToMap = [geojson, simplified]
|
|
43
|
+
*/
|
|
44
|
+
declare function simplify<T extends AllGeoJSON>(geojson: T, options?: {
|
|
45
|
+
tolerance?: number;
|
|
46
|
+
highQuality?: boolean;
|
|
47
|
+
mutate?: boolean;
|
|
48
|
+
}): T;
|
|
49
|
+
|
|
50
|
+
export { simplify as default, simplify };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AllGeoJSON } from '@turf/helpers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Takes a {@link GeoJSON} object and returns a simplified version. Internally uses the 2d version of
|
|
5
|
+
* [simplify-js](http://mourner.github.io/simplify-js/) to perform simplification using the Ramer-Douglas-Peucker algorithm.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @name simplify
|
|
9
|
+
* @param {GeoJSON} geojson object to be simplified
|
|
10
|
+
* @param {Object} [options={}] Optional parameters
|
|
11
|
+
* @param {number} [options.tolerance=1] simplification tolerance
|
|
12
|
+
* @param {boolean} [options.highQuality=false] whether or not to spend more time to create a higher-quality simplification with a different algorithm
|
|
13
|
+
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
|
|
14
|
+
* @returns {GeoJSON} a simplified GeoJSON
|
|
15
|
+
* @example
|
|
16
|
+
* var geojson = turf.polygon([[
|
|
17
|
+
* [-70.603637, -33.399918],
|
|
18
|
+
* [-70.614624, -33.395332],
|
|
19
|
+
* [-70.639343, -33.392466],
|
|
20
|
+
* [-70.659942, -33.394759],
|
|
21
|
+
* [-70.683975, -33.404504],
|
|
22
|
+
* [-70.697021, -33.419406],
|
|
23
|
+
* [-70.701141, -33.434306],
|
|
24
|
+
* [-70.700454, -33.446339],
|
|
25
|
+
* [-70.694274, -33.458369],
|
|
26
|
+
* [-70.682601, -33.465816],
|
|
27
|
+
* [-70.668869, -33.472117],
|
|
28
|
+
* [-70.646209, -33.473835],
|
|
29
|
+
* [-70.624923, -33.472117],
|
|
30
|
+
* [-70.609817, -33.468107],
|
|
31
|
+
* [-70.595397, -33.458369],
|
|
32
|
+
* [-70.587158, -33.442901],
|
|
33
|
+
* [-70.587158, -33.426283],
|
|
34
|
+
* [-70.590591, -33.414248],
|
|
35
|
+
* [-70.594711, -33.406224],
|
|
36
|
+
* [-70.603637, -33.399918]
|
|
37
|
+
* ]]);
|
|
38
|
+
* var options = {tolerance: 0.01, highQuality: false};
|
|
39
|
+
* var simplified = turf.simplify(geojson, options);
|
|
40
|
+
*
|
|
41
|
+
* //addToMap
|
|
42
|
+
* var addToMap = [geojson, simplified]
|
|
43
|
+
*/
|
|
44
|
+
declare function simplify<T extends AllGeoJSON>(geojson: T, options?: {
|
|
45
|
+
tolerance?: number;
|
|
46
|
+
highQuality?: boolean;
|
|
47
|
+
mutate?: boolean;
|
|
48
|
+
}): T;
|
|
49
|
+
|
|
50
|
+
export { simplify as default, simplify };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import { cleanCoords } from "@turf/clean-coords";
|
|
3
|
+
import { clone } from "@turf/clone";
|
|
4
|
+
import { geomEach } from "@turf/meta";
|
|
5
|
+
import { isObject } from "@turf/helpers";
|
|
6
|
+
|
|
7
|
+
// lib/simplify.js
|
|
8
|
+
function getSqDist(p1, p2) {
|
|
9
|
+
var dx = p1[0] - p2[0], dy = p1[1] - p2[1];
|
|
10
|
+
return dx * dx + dy * dy;
|
|
11
|
+
}
|
|
12
|
+
function getSqSegDist(p, p1, p2) {
|
|
13
|
+
var x = p1[0], y = p1[1], dx = p2[0] - x, dy = p2[1] - y;
|
|
14
|
+
if (dx !== 0 || dy !== 0) {
|
|
15
|
+
var t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy);
|
|
16
|
+
if (t > 1) {
|
|
17
|
+
x = p2[0];
|
|
18
|
+
y = p2[1];
|
|
19
|
+
} else if (t > 0) {
|
|
20
|
+
x += dx * t;
|
|
21
|
+
y += dy * t;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
dx = p[0] - x;
|
|
25
|
+
dy = p[1] - y;
|
|
26
|
+
return dx * dx + dy * dy;
|
|
27
|
+
}
|
|
28
|
+
function simplifyRadialDist(points, sqTolerance) {
|
|
29
|
+
var prevPoint = points[0], newPoints = [prevPoint], point;
|
|
30
|
+
for (var i = 1, len = points.length; i < len; i++) {
|
|
31
|
+
point = points[i];
|
|
32
|
+
if (getSqDist(point, prevPoint) > sqTolerance) {
|
|
33
|
+
newPoints.push(point);
|
|
34
|
+
prevPoint = point;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (prevPoint !== point)
|
|
38
|
+
newPoints.push(point);
|
|
39
|
+
return newPoints;
|
|
40
|
+
}
|
|
41
|
+
function simplifyDPStep(points, first, last, sqTolerance, simplified) {
|
|
42
|
+
var maxSqDist = sqTolerance, index;
|
|
43
|
+
for (var i = first + 1; i < last; i++) {
|
|
44
|
+
var sqDist = getSqSegDist(points[i], points[first], points[last]);
|
|
45
|
+
if (sqDist > maxSqDist) {
|
|
46
|
+
index = i;
|
|
47
|
+
maxSqDist = sqDist;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (maxSqDist > sqTolerance) {
|
|
51
|
+
if (index - first > 1)
|
|
52
|
+
simplifyDPStep(points, first, index, sqTolerance, simplified);
|
|
53
|
+
simplified.push(points[index]);
|
|
54
|
+
if (last - index > 1)
|
|
55
|
+
simplifyDPStep(points, index, last, sqTolerance, simplified);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function simplifyDouglasPeucker(points, sqTolerance) {
|
|
59
|
+
var last = points.length - 1;
|
|
60
|
+
var simplified = [points[0]];
|
|
61
|
+
simplifyDPStep(points, 0, last, sqTolerance, simplified);
|
|
62
|
+
simplified.push(points[last]);
|
|
63
|
+
return simplified;
|
|
64
|
+
}
|
|
65
|
+
function simplify(points, tolerance, highestQuality) {
|
|
66
|
+
if (points.length <= 2)
|
|
67
|
+
return points;
|
|
68
|
+
var sqTolerance = tolerance !== void 0 ? tolerance * tolerance : 1;
|
|
69
|
+
points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);
|
|
70
|
+
points = simplifyDouglasPeucker(points, sqTolerance);
|
|
71
|
+
return points;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// index.ts
|
|
75
|
+
function simplify2(geojson, options = {}) {
|
|
76
|
+
var _a, _b, _c;
|
|
77
|
+
options = options != null ? options : {};
|
|
78
|
+
if (!isObject(options))
|
|
79
|
+
throw new Error("options is invalid");
|
|
80
|
+
const tolerance = (_a = options.tolerance) != null ? _a : 1;
|
|
81
|
+
const highQuality = (_b = options.highQuality) != null ? _b : false;
|
|
82
|
+
const mutate = (_c = options.mutate) != null ? _c : false;
|
|
83
|
+
if (!geojson)
|
|
84
|
+
throw new Error("geojson is required");
|
|
85
|
+
if (tolerance && tolerance < 0)
|
|
86
|
+
throw new Error("invalid tolerance");
|
|
87
|
+
if (mutate !== true)
|
|
88
|
+
geojson = clone(geojson);
|
|
89
|
+
geomEach(geojson, function(geom) {
|
|
90
|
+
simplifyGeom(geom, tolerance, highQuality);
|
|
91
|
+
});
|
|
92
|
+
return geojson;
|
|
93
|
+
}
|
|
94
|
+
function simplifyGeom(geometry, tolerance, highQuality) {
|
|
95
|
+
const type = geometry.type;
|
|
96
|
+
if (type === "Point" || type === "MultiPoint")
|
|
97
|
+
return geometry;
|
|
98
|
+
cleanCoords(geometry, { mutate: true });
|
|
99
|
+
if (type !== "GeometryCollection") {
|
|
100
|
+
switch (type) {
|
|
101
|
+
case "LineString":
|
|
102
|
+
geometry.coordinates = simplify(
|
|
103
|
+
geometry.coordinates,
|
|
104
|
+
tolerance,
|
|
105
|
+
highQuality
|
|
106
|
+
);
|
|
107
|
+
break;
|
|
108
|
+
case "MultiLineString":
|
|
109
|
+
geometry.coordinates = geometry.coordinates.map(
|
|
110
|
+
(lines) => simplify(lines, tolerance, highQuality)
|
|
111
|
+
);
|
|
112
|
+
break;
|
|
113
|
+
case "Polygon":
|
|
114
|
+
geometry.coordinates = simplifyPolygon(
|
|
115
|
+
geometry.coordinates,
|
|
116
|
+
tolerance,
|
|
117
|
+
highQuality
|
|
118
|
+
);
|
|
119
|
+
break;
|
|
120
|
+
case "MultiPolygon":
|
|
121
|
+
geometry.coordinates = geometry.coordinates.map(
|
|
122
|
+
(rings) => simplifyPolygon(rings, tolerance, highQuality)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return geometry;
|
|
127
|
+
}
|
|
128
|
+
function simplifyPolygon(coordinates, tolerance, highQuality) {
|
|
129
|
+
return coordinates.map(function(ring) {
|
|
130
|
+
if (ring.length < 4) {
|
|
131
|
+
throw new Error("invalid polygon");
|
|
132
|
+
}
|
|
133
|
+
let ringTolerance = tolerance;
|
|
134
|
+
let simpleRing = simplify(ring, ringTolerance, highQuality);
|
|
135
|
+
while (!checkValidity(simpleRing)) {
|
|
136
|
+
ringTolerance -= ringTolerance * 0.01;
|
|
137
|
+
simpleRing = simplify(ring, ringTolerance, highQuality);
|
|
138
|
+
}
|
|
139
|
+
if (simpleRing[simpleRing.length - 1][0] !== simpleRing[0][0] || simpleRing[simpleRing.length - 1][1] !== simpleRing[0][1]) {
|
|
140
|
+
simpleRing.push(simpleRing[0]);
|
|
141
|
+
}
|
|
142
|
+
return simpleRing;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function checkValidity(ring) {
|
|
146
|
+
if (ring.length < 3)
|
|
147
|
+
return false;
|
|
148
|
+
return !(ring.length === 3 && ring[2][0] === ring[0][0] && ring[2][1] === ring[0][1]);
|
|
149
|
+
}
|
|
150
|
+
var turf_simplify_default = simplify2;
|
|
151
|
+
export {
|
|
152
|
+
turf_simplify_default as default,
|
|
153
|
+
simplify2 as simplify
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts","../../lib/simplify.js"],"sourcesContent":["import { Geometry, Position } from \"geojson\";\nimport { cleanCoords } from \"@turf/clean-coords\";\nimport { clone } from \"@turf/clone\";\nimport { geomEach } from \"@turf/meta\";\nimport { AllGeoJSON, isObject } from \"@turf/helpers\";\nimport { simplify as simplifyJS } from \"./lib/simplify.js\";\n\n/**\n * Takes a {@link GeoJSON} object and returns a simplified version. Internally uses the 2d version of\n * [simplify-js](http://mourner.github.io/simplify-js/) to perform simplification using the Ramer-Douglas-Peucker algorithm.\n *\n *\n * @name simplify\n * @param {GeoJSON} geojson object to be simplified\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.tolerance=1] simplification tolerance\n * @param {boolean} [options.highQuality=false] whether or not to spend more time to create a higher-quality simplification with a different algorithm\n * @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)\n * @returns {GeoJSON} a simplified GeoJSON\n * @example\n * var geojson = turf.polygon([[\n * [-70.603637, -33.399918],\n * [-70.614624, -33.395332],\n * [-70.639343, -33.392466],\n * [-70.659942, -33.394759],\n * [-70.683975, -33.404504],\n * [-70.697021, -33.419406],\n * [-70.701141, -33.434306],\n * [-70.700454, -33.446339],\n * [-70.694274, -33.458369],\n * [-70.682601, -33.465816],\n * [-70.668869, -33.472117],\n * [-70.646209, -33.473835],\n * [-70.624923, -33.472117],\n * [-70.609817, -33.468107],\n * [-70.595397, -33.458369],\n * [-70.587158, -33.442901],\n * [-70.587158, -33.426283],\n * [-70.590591, -33.414248],\n * [-70.594711, -33.406224],\n * [-70.603637, -33.399918]\n * ]]);\n * var options = {tolerance: 0.01, highQuality: false};\n * var simplified = turf.simplify(geojson, options);\n *\n * //addToMap\n * var addToMap = [geojson, simplified]\n */\nfunction simplify<T extends AllGeoJSON>(\n geojson: T,\n options: {\n tolerance?: number;\n highQuality?: boolean;\n mutate?: boolean;\n } = {}\n): T {\n // Optional parameters\n options = options ?? {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const tolerance = options.tolerance ?? 1;\n const highQuality = options.highQuality ?? false;\n const mutate = options.mutate ?? false;\n\n if (!geojson) throw new Error(\"geojson is required\");\n if (tolerance && tolerance < 0) throw new Error(\"invalid tolerance\");\n\n // Clone geojson to avoid side effects\n if (mutate !== true) geojson = clone(geojson);\n\n geomEach(geojson, function (geom) {\n simplifyGeom(geom, tolerance, highQuality);\n });\n return geojson;\n}\n\n/**\n * Simplifies a feature's coordinates\n *\n * @private\n * @param {Geometry} geometry to be simplified\n * @param {number} [tolerance=1] simplification tolerance\n * @param {boolean} [highQuality=false] whether or not to spend more time to create a higher-quality simplification with a different algorithm\n * @returns {Geometry} output\n */\nfunction simplifyGeom(\n geometry: Geometry,\n tolerance: number,\n highQuality: boolean\n) {\n const type = geometry.type;\n\n // \"unsimplyfiable\" geometry types\n if (type === \"Point\" || type === \"MultiPoint\") return geometry;\n\n // Remove any extra coordinates\n cleanCoords(geometry, { mutate: true });\n\n if (type !== \"GeometryCollection\") {\n // TODO should this cater for GeometryCollections too?\n switch (type) {\n case \"LineString\":\n geometry.coordinates = simplifyJS(\n geometry.coordinates,\n tolerance,\n highQuality\n );\n break;\n case \"MultiLineString\":\n geometry.coordinates = geometry.coordinates.map((lines) =>\n simplifyJS(lines, tolerance, highQuality)\n );\n break;\n case \"Polygon\":\n geometry.coordinates = simplifyPolygon(\n geometry.coordinates,\n tolerance,\n highQuality\n );\n break;\n case \"MultiPolygon\":\n geometry.coordinates = geometry.coordinates.map((rings) =>\n simplifyPolygon(rings, tolerance, highQuality)\n );\n }\n }\n\n return geometry;\n}\n\n/**\n * Simplifies the coordinates of a Polygon with simplify-js\n *\n * @private\n * @param {Array<number>} coordinates to be processed\n * @param {number} tolerance simplification tolerance\n * @param {boolean} highQuality whether or not to spend more time to create a higher-quality\n * @returns {Array<Array<Array<number>>>} simplified coords\n */\nfunction simplifyPolygon(\n coordinates: Position[][],\n tolerance: number,\n highQuality: boolean\n) {\n return coordinates.map(function (ring) {\n if (ring.length < 4) {\n throw new Error(\"invalid polygon\");\n }\n let ringTolerance = tolerance;\n let simpleRing = simplifyJS(ring, ringTolerance, highQuality);\n // remove 1 percent of tolerance until enough points to make a triangle\n while (!checkValidity(simpleRing)) {\n ringTolerance -= ringTolerance * 0.01;\n simpleRing = simplifyJS(ring, ringTolerance, highQuality);\n }\n if (\n simpleRing[simpleRing.length - 1][0] !== simpleRing[0][0] ||\n simpleRing[simpleRing.length - 1][1] !== simpleRing[0][1]\n ) {\n simpleRing.push(simpleRing[0]);\n }\n return simpleRing;\n });\n}\n\n/**\n * Returns true if ring has at least 3 coordinates and its first coordinate is the same as its last\n *\n * @private\n * @param {Array<number>} ring coordinates to be checked\n * @returns {boolean} true if valid\n */\nfunction checkValidity(ring: Position[]) {\n if (ring.length < 3) return false;\n //if the last point is the same as the first, it's not a triangle\n return !(\n ring.length === 3 &&\n ring[2][0] === ring[0][0] &&\n ring[2][1] === ring[0][1]\n );\n}\n\nexport { simplify };\nexport default simplify;\n","/*\n (c) 2013, Vladimir Agafonkin\n Simplify.js, a high-performance JS polyline simplification library\n mourner.github.io/simplify-js\n*/\n\n// to suit your point format, run search/replace for '.x' and '.y';\n// for 3D version, see 3d branch (configurability would draw significant performance overhead)\n\n// square distance between 2 points\nfunction getSqDist(p1, p2) {\n var dx = p1[0] - p2[0],\n dy = p1[1] - p2[1];\n\n return dx * dx + dy * dy;\n}\n\n// square distance from a point to a segment\nfunction getSqSegDist(p, p1, p2) {\n var x = p1[0],\n y = p1[1],\n dx = p2[0] - x,\n dy = p2[1] - y;\n\n if (dx !== 0 || dy !== 0) {\n var t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy);\n\n if (t > 1) {\n x = p2[0];\n y = p2[1];\n } else if (t > 0) {\n x += dx * t;\n y += dy * t;\n }\n }\n\n dx = p[0] - x;\n dy = p[1] - y;\n\n return dx * dx + dy * dy;\n}\n// rest of the code doesn't care about point format\n\n// basic distance-based simplification\nfunction simplifyRadialDist(points, sqTolerance) {\n var prevPoint = points[0],\n newPoints = [prevPoint],\n point;\n\n for (var i = 1, len = points.length; i < len; i++) {\n point = points[i];\n\n if (getSqDist(point, prevPoint) > sqTolerance) {\n newPoints.push(point);\n prevPoint = point;\n }\n }\n\n if (prevPoint !== point) newPoints.push(point);\n\n return newPoints;\n}\n\nfunction simplifyDPStep(points, first, last, sqTolerance, simplified) {\n var maxSqDist = sqTolerance,\n index;\n\n for (var i = first + 1; i < last; i++) {\n var sqDist = getSqSegDist(points[i], points[first], points[last]);\n\n if (sqDist > maxSqDist) {\n index = i;\n maxSqDist = sqDist;\n }\n }\n\n if (maxSqDist > sqTolerance) {\n if (index - first > 1)\n simplifyDPStep(points, first, index, sqTolerance, simplified);\n simplified.push(points[index]);\n if (last - index > 1)\n simplifyDPStep(points, index, last, sqTolerance, simplified);\n }\n}\n\n// simplification using Ramer-Douglas-Peucker algorithm\nfunction simplifyDouglasPeucker(points, sqTolerance) {\n var last = points.length - 1;\n\n var simplified = [points[0]];\n simplifyDPStep(points, 0, last, sqTolerance, simplified);\n simplified.push(points[last]);\n\n return simplified;\n}\n\n// both algorithms combined for awesome performance\nfunction simplify(points, tolerance, highestQuality) {\n if (points.length <= 2) return points;\n\n var sqTolerance = tolerance !== undefined ? tolerance * tolerance : 1;\n\n points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);\n points = simplifyDouglasPeucker(points, sqTolerance);\n\n return points;\n}\n\nexport { simplify };\nexport default simplify;\n"],"mappings":";AACA,SAAS,mBAAmB;AAC5B,SAAS,aAAa;AACtB,SAAS,gBAAgB;AACzB,SAAqB,gBAAgB;;;ACMrC,SAAS,UAAU,IAAI,IAAI;AACzB,MAAI,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC,GACnB,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC;AAEnB,SAAO,KAAK,KAAK,KAAK;AACxB;AAGA,SAAS,aAAa,GAAG,IAAI,IAAI;AAC/B,MAAI,IAAI,GAAG,CAAC,GACV,IAAI,GAAG,CAAC,GACR,KAAK,GAAG,CAAC,IAAI,GACb,KAAK,GAAG,CAAC,IAA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
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0-alpha.7+0ce6ecca0",
|
|
4
4
|
"description": "turf simplify module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -28,45 +28,54 @@
|
|
|
28
28
|
"algorithm",
|
|
29
29
|
"peucker"
|
|
30
30
|
],
|
|
31
|
-
"
|
|
32
|
-
"
|
|
31
|
+
"type": "module",
|
|
32
|
+
"main": "dist/cjs/index.cjs",
|
|
33
|
+
"module": "dist/esm/index.js",
|
|
34
|
+
"types": "dist/esm/index.d.ts",
|
|
33
35
|
"exports": {
|
|
34
36
|
"./package.json": "./package.json",
|
|
35
37
|
".": {
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/esm/index.d.ts",
|
|
40
|
+
"default": "./dist/esm/index.js"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./dist/cjs/index.d.cts",
|
|
44
|
+
"default": "./dist/cjs/index.cjs"
|
|
45
|
+
}
|
|
39
46
|
}
|
|
40
47
|
},
|
|
41
|
-
"types": "index.d.ts",
|
|
42
48
|
"sideEffects": false,
|
|
43
49
|
"files": [
|
|
44
|
-
"dist"
|
|
45
|
-
"index.d.ts"
|
|
50
|
+
"dist"
|
|
46
51
|
],
|
|
47
52
|
"scripts": {
|
|
48
|
-
"bench": "tsx bench.
|
|
49
|
-
"build": "
|
|
50
|
-
"docs": "tsx ../../scripts/generate-readmes",
|
|
51
|
-
"test": "npm-run-all test:*",
|
|
52
|
-
"test:tape": "tsx test.
|
|
53
|
-
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
53
|
+
"bench": "tsx bench.ts",
|
|
54
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
55
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
56
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
57
|
+
"test:tape": "tsx test.ts",
|
|
58
|
+
"test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
|
|
54
59
|
},
|
|
55
60
|
"devDependencies": {
|
|
56
|
-
"@turf/truncate": "^7.
|
|
57
|
-
"benchmark": "
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
61
|
+
"@turf/truncate": "^7.1.0-alpha.7+0ce6ecca0",
|
|
62
|
+
"@types/benchmark": "^2.1.5",
|
|
63
|
+
"@types/tape": "^4.2.32",
|
|
64
|
+
"benchmark": "^2.1.4",
|
|
65
|
+
"load-json-file": "^7.0.1",
|
|
66
|
+
"npm-run-all": "^4.1.5",
|
|
67
|
+
"tape": "^5.7.2",
|
|
68
|
+
"tsup": "^8.0.1",
|
|
69
|
+
"tsx": "^4.6.2",
|
|
70
|
+
"typescript": "^5.2.2",
|
|
71
|
+
"write-json-file": "^5.0.0"
|
|
64
72
|
},
|
|
65
73
|
"dependencies": {
|
|
66
|
-
"@turf/clean-coords": "^7.
|
|
67
|
-
"@turf/clone": "^7.
|
|
68
|
-
"@turf/helpers": "^7.
|
|
69
|
-
"@turf/meta": "^7.
|
|
74
|
+
"@turf/clean-coords": "^7.1.0-alpha.7+0ce6ecca0",
|
|
75
|
+
"@turf/clone": "^7.1.0-alpha.7+0ce6ecca0",
|
|
76
|
+
"@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0",
|
|
77
|
+
"@turf/meta": "^7.1.0-alpha.7+0ce6ecca0",
|
|
78
|
+
"tslib": "^2.6.2"
|
|
70
79
|
},
|
|
71
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea"
|
|
72
81
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import cleanCoords from '@turf/clean-coords';
|
|
2
|
-
import clone from '@turf/clone';
|
|
3
|
-
import { geomEach } from '@turf/meta';
|
|
4
|
-
import { isObject } from '@turf/helpers';
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
(c) 2013, Vladimir Agafonkin
|
|
8
|
-
Simplify.js, a high-performance JS polyline simplification library
|
|
9
|
-
mourner.github.io/simplify-js
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
// to suit your point format, run search/replace for '.x' and '.y';
|
|
13
|
-
// for 3D version, see 3d branch (configurability would draw significant performance overhead)
|
|
14
|
-
|
|
15
|
-
// square distance between 2 points
|
|
16
|
-
function getSqDist(p1, p2) {
|
|
17
|
-
var dx = p1.x - p2.x,
|
|
18
|
-
dy = p1.y - p2.y;
|
|
19
|
-
|
|
20
|
-
return dx * dx + dy * dy;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// square distance from a point to a segment
|
|
24
|
-
function getSqSegDist(p, p1, p2) {
|
|
25
|
-
var x = p1.x,
|
|
26
|
-
y = p1.y,
|
|
27
|
-
dx = p2.x - x,
|
|
28
|
-
dy = p2.y - y;
|
|
29
|
-
|
|
30
|
-
if (dx !== 0 || dy !== 0) {
|
|
31
|
-
var t = ((p.x - x) * dx + (p.y - y) * dy) / (dx * dx + dy * dy);
|
|
32
|
-
|
|
33
|
-
if (t > 1) {
|
|
34
|
-
x = p2.x;
|
|
35
|
-
y = p2.y;
|
|
36
|
-
} else if (t > 0) {
|
|
37
|
-
x += dx * t;
|
|
38
|
-
y += dy * t;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
dx = p.x - x;
|
|
43
|
-
dy = p.y - y;
|
|
44
|
-
|
|
45
|
-
return dx * dx + dy * dy;
|
|
46
|
-
}
|
|
47
|
-
// rest of the code doesn't care about point format
|
|
48
|
-
|
|
49
|
-
// basic distance-based simplification
|
|
50
|
-
function simplifyRadialDist(points, sqTolerance) {
|
|
51
|
-
var prevPoint = points[0],
|
|
52
|
-
newPoints = [prevPoint],
|
|
53
|
-
point;
|
|
54
|
-
|
|
55
|
-
for (var i = 1, len = points.length; i < len; i++) {
|
|
56
|
-
point = points[i];
|
|
57
|
-
|
|
58
|
-
if (getSqDist(point, prevPoint) > sqTolerance) {
|
|
59
|
-
newPoints.push(point);
|
|
60
|
-
prevPoint = point;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (prevPoint !== point) newPoints.push(point);
|
|
65
|
-
|
|
66
|
-
return newPoints;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function simplifyDPStep(points, first, last, sqTolerance, simplified) {
|
|
70
|
-
var maxSqDist = sqTolerance,
|
|
71
|
-
index;
|
|
72
|
-
|
|
73
|
-
for (var i = first + 1; i < last; i++) {
|
|
74
|
-
var sqDist = getSqSegDist(points[i], points[first], points[last]);
|
|
75
|
-
|
|
76
|
-
if (sqDist > maxSqDist) {
|
|
77
|
-
index = i;
|
|
78
|
-
maxSqDist = sqDist;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (maxSqDist > sqTolerance) {
|
|
83
|
-
if (index - first > 1)
|
|
84
|
-
simplifyDPStep(points, first, index, sqTolerance, simplified);
|
|
85
|
-
simplified.push(points[index]);
|
|
86
|
-
if (last - index > 1)
|
|
87
|
-
simplifyDPStep(points, index, last, sqTolerance, simplified);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// simplification using Ramer-Douglas-Peucker algorithm
|
|
92
|
-
function simplifyDouglasPeucker(points, sqTolerance) {
|
|
93
|
-
var last = points.length - 1;
|
|
94
|
-
|
|
95
|
-
var simplified = [points[0]];
|
|
96
|
-
simplifyDPStep(points, 0, last, sqTolerance, simplified);
|
|
97
|
-
simplified.push(points[last]);
|
|
98
|
-
|
|
99
|
-
return simplified;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// both algorithms combined for awesome performance
|
|
103
|
-
function simplify(points, tolerance, highestQuality) {
|
|
104
|
-
if (points.length <= 2) return points;
|
|
105
|
-
|
|
106
|
-
var sqTolerance = tolerance !== undefined ? tolerance * tolerance : 1;
|
|
107
|
-
|
|
108
|
-
points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);
|
|
109
|
-
points = simplifyDouglasPeucker(points, sqTolerance);
|
|
110
|
-
|
|
111
|
-
return points;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Takes a {@link GeoJSON} object and returns a simplified version. Internally uses
|
|
116
|
-
* [simplify-js](http://mourner.github.io/simplify-js/) to perform simplification using the Ramer-Douglas-Peucker algorithm.
|
|
117
|
-
*
|
|
118
|
-
* @name simplify
|
|
119
|
-
* @param {GeoJSON} geojson object to be simplified
|
|
120
|
-
* @param {Object} [options={}] Optional parameters
|
|
121
|
-
* @param {number} [options.tolerance=1] simplification tolerance
|
|
122
|
-
* @param {boolean} [options.highQuality=false] whether or not to spend more time to create a higher-quality simplification with a different algorithm
|
|
123
|
-
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
|
|
124
|
-
* @returns {GeoJSON} a simplified GeoJSON
|
|
125
|
-
* @example
|
|
126
|
-
* var geojson = turf.polygon([[
|
|
127
|
-
* [-70.603637, -33.399918],
|
|
128
|
-
* [-70.614624, -33.395332],
|
|
129
|
-
* [-70.639343, -33.392466],
|
|
130
|
-
* [-70.659942, -33.394759],
|
|
131
|
-
* [-70.683975, -33.404504],
|
|
132
|
-
* [-70.697021, -33.419406],
|
|
133
|
-
* [-70.701141, -33.434306],
|
|
134
|
-
* [-70.700454, -33.446339],
|
|
135
|
-
* [-70.694274, -33.458369],
|
|
136
|
-
* [-70.682601, -33.465816],
|
|
137
|
-
* [-70.668869, -33.472117],
|
|
138
|
-
* [-70.646209, -33.473835],
|
|
139
|
-
* [-70.624923, -33.472117],
|
|
140
|
-
* [-70.609817, -33.468107],
|
|
141
|
-
* [-70.595397, -33.458369],
|
|
142
|
-
* [-70.587158, -33.442901],
|
|
143
|
-
* [-70.587158, -33.426283],
|
|
144
|
-
* [-70.590591, -33.414248],
|
|
145
|
-
* [-70.594711, -33.406224],
|
|
146
|
-
* [-70.603637, -33.399918]
|
|
147
|
-
* ]]);
|
|
148
|
-
* var options = {tolerance: 0.01, highQuality: false};
|
|
149
|
-
* var simplified = turf.simplify(geojson, options);
|
|
150
|
-
*
|
|
151
|
-
* //addToMap
|
|
152
|
-
* var addToMap = [geojson, simplified]
|
|
153
|
-
*/
|
|
154
|
-
function simplify$1(geojson, options) {
|
|
155
|
-
// Optional parameters
|
|
156
|
-
options = options || {};
|
|
157
|
-
if (!isObject(options)) throw new Error("options is invalid");
|
|
158
|
-
var tolerance = options.tolerance !== undefined ? options.tolerance : 1;
|
|
159
|
-
var highQuality = options.highQuality || false;
|
|
160
|
-
var mutate = options.mutate || false;
|
|
161
|
-
|
|
162
|
-
if (!geojson) throw new Error("geojson is required");
|
|
163
|
-
if (tolerance && tolerance < 0) throw new Error("invalid tolerance");
|
|
164
|
-
|
|
165
|
-
// Clone geojson to avoid side effects
|
|
166
|
-
if (mutate !== true) geojson = clone(geojson);
|
|
167
|
-
|
|
168
|
-
geomEach(geojson, function (geom) {
|
|
169
|
-
simplifyGeom(geom, tolerance, highQuality);
|
|
170
|
-
});
|
|
171
|
-
return geojson;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Simplifies a feature's coordinates
|
|
176
|
-
*
|
|
177
|
-
* @private
|
|
178
|
-
* @param {Geometry} geometry to be simplified
|
|
179
|
-
* @param {number} [tolerance=1] simplification tolerance
|
|
180
|
-
* @param {boolean} [highQuality=false] whether or not to spend more time to create a higher-quality simplification with a different algorithm
|
|
181
|
-
* @returns {Geometry} output
|
|
182
|
-
*/
|
|
183
|
-
function simplifyGeom(geometry, tolerance, highQuality) {
|
|
184
|
-
var type = geometry.type;
|
|
185
|
-
|
|
186
|
-
// "unsimplyfiable" geometry types
|
|
187
|
-
if (type === "Point" || type === "MultiPoint") return geometry;
|
|
188
|
-
|
|
189
|
-
// Remove any extra coordinates
|
|
190
|
-
cleanCoords(geometry, true);
|
|
191
|
-
|
|
192
|
-
var coordinates = geometry.coordinates;
|
|
193
|
-
switch (type) {
|
|
194
|
-
case "LineString":
|
|
195
|
-
geometry["coordinates"] = simplifyLine(
|
|
196
|
-
coordinates,
|
|
197
|
-
tolerance,
|
|
198
|
-
highQuality
|
|
199
|
-
);
|
|
200
|
-
break;
|
|
201
|
-
case "MultiLineString":
|
|
202
|
-
geometry["coordinates"] = coordinates.map(function (lines) {
|
|
203
|
-
return simplifyLine(lines, tolerance, highQuality);
|
|
204
|
-
});
|
|
205
|
-
break;
|
|
206
|
-
case "Polygon":
|
|
207
|
-
geometry["coordinates"] = simplifyPolygon(
|
|
208
|
-
coordinates,
|
|
209
|
-
tolerance,
|
|
210
|
-
highQuality
|
|
211
|
-
);
|
|
212
|
-
break;
|
|
213
|
-
case "MultiPolygon":
|
|
214
|
-
geometry["coordinates"] = coordinates.map(function (rings) {
|
|
215
|
-
return simplifyPolygon(rings, tolerance, highQuality);
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
return geometry;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Simplifies the coordinates of a LineString with simplify-js
|
|
223
|
-
*
|
|
224
|
-
* @private
|
|
225
|
-
* @param {Array<number>} coordinates to be processed
|
|
226
|
-
* @param {number} tolerance simplification tolerance
|
|
227
|
-
* @param {boolean} highQuality whether or not to spend more time to create a higher-quality
|
|
228
|
-
* @returns {Array<Array<number>>} simplified coords
|
|
229
|
-
*/
|
|
230
|
-
function simplifyLine(coordinates, tolerance, highQuality) {
|
|
231
|
-
return simplify(
|
|
232
|
-
coordinates.map(function (coord) {
|
|
233
|
-
return { x: coord[0], y: coord[1], z: coord[2] };
|
|
234
|
-
}),
|
|
235
|
-
tolerance,
|
|
236
|
-
highQuality
|
|
237
|
-
).map(function (coords) {
|
|
238
|
-
return coords.z ? [coords.x, coords.y, coords.z] : [coords.x, coords.y];
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Simplifies the coordinates of a Polygon with simplify-js
|
|
244
|
-
*
|
|
245
|
-
* @private
|
|
246
|
-
* @param {Array<number>} coordinates to be processed
|
|
247
|
-
* @param {number} tolerance simplification tolerance
|
|
248
|
-
* @param {boolean} highQuality whether or not to spend more time to create a higher-quality
|
|
249
|
-
* @returns {Array<Array<Array<number>>>} simplified coords
|
|
250
|
-
*/
|
|
251
|
-
function simplifyPolygon(coordinates, tolerance, highQuality) {
|
|
252
|
-
return coordinates.map(function (ring) {
|
|
253
|
-
var pts = ring.map(function (coord) {
|
|
254
|
-
return { x: coord[0], y: coord[1] };
|
|
255
|
-
});
|
|
256
|
-
if (pts.length < 4) {
|
|
257
|
-
throw new Error("invalid polygon");
|
|
258
|
-
}
|
|
259
|
-
var simpleRing = simplify(pts, tolerance, highQuality).map(function (
|
|
260
|
-
coords
|
|
261
|
-
) {
|
|
262
|
-
return [coords.x, coords.y];
|
|
263
|
-
});
|
|
264
|
-
//remove 1 percent of tolerance until enough points to make a triangle
|
|
265
|
-
while (!checkValidity(simpleRing)) {
|
|
266
|
-
tolerance -= tolerance * 0.01;
|
|
267
|
-
simpleRing = simplify(pts, tolerance, highQuality).map(function (
|
|
268
|
-
coords
|
|
269
|
-
) {
|
|
270
|
-
return [coords.x, coords.y];
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
if (
|
|
274
|
-
simpleRing[simpleRing.length - 1][0] !== simpleRing[0][0] ||
|
|
275
|
-
simpleRing[simpleRing.length - 1][1] !== simpleRing[0][1]
|
|
276
|
-
) {
|
|
277
|
-
simpleRing.push(simpleRing[0]);
|
|
278
|
-
}
|
|
279
|
-
return simpleRing;
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Returns true if ring has at least 3 coordinates and its first coordinate is the same as its last
|
|
285
|
-
*
|
|
286
|
-
* @private
|
|
287
|
-
* @param {Array<number>} ring coordinates to be checked
|
|
288
|
-
* @returns {boolean} true if valid
|
|
289
|
-
*/
|
|
290
|
-
function checkValidity(ring) {
|
|
291
|
-
if (ring.length < 3) return false;
|
|
292
|
-
//if the last point is the same as the first, it's not a triangle
|
|
293
|
-
return !(
|
|
294
|
-
ring.length === 3 &&
|
|
295
|
-
ring[2][0] === ring[0][0] &&
|
|
296
|
-
ring[2][1] === ring[0][1]
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export default simplify$1;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var cleanCoords = require('@turf/clean-coords');
|
|
4
|
-
var clone = require('@turf/clone');
|
|
5
|
-
var meta = require('@turf/meta');
|
|
6
|
-
var helpers = require('@turf/helpers');
|
|
7
|
-
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
var cleanCoords__default = /*#__PURE__*/_interopDefaultLegacy(cleanCoords);
|
|
11
|
-
var clone__default = /*#__PURE__*/_interopDefaultLegacy(clone);
|
|
12
|
-
|
|
13
|
-
/*
|
|
14
|
-
(c) 2013, Vladimir Agafonkin
|
|
15
|
-
Simplify.js, a high-performance JS polyline simplification library
|
|
16
|
-
mourner.github.io/simplify-js
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
// to suit your point format, run search/replace for '.x' and '.y';
|
|
20
|
-
// for 3D version, see 3d branch (configurability would draw significant performance overhead)
|
|
21
|
-
|
|
22
|
-
// square distance between 2 points
|
|
23
|
-
function getSqDist(p1, p2) {
|
|
24
|
-
var dx = p1.x - p2.x,
|
|
25
|
-
dy = p1.y - p2.y;
|
|
26
|
-
|
|
27
|
-
return dx * dx + dy * dy;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// square distance from a point to a segment
|
|
31
|
-
function getSqSegDist(p, p1, p2) {
|
|
32
|
-
var x = p1.x,
|
|
33
|
-
y = p1.y,
|
|
34
|
-
dx = p2.x - x,
|
|
35
|
-
dy = p2.y - y;
|
|
36
|
-
|
|
37
|
-
if (dx !== 0 || dy !== 0) {
|
|
38
|
-
var t = ((p.x - x) * dx + (p.y - y) * dy) / (dx * dx + dy * dy);
|
|
39
|
-
|
|
40
|
-
if (t > 1) {
|
|
41
|
-
x = p2.x;
|
|
42
|
-
y = p2.y;
|
|
43
|
-
} else if (t > 0) {
|
|
44
|
-
x += dx * t;
|
|
45
|
-
y += dy * t;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
dx = p.x - x;
|
|
50
|
-
dy = p.y - y;
|
|
51
|
-
|
|
52
|
-
return dx * dx + dy * dy;
|
|
53
|
-
}
|
|
54
|
-
// rest of the code doesn't care about point format
|
|
55
|
-
|
|
56
|
-
// basic distance-based simplification
|
|
57
|
-
function simplifyRadialDist(points, sqTolerance) {
|
|
58
|
-
var prevPoint = points[0],
|
|
59
|
-
newPoints = [prevPoint],
|
|
60
|
-
point;
|
|
61
|
-
|
|
62
|
-
for (var i = 1, len = points.length; i < len; i++) {
|
|
63
|
-
point = points[i];
|
|
64
|
-
|
|
65
|
-
if (getSqDist(point, prevPoint) > sqTolerance) {
|
|
66
|
-
newPoints.push(point);
|
|
67
|
-
prevPoint = point;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (prevPoint !== point) newPoints.push(point);
|
|
72
|
-
|
|
73
|
-
return newPoints;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function simplifyDPStep(points, first, last, sqTolerance, simplified) {
|
|
77
|
-
var maxSqDist = sqTolerance,
|
|
78
|
-
index;
|
|
79
|
-
|
|
80
|
-
for (var i = first + 1; i < last; i++) {
|
|
81
|
-
var sqDist = getSqSegDist(points[i], points[first], points[last]);
|
|
82
|
-
|
|
83
|
-
if (sqDist > maxSqDist) {
|
|
84
|
-
index = i;
|
|
85
|
-
maxSqDist = sqDist;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (maxSqDist > sqTolerance) {
|
|
90
|
-
if (index - first > 1)
|
|
91
|
-
simplifyDPStep(points, first, index, sqTolerance, simplified);
|
|
92
|
-
simplified.push(points[index]);
|
|
93
|
-
if (last - index > 1)
|
|
94
|
-
simplifyDPStep(points, index, last, sqTolerance, simplified);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// simplification using Ramer-Douglas-Peucker algorithm
|
|
99
|
-
function simplifyDouglasPeucker(points, sqTolerance) {
|
|
100
|
-
var last = points.length - 1;
|
|
101
|
-
|
|
102
|
-
var simplified = [points[0]];
|
|
103
|
-
simplifyDPStep(points, 0, last, sqTolerance, simplified);
|
|
104
|
-
simplified.push(points[last]);
|
|
105
|
-
|
|
106
|
-
return simplified;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// both algorithms combined for awesome performance
|
|
110
|
-
function simplify(points, tolerance, highestQuality) {
|
|
111
|
-
if (points.length <= 2) return points;
|
|
112
|
-
|
|
113
|
-
var sqTolerance = tolerance !== undefined ? tolerance * tolerance : 1;
|
|
114
|
-
|
|
115
|
-
points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);
|
|
116
|
-
points = simplifyDouglasPeucker(points, sqTolerance);
|
|
117
|
-
|
|
118
|
-
return points;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Takes a {@link GeoJSON} object and returns a simplified version. Internally uses
|
|
123
|
-
* [simplify-js](http://mourner.github.io/simplify-js/) to perform simplification using the Ramer-Douglas-Peucker algorithm.
|
|
124
|
-
*
|
|
125
|
-
* @name simplify
|
|
126
|
-
* @param {GeoJSON} geojson object to be simplified
|
|
127
|
-
* @param {Object} [options={}] Optional parameters
|
|
128
|
-
* @param {number} [options.tolerance=1] simplification tolerance
|
|
129
|
-
* @param {boolean} [options.highQuality=false] whether or not to spend more time to create a higher-quality simplification with a different algorithm
|
|
130
|
-
* @param {boolean} [options.mutate=false] allows GeoJSON input to be mutated (significant performance increase if true)
|
|
131
|
-
* @returns {GeoJSON} a simplified GeoJSON
|
|
132
|
-
* @example
|
|
133
|
-
* var geojson = turf.polygon([[
|
|
134
|
-
* [-70.603637, -33.399918],
|
|
135
|
-
* [-70.614624, -33.395332],
|
|
136
|
-
* [-70.639343, -33.392466],
|
|
137
|
-
* [-70.659942, -33.394759],
|
|
138
|
-
* [-70.683975, -33.404504],
|
|
139
|
-
* [-70.697021, -33.419406],
|
|
140
|
-
* [-70.701141, -33.434306],
|
|
141
|
-
* [-70.700454, -33.446339],
|
|
142
|
-
* [-70.694274, -33.458369],
|
|
143
|
-
* [-70.682601, -33.465816],
|
|
144
|
-
* [-70.668869, -33.472117],
|
|
145
|
-
* [-70.646209, -33.473835],
|
|
146
|
-
* [-70.624923, -33.472117],
|
|
147
|
-
* [-70.609817, -33.468107],
|
|
148
|
-
* [-70.595397, -33.458369],
|
|
149
|
-
* [-70.587158, -33.442901],
|
|
150
|
-
* [-70.587158, -33.426283],
|
|
151
|
-
* [-70.590591, -33.414248],
|
|
152
|
-
* [-70.594711, -33.406224],
|
|
153
|
-
* [-70.603637, -33.399918]
|
|
154
|
-
* ]]);
|
|
155
|
-
* var options = {tolerance: 0.01, highQuality: false};
|
|
156
|
-
* var simplified = turf.simplify(geojson, options);
|
|
157
|
-
*
|
|
158
|
-
* //addToMap
|
|
159
|
-
* var addToMap = [geojson, simplified]
|
|
160
|
-
*/
|
|
161
|
-
function simplify$1(geojson, options) {
|
|
162
|
-
// Optional parameters
|
|
163
|
-
options = options || {};
|
|
164
|
-
if (!helpers.isObject(options)) throw new Error("options is invalid");
|
|
165
|
-
var tolerance = options.tolerance !== undefined ? options.tolerance : 1;
|
|
166
|
-
var highQuality = options.highQuality || false;
|
|
167
|
-
var mutate = options.mutate || false;
|
|
168
|
-
|
|
169
|
-
if (!geojson) throw new Error("geojson is required");
|
|
170
|
-
if (tolerance && tolerance < 0) throw new Error("invalid tolerance");
|
|
171
|
-
|
|
172
|
-
// Clone geojson to avoid side effects
|
|
173
|
-
if (mutate !== true) geojson = clone__default['default'](geojson);
|
|
174
|
-
|
|
175
|
-
meta.geomEach(geojson, function (geom) {
|
|
176
|
-
simplifyGeom(geom, tolerance, highQuality);
|
|
177
|
-
});
|
|
178
|
-
return geojson;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Simplifies a feature's coordinates
|
|
183
|
-
*
|
|
184
|
-
* @private
|
|
185
|
-
* @param {Geometry} geometry to be simplified
|
|
186
|
-
* @param {number} [tolerance=1] simplification tolerance
|
|
187
|
-
* @param {boolean} [highQuality=false] whether or not to spend more time to create a higher-quality simplification with a different algorithm
|
|
188
|
-
* @returns {Geometry} output
|
|
189
|
-
*/
|
|
190
|
-
function simplifyGeom(geometry, tolerance, highQuality) {
|
|
191
|
-
var type = geometry.type;
|
|
192
|
-
|
|
193
|
-
// "unsimplyfiable" geometry types
|
|
194
|
-
if (type === "Point" || type === "MultiPoint") return geometry;
|
|
195
|
-
|
|
196
|
-
// Remove any extra coordinates
|
|
197
|
-
cleanCoords__default['default'](geometry, true);
|
|
198
|
-
|
|
199
|
-
var coordinates = geometry.coordinates;
|
|
200
|
-
switch (type) {
|
|
201
|
-
case "LineString":
|
|
202
|
-
geometry["coordinates"] = simplifyLine(
|
|
203
|
-
coordinates,
|
|
204
|
-
tolerance,
|
|
205
|
-
highQuality
|
|
206
|
-
);
|
|
207
|
-
break;
|
|
208
|
-
case "MultiLineString":
|
|
209
|
-
geometry["coordinates"] = coordinates.map(function (lines) {
|
|
210
|
-
return simplifyLine(lines, tolerance, highQuality);
|
|
211
|
-
});
|
|
212
|
-
break;
|
|
213
|
-
case "Polygon":
|
|
214
|
-
geometry["coordinates"] = simplifyPolygon(
|
|
215
|
-
coordinates,
|
|
216
|
-
tolerance,
|
|
217
|
-
highQuality
|
|
218
|
-
);
|
|
219
|
-
break;
|
|
220
|
-
case "MultiPolygon":
|
|
221
|
-
geometry["coordinates"] = coordinates.map(function (rings) {
|
|
222
|
-
return simplifyPolygon(rings, tolerance, highQuality);
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
return geometry;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Simplifies the coordinates of a LineString with simplify-js
|
|
230
|
-
*
|
|
231
|
-
* @private
|
|
232
|
-
* @param {Array<number>} coordinates to be processed
|
|
233
|
-
* @param {number} tolerance simplification tolerance
|
|
234
|
-
* @param {boolean} highQuality whether or not to spend more time to create a higher-quality
|
|
235
|
-
* @returns {Array<Array<number>>} simplified coords
|
|
236
|
-
*/
|
|
237
|
-
function simplifyLine(coordinates, tolerance, highQuality) {
|
|
238
|
-
return simplify(
|
|
239
|
-
coordinates.map(function (coord) {
|
|
240
|
-
return { x: coord[0], y: coord[1], z: coord[2] };
|
|
241
|
-
}),
|
|
242
|
-
tolerance,
|
|
243
|
-
highQuality
|
|
244
|
-
).map(function (coords) {
|
|
245
|
-
return coords.z ? [coords.x, coords.y, coords.z] : [coords.x, coords.y];
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Simplifies the coordinates of a Polygon with simplify-js
|
|
251
|
-
*
|
|
252
|
-
* @private
|
|
253
|
-
* @param {Array<number>} coordinates to be processed
|
|
254
|
-
* @param {number} tolerance simplification tolerance
|
|
255
|
-
* @param {boolean} highQuality whether or not to spend more time to create a higher-quality
|
|
256
|
-
* @returns {Array<Array<Array<number>>>} simplified coords
|
|
257
|
-
*/
|
|
258
|
-
function simplifyPolygon(coordinates, tolerance, highQuality) {
|
|
259
|
-
return coordinates.map(function (ring) {
|
|
260
|
-
var pts = ring.map(function (coord) {
|
|
261
|
-
return { x: coord[0], y: coord[1] };
|
|
262
|
-
});
|
|
263
|
-
if (pts.length < 4) {
|
|
264
|
-
throw new Error("invalid polygon");
|
|
265
|
-
}
|
|
266
|
-
var simpleRing = simplify(pts, tolerance, highQuality).map(function (
|
|
267
|
-
coords
|
|
268
|
-
) {
|
|
269
|
-
return [coords.x, coords.y];
|
|
270
|
-
});
|
|
271
|
-
//remove 1 percent of tolerance until enough points to make a triangle
|
|
272
|
-
while (!checkValidity(simpleRing)) {
|
|
273
|
-
tolerance -= tolerance * 0.01;
|
|
274
|
-
simpleRing = simplify(pts, tolerance, highQuality).map(function (
|
|
275
|
-
coords
|
|
276
|
-
) {
|
|
277
|
-
return [coords.x, coords.y];
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
if (
|
|
281
|
-
simpleRing[simpleRing.length - 1][0] !== simpleRing[0][0] ||
|
|
282
|
-
simpleRing[simpleRing.length - 1][1] !== simpleRing[0][1]
|
|
283
|
-
) {
|
|
284
|
-
simpleRing.push(simpleRing[0]);
|
|
285
|
-
}
|
|
286
|
-
return simpleRing;
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Returns true if ring has at least 3 coordinates and its first coordinate is the same as its last
|
|
292
|
-
*
|
|
293
|
-
* @private
|
|
294
|
-
* @param {Array<number>} ring coordinates to be checked
|
|
295
|
-
* @returns {boolean} true if valid
|
|
296
|
-
*/
|
|
297
|
-
function checkValidity(ring) {
|
|
298
|
-
if (ring.length < 3) return false;
|
|
299
|
-
//if the last point is the same as the first, it's not a triangle
|
|
300
|
-
return !(
|
|
301
|
-
ring.length === 3 &&
|
|
302
|
-
ring[2][0] === ring[0][0] &&
|
|
303
|
-
ring[2][1] === ring[0][1]
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
module.exports = simplify$1;
|
|
308
|
-
module.exports.default = simplify$1;
|
package/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AllGeoJSON } from "@turf/helpers";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* http://turfjs.org/docs/#simplify
|
|
5
|
-
*/
|
|
6
|
-
export default function simplify<T extends AllGeoJSON>(
|
|
7
|
-
geojson: T,
|
|
8
|
-
options?: {
|
|
9
|
-
tolerance?: number;
|
|
10
|
-
highQuality?: boolean;
|
|
11
|
-
mutate?: boolean;
|
|
12
|
-
}
|
|
13
|
-
): T;
|