@turf/line-segment 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 +8 -15
- package/dist/es/index.js +19 -19
- package/dist/js/index.d.ts +1 -1
- package/dist/js/index.js +21 -21
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
## lineSegment
|
|
6
6
|
|
|
7
|
-
Creates a [FeatureCollection][1] of 2-vertex [LineString][2] segments from a
|
|
7
|
+
Creates a [FeatureCollection][1] of 2-vertex [LineString][2] segments from a
|
|
8
|
+
[(Multi)LineString][2] or [(Multi)Polygon][3].
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
### Parameters
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
* `geojson` **[GeoJSON][4]** GeoJSON Polygon or LineString
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
### Examples
|
|
14
15
|
|
|
15
16
|
```javascript
|
|
16
17
|
var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
|
|
@@ -20,7 +21,7 @@ var segments = turf.lineSegment(polygon);
|
|
|
20
21
|
var addToMap = [polygon, segments]
|
|
21
22
|
```
|
|
22
23
|
|
|
23
|
-
Returns **[FeatureCollection][5]
|
|
24
|
+
Returns **[FeatureCollection][5]<[LineString][6]>** 2-vertex line segments
|
|
24
25
|
|
|
25
26
|
[1]: https://tools.ietf.org/html/rfc7946#section-3.3
|
|
26
27
|
|
|
@@ -28,19 +29,11 @@ Returns **[FeatureCollection][5]<[LineString][7]>** 2-vertex line segments
|
|
|
28
29
|
|
|
29
30
|
[3]: https://tools.ietf.org/html/rfc7946#section-3.1.6
|
|
30
31
|
|
|
31
|
-
[4]: https://tools.ietf.org/html/rfc7946#section-3
|
|
32
|
+
[4]: https://tools.ietf.org/html/rfc7946#section-3
|
|
32
33
|
|
|
33
34
|
[5]: https://tools.ietf.org/html/rfc7946#section-3.3
|
|
34
35
|
|
|
35
|
-
[6]: https://tools.ietf.org/html/rfc7946#section-3.
|
|
36
|
-
|
|
37
|
-
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.4
|
|
38
|
-
|
|
39
|
-
[8]: https://tools.ietf.org/html/rfc7946#section-3.1.5
|
|
40
|
-
|
|
41
|
-
[9]: https://tools.ietf.org/html/rfc7946#section-3.1.7
|
|
42
|
-
|
|
43
|
-
[10]: https://tools.ietf.org/html/rfc7946#section-3.1.6
|
|
36
|
+
[6]: https://tools.ietf.org/html/rfc7946#section-3.1.4
|
|
44
37
|
|
|
45
38
|
<!-- This file is automatically generated. Please don't edit it directly:
|
|
46
39
|
if you find an error, edit the source file (likely index.js), and re-run
|
package/dist/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { featureCollection, lineString
|
|
1
|
+
import { featureCollection, lineString } from "@turf/helpers";
|
|
2
2
|
import { getCoords } from "@turf/invariant";
|
|
3
3
|
import { flattenEach } from "@turf/meta";
|
|
4
4
|
/**
|
|
@@ -19,8 +19,8 @@ function lineSegment(geojson) {
|
|
|
19
19
|
if (!geojson) {
|
|
20
20
|
throw new Error("geojson is required");
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
flattenEach(geojson,
|
|
22
|
+
const results = [];
|
|
23
|
+
flattenEach(geojson, (feature) => {
|
|
24
24
|
lineSegmentFeature(feature, results);
|
|
25
25
|
});
|
|
26
26
|
return featureCollection(results);
|
|
@@ -34,8 +34,8 @@ function lineSegment(geojson) {
|
|
|
34
34
|
* @returns {void}
|
|
35
35
|
*/
|
|
36
36
|
function lineSegmentFeature(geojson, results) {
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
let coords = [];
|
|
38
|
+
const geometry = geojson.geometry;
|
|
39
39
|
if (geometry !== null) {
|
|
40
40
|
switch (geometry.type) {
|
|
41
41
|
case "Polygon":
|
|
@@ -44,9 +44,9 @@ function lineSegmentFeature(geojson, results) {
|
|
|
44
44
|
case "LineString":
|
|
45
45
|
coords = [getCoords(geometry)];
|
|
46
46
|
}
|
|
47
|
-
coords.forEach(
|
|
48
|
-
|
|
49
|
-
segments.forEach(
|
|
47
|
+
coords.forEach((coord) => {
|
|
48
|
+
const segments = createSegments(coord, geojson.properties);
|
|
49
|
+
segments.forEach((segment) => {
|
|
50
50
|
segment.id = results.length;
|
|
51
51
|
results.push(segment);
|
|
52
52
|
});
|
|
@@ -62,9 +62,9 @@ function lineSegmentFeature(geojson, results) {
|
|
|
62
62
|
* @returns {Array<Feature<LineString>>} line segments
|
|
63
63
|
*/
|
|
64
64
|
function createSegments(coords, properties) {
|
|
65
|
-
|
|
66
|
-
coords.reduce(
|
|
67
|
-
|
|
65
|
+
const segments = [];
|
|
66
|
+
coords.reduce((previousCoords, currentCoords) => {
|
|
67
|
+
const segment = lineString([previousCoords, currentCoords], properties);
|
|
68
68
|
segment.bbox = bbox(previousCoords, currentCoords);
|
|
69
69
|
segments.push(segment);
|
|
70
70
|
return currentCoords;
|
|
@@ -80,14 +80,14 @@ function createSegments(coords, properties) {
|
|
|
80
80
|
* @returns {BBox} [west, south, east, north]
|
|
81
81
|
*/
|
|
82
82
|
function bbox(coords1, coords2) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
const x1 = coords1[0];
|
|
84
|
+
const y1 = coords1[1];
|
|
85
|
+
const x2 = coords2[0];
|
|
86
|
+
const y2 = coords2[1];
|
|
87
|
+
const west = x1 < x2 ? x1 : x2;
|
|
88
|
+
const south = y1 < y2 ? y1 : y2;
|
|
89
|
+
const east = x1 > x2 ? x1 : x2;
|
|
90
|
+
const north = y1 > y2 ? y1 : y2;
|
|
91
91
|
return [west, south, east, north];
|
|
92
92
|
}
|
|
93
93
|
export default lineSegment;
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Feature, FeatureCollection, LineString, MultiLineString, MultiPolygon, Polygon } from "
|
|
1
|
+
import { Feature, FeatureCollection, LineString, MultiLineString, MultiPolygon, Polygon } from "geojson";
|
|
2
2
|
/**
|
|
3
3
|
* Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a
|
|
4
4
|
* {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.
|
package/dist/js/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const helpers_1 = require("@turf/helpers");
|
|
4
|
+
const invariant_1 = require("@turf/invariant");
|
|
5
|
+
const meta_1 = require("@turf/meta");
|
|
6
6
|
/**
|
|
7
7
|
* Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a
|
|
8
8
|
* {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.
|
|
@@ -21,8 +21,8 @@ function lineSegment(geojson) {
|
|
|
21
21
|
if (!geojson) {
|
|
22
22
|
throw new Error("geojson is required");
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
meta_1.flattenEach(geojson,
|
|
24
|
+
const results = [];
|
|
25
|
+
meta_1.flattenEach(geojson, (feature) => {
|
|
26
26
|
lineSegmentFeature(feature, results);
|
|
27
27
|
});
|
|
28
28
|
return helpers_1.featureCollection(results);
|
|
@@ -36,8 +36,8 @@ function lineSegment(geojson) {
|
|
|
36
36
|
* @returns {void}
|
|
37
37
|
*/
|
|
38
38
|
function lineSegmentFeature(geojson, results) {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
let coords = [];
|
|
40
|
+
const geometry = geojson.geometry;
|
|
41
41
|
if (geometry !== null) {
|
|
42
42
|
switch (geometry.type) {
|
|
43
43
|
case "Polygon":
|
|
@@ -46,9 +46,9 @@ function lineSegmentFeature(geojson, results) {
|
|
|
46
46
|
case "LineString":
|
|
47
47
|
coords = [invariant_1.getCoords(geometry)];
|
|
48
48
|
}
|
|
49
|
-
coords.forEach(
|
|
50
|
-
|
|
51
|
-
segments.forEach(
|
|
49
|
+
coords.forEach((coord) => {
|
|
50
|
+
const segments = createSegments(coord, geojson.properties);
|
|
51
|
+
segments.forEach((segment) => {
|
|
52
52
|
segment.id = results.length;
|
|
53
53
|
results.push(segment);
|
|
54
54
|
});
|
|
@@ -64,9 +64,9 @@ function lineSegmentFeature(geojson, results) {
|
|
|
64
64
|
* @returns {Array<Feature<LineString>>} line segments
|
|
65
65
|
*/
|
|
66
66
|
function createSegments(coords, properties) {
|
|
67
|
-
|
|
68
|
-
coords.reduce(
|
|
69
|
-
|
|
67
|
+
const segments = [];
|
|
68
|
+
coords.reduce((previousCoords, currentCoords) => {
|
|
69
|
+
const segment = helpers_1.lineString([previousCoords, currentCoords], properties);
|
|
70
70
|
segment.bbox = bbox(previousCoords, currentCoords);
|
|
71
71
|
segments.push(segment);
|
|
72
72
|
return currentCoords;
|
|
@@ -82,14 +82,14 @@ function createSegments(coords, properties) {
|
|
|
82
82
|
* @returns {BBox} [west, south, east, north]
|
|
83
83
|
*/
|
|
84
84
|
function bbox(coords1, coords2) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
const x1 = coords1[0];
|
|
86
|
+
const y1 = coords1[1];
|
|
87
|
+
const x2 = coords2[0];
|
|
88
|
+
const y2 = coords2[1];
|
|
89
|
+
const west = x1 < x2 ? x1 : x2;
|
|
90
|
+
const south = y1 < y2 ? y1 : y2;
|
|
91
|
+
const east = x1 > x2 ? x1 : x2;
|
|
92
|
+
const north = y1 > y2 ? y1 : y2;
|
|
93
93
|
return [west, south, east, north];
|
|
94
94
|
}
|
|
95
95
|
exports.default = lineSegment;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/line-segment",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.1",
|
|
4
4
|
"description": "turf line-segment module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"exports": {
|
|
27
27
|
"./package.json": "./package.json",
|
|
28
28
|
".": {
|
|
29
|
+
"types": "./dist/js/index.d.ts",
|
|
29
30
|
"import": "./dist/es/index.js",
|
|
30
31
|
"require": "./dist/js/index.js"
|
|
31
32
|
}
|
|
@@ -36,13 +37,13 @@
|
|
|
36
37
|
"dist"
|
|
37
38
|
],
|
|
38
39
|
"scripts": {
|
|
39
|
-
"bench": "
|
|
40
|
+
"bench": "tsx bench.js",
|
|
40
41
|
"build": "npm-run-all build:*",
|
|
41
42
|
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
|
|
42
43
|
"build:js": "tsc",
|
|
43
|
-
"docs": "
|
|
44
|
+
"docs": "tsx ../../scripts/generate-readmes",
|
|
44
45
|
"test": "npm-run-all test:*",
|
|
45
|
-
"test:tape": "
|
|
46
|
+
"test:tape": "tsx test.js"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@types/tape": "*",
|
|
@@ -50,15 +51,16 @@
|
|
|
50
51
|
"load-json-file": "*",
|
|
51
52
|
"npm-run-all": "*",
|
|
52
53
|
"tape": "*",
|
|
53
|
-
"ts-node": "*",
|
|
54
54
|
"tslint": "*",
|
|
55
|
+
"tsx": "*",
|
|
55
56
|
"typescript": "*",
|
|
56
57
|
"write-json-file": "*"
|
|
57
58
|
},
|
|
58
59
|
"dependencies": {
|
|
59
|
-
"@turf/helpers": "^
|
|
60
|
-
"@turf/invariant": "^
|
|
61
|
-
"@turf/meta": "^
|
|
60
|
+
"@turf/helpers": "^7.0.0-alpha.1",
|
|
61
|
+
"@turf/invariant": "^7.0.0-alpha.1",
|
|
62
|
+
"@turf/meta": "^7.0.0-alpha.1",
|
|
63
|
+
"tslib": "^2.3.0"
|
|
62
64
|
},
|
|
63
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
|
|
64
66
|
}
|