@turf/clean-coords 6.5.0 → 7.0.0-alpha.1
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 +7 -6
- package/dist/es/index.js +11 -7
- package/dist/js/index.d.ts +0 -0
- package/dist/js/index.js +13 -9
- package/package.json +12 -10
package/README.md
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
|
|
7
7
|
Removes redundant coordinates from any GeoJSON Geometry.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Parameters
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- `options.mutate` **[boolean][4]** allows GeoJSON input to be mutated (optional, default `false`)
|
|
11
|
+
* `geojson` **([Geometry][1] | [Feature][2])** Feature or Geometry
|
|
12
|
+
* `options` **[Object][3]** Optional parameters (optional, default `{}`)
|
|
14
13
|
|
|
15
|
-
**
|
|
14
|
+
* `options.mutate` **[boolean][4]** allows GeoJSON input to be mutated (optional, default `false`)
|
|
15
|
+
|
|
16
|
+
### Examples
|
|
16
17
|
|
|
17
18
|
```javascript
|
|
18
19
|
var line = turf.lineString([[0, 0], [0, 2], [0, 5], [0, 8], [0, 8], [0, 10]]);
|
|
@@ -25,7 +26,7 @@ turf.cleanCoords(multiPoint).geometry.coordinates;
|
|
|
25
26
|
//= [[0, 0], [2, 2]]
|
|
26
27
|
```
|
|
27
28
|
|
|
28
|
-
Returns **([Geometry][1]
|
|
29
|
+
Returns **([Geometry][1] | [Feature][2])** the cleaned input Feature/Geometry
|
|
29
30
|
|
|
30
31
|
[1]: https://tools.ietf.org/html/rfc7946#section-3.1
|
|
31
32
|
|
package/dist/es/index.js
CHANGED
|
@@ -19,8 +19,7 @@ import { getCoords, getType } from "@turf/invariant";
|
|
|
19
19
|
* turf.cleanCoords(multiPoint).geometry.coordinates;
|
|
20
20
|
* //= [[0, 0], [2, 2]]
|
|
21
21
|
*/
|
|
22
|
-
function cleanCoords(geojson, options) {
|
|
23
|
-
if (options === void 0) { options = {}; }
|
|
22
|
+
function cleanCoords(geojson, options = {}) {
|
|
24
23
|
// Backwards compatible with v4.0
|
|
25
24
|
var mutate = typeof options === "object" ? options.mutate : options;
|
|
26
25
|
if (!geojson)
|
|
@@ -30,19 +29,19 @@ function cleanCoords(geojson, options) {
|
|
|
30
29
|
var newCoords = [];
|
|
31
30
|
switch (type) {
|
|
32
31
|
case "LineString":
|
|
33
|
-
newCoords = cleanLine(geojson);
|
|
32
|
+
newCoords = cleanLine(geojson, type);
|
|
34
33
|
break;
|
|
35
34
|
case "MultiLineString":
|
|
36
35
|
case "Polygon":
|
|
37
36
|
getCoords(geojson).forEach(function (line) {
|
|
38
|
-
newCoords.push(cleanLine(line));
|
|
37
|
+
newCoords.push(cleanLine(line, type));
|
|
39
38
|
});
|
|
40
39
|
break;
|
|
41
40
|
case "MultiPolygon":
|
|
42
41
|
getCoords(geojson).forEach(function (polygons) {
|
|
43
42
|
var polyPoints = [];
|
|
44
43
|
polygons.forEach(function (ring) {
|
|
45
|
-
polyPoints.push(cleanLine(ring));
|
|
44
|
+
polyPoints.push(cleanLine(ring, type));
|
|
46
45
|
});
|
|
47
46
|
newCoords.push(polyPoints);
|
|
48
47
|
});
|
|
@@ -86,9 +85,10 @@ function cleanCoords(geojson, options) {
|
|
|
86
85
|
*
|
|
87
86
|
* @private
|
|
88
87
|
* @param {Array<number>|LineString} line Line
|
|
88
|
+
* @param {string} type Type of geometry
|
|
89
89
|
* @returns {Array<number>} Cleaned coordinates
|
|
90
90
|
*/
|
|
91
|
-
function cleanLine(line) {
|
|
91
|
+
function cleanLine(line, type) {
|
|
92
92
|
var points = getCoords(line);
|
|
93
93
|
// handle "clean" segment
|
|
94
94
|
if (points.length === 2 && !equals(points[0], points[1]))
|
|
@@ -113,8 +113,12 @@ function cleanLine(line) {
|
|
|
113
113
|
}
|
|
114
114
|
newPoints.push(points[points.length - 1]);
|
|
115
115
|
newPointsLength = newPoints.length;
|
|
116
|
-
|
|
116
|
+
// (Multi)Polygons must have at least 4 points, but a closed LineString with only 3 points is acceptable
|
|
117
|
+
if ((type === "Polygon" || type === "MultiPolygon") &&
|
|
118
|
+
equals(points[0], points[points.length - 1]) &&
|
|
119
|
+
newPointsLength < 4) {
|
|
117
120
|
throw new Error("invalid polygon");
|
|
121
|
+
}
|
|
118
122
|
if (isPointOnLineSegment(newPoints[newPointsLength - 3], newPoints[newPointsLength - 1], newPoints[newPointsLength - 2]))
|
|
119
123
|
newPoints.splice(newPoints.length - 2, 1);
|
|
120
124
|
return newPoints;
|
package/dist/js/index.d.ts
CHANGED
|
File without changes
|
package/dist/js/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const helpers_1 = require("@turf/helpers");
|
|
4
|
+
const invariant_1 = require("@turf/invariant");
|
|
5
5
|
// To-Do => Improve Typescript GeoJSON handling
|
|
6
6
|
/**
|
|
7
7
|
* Removes redundant coordinates from any GeoJSON Geometry.
|
|
@@ -21,8 +21,7 @@ var invariant_1 = require("@turf/invariant");
|
|
|
21
21
|
* turf.cleanCoords(multiPoint).geometry.coordinates;
|
|
22
22
|
* //= [[0, 0], [2, 2]]
|
|
23
23
|
*/
|
|
24
|
-
function cleanCoords(geojson, options) {
|
|
25
|
-
if (options === void 0) { options = {}; }
|
|
24
|
+
function cleanCoords(geojson, options = {}) {
|
|
26
25
|
// Backwards compatible with v4.0
|
|
27
26
|
var mutate = typeof options === "object" ? options.mutate : options;
|
|
28
27
|
if (!geojson)
|
|
@@ -32,19 +31,19 @@ function cleanCoords(geojson, options) {
|
|
|
32
31
|
var newCoords = [];
|
|
33
32
|
switch (type) {
|
|
34
33
|
case "LineString":
|
|
35
|
-
newCoords = cleanLine(geojson);
|
|
34
|
+
newCoords = cleanLine(geojson, type);
|
|
36
35
|
break;
|
|
37
36
|
case "MultiLineString":
|
|
38
37
|
case "Polygon":
|
|
39
38
|
invariant_1.getCoords(geojson).forEach(function (line) {
|
|
40
|
-
newCoords.push(cleanLine(line));
|
|
39
|
+
newCoords.push(cleanLine(line, type));
|
|
41
40
|
});
|
|
42
41
|
break;
|
|
43
42
|
case "MultiPolygon":
|
|
44
43
|
invariant_1.getCoords(geojson).forEach(function (polygons) {
|
|
45
44
|
var polyPoints = [];
|
|
46
45
|
polygons.forEach(function (ring) {
|
|
47
|
-
polyPoints.push(cleanLine(ring));
|
|
46
|
+
polyPoints.push(cleanLine(ring, type));
|
|
48
47
|
});
|
|
49
48
|
newCoords.push(polyPoints);
|
|
50
49
|
});
|
|
@@ -88,9 +87,10 @@ function cleanCoords(geojson, options) {
|
|
|
88
87
|
*
|
|
89
88
|
* @private
|
|
90
89
|
* @param {Array<number>|LineString} line Line
|
|
90
|
+
* @param {string} type Type of geometry
|
|
91
91
|
* @returns {Array<number>} Cleaned coordinates
|
|
92
92
|
*/
|
|
93
|
-
function cleanLine(line) {
|
|
93
|
+
function cleanLine(line, type) {
|
|
94
94
|
var points = invariant_1.getCoords(line);
|
|
95
95
|
// handle "clean" segment
|
|
96
96
|
if (points.length === 2 && !equals(points[0], points[1]))
|
|
@@ -115,8 +115,12 @@ function cleanLine(line) {
|
|
|
115
115
|
}
|
|
116
116
|
newPoints.push(points[points.length - 1]);
|
|
117
117
|
newPointsLength = newPoints.length;
|
|
118
|
-
|
|
118
|
+
// (Multi)Polygons must have at least 4 points, but a closed LineString with only 3 points is acceptable
|
|
119
|
+
if ((type === "Polygon" || type === "MultiPolygon") &&
|
|
120
|
+
equals(points[0], points[points.length - 1]) &&
|
|
121
|
+
newPointsLength < 4) {
|
|
119
122
|
throw new Error("invalid polygon");
|
|
123
|
+
}
|
|
120
124
|
if (isPointOnLineSegment(newPoints[newPointsLength - 3], newPoints[newPointsLength - 1], newPoints[newPointsLength - 2]))
|
|
121
125
|
newPoints.splice(newPoints.length - 2, 1);
|
|
122
126
|
return newPoints;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/clean-coords",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.1",
|
|
4
4
|
"description": "turf clean-coords module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
"./package.json": "./package.json",
|
|
31
31
|
".": {
|
|
32
|
+
"types": "./dist/js/index.d.ts",
|
|
32
33
|
"import": "./dist/es/index.js",
|
|
33
34
|
"require": "./dist/js/index.js"
|
|
34
35
|
}
|
|
@@ -39,30 +40,31 @@
|
|
|
39
40
|
"dist"
|
|
40
41
|
],
|
|
41
42
|
"scripts": {
|
|
42
|
-
"bench": "
|
|
43
|
+
"bench": "tsx bench.js",
|
|
43
44
|
"build": "npm-run-all build:*",
|
|
44
45
|
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
|
|
45
46
|
"build:js": "tsc",
|
|
46
|
-
"docs": "
|
|
47
|
+
"docs": "tsx ../../scripts/generate-readmes",
|
|
47
48
|
"test": "npm-run-all test:*",
|
|
48
|
-
"test:tape": "
|
|
49
|
-
"test:types": "tsc --esModuleInterop --noEmit types.ts"
|
|
49
|
+
"test:tape": "tsx test.js",
|
|
50
|
+
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@turf/truncate": "^
|
|
53
|
+
"@turf/truncate": "^7.0.0-alpha.1",
|
|
53
54
|
"@types/tape": "*",
|
|
54
55
|
"benchmark": "*",
|
|
55
56
|
"load-json-file": "*",
|
|
56
57
|
"npm-run-all": "*",
|
|
57
58
|
"tape": "*",
|
|
58
|
-
"ts-node": "*",
|
|
59
59
|
"tslint": "*",
|
|
60
|
+
"tsx": "*",
|
|
60
61
|
"typescript": "*",
|
|
61
62
|
"write-json-file": "*"
|
|
62
63
|
},
|
|
63
64
|
"dependencies": {
|
|
64
|
-
"@turf/helpers": "^
|
|
65
|
-
"@turf/invariant": "^
|
|
65
|
+
"@turf/helpers": "^7.0.0-alpha.1",
|
|
66
|
+
"@turf/invariant": "^7.0.0-alpha.1",
|
|
67
|
+
"tslib": "^2.3.0"
|
|
66
68
|
},
|
|
67
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
|
|
68
70
|
}
|