@turf/line-segment 7.0.0-alpha.0 → 7.0.0-alpha.110
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 +4 -9
- package/dist/cjs/index.cjs +68 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{js → cjs}/index.d.ts +4 -2
- package/dist/esm/index.d.mts +19 -0
- package/dist/esm/index.mjs +68 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +33 -27
- package/dist/es/index.js +0 -93
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -95
package/README.md
CHANGED
|
@@ -35,26 +35,21 @@ Returns **[FeatureCollection][5]<[LineString][6]>** 2-vertex line segments
|
|
|
35
35
|
|
|
36
36
|
[6]: https://tools.ietf.org/html/rfc7946#section-3.1.4
|
|
37
37
|
|
|
38
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
39
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
40
|
-
./scripts/generate-readmes in the turf project. -->
|
|
38
|
+
<!-- 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. -->
|
|
41
39
|
|
|
42
40
|
---
|
|
43
41
|
|
|
44
|
-
This module is part of the [Turfjs project](
|
|
45
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
46
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
47
|
-
PRs and issues.
|
|
42
|
+
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.
|
|
48
43
|
|
|
49
44
|
### Installation
|
|
50
45
|
|
|
51
|
-
Install this module individually:
|
|
46
|
+
Install this single module individually:
|
|
52
47
|
|
|
53
48
|
```sh
|
|
54
49
|
$ npm install @turf/line-segment
|
|
55
50
|
```
|
|
56
51
|
|
|
57
|
-
Or install the
|
|
52
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
58
53
|
|
|
59
54
|
```sh
|
|
60
55
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
var _helpers = require('@turf/helpers');
|
|
6
|
+
var _invariant = require('@turf/invariant');
|
|
7
|
+
var _meta = require('@turf/meta');
|
|
8
|
+
function lineSegment(geojson) {
|
|
9
|
+
if (!geojson) {
|
|
10
|
+
throw new Error("geojson is required");
|
|
11
|
+
}
|
|
12
|
+
const results = [];
|
|
13
|
+
_meta.flattenEach.call(void 0, geojson, (feature) => {
|
|
14
|
+
lineSegmentFeature(feature, results);
|
|
15
|
+
});
|
|
16
|
+
return _helpers.featureCollection.call(void 0, results);
|
|
17
|
+
}
|
|
18
|
+
__name(lineSegment, "lineSegment");
|
|
19
|
+
function lineSegmentFeature(geojson, results) {
|
|
20
|
+
let coords = [];
|
|
21
|
+
const geometry = geojson.geometry;
|
|
22
|
+
if (geometry !== null) {
|
|
23
|
+
switch (geometry.type) {
|
|
24
|
+
case "Polygon":
|
|
25
|
+
coords = _invariant.getCoords.call(void 0, geometry);
|
|
26
|
+
break;
|
|
27
|
+
case "LineString":
|
|
28
|
+
coords = [_invariant.getCoords.call(void 0, geometry)];
|
|
29
|
+
}
|
|
30
|
+
coords.forEach((coord) => {
|
|
31
|
+
const segments = createSegments(coord, geojson.properties);
|
|
32
|
+
segments.forEach((segment) => {
|
|
33
|
+
segment.id = results.length;
|
|
34
|
+
results.push(segment);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
__name(lineSegmentFeature, "lineSegmentFeature");
|
|
40
|
+
function createSegments(coords, properties) {
|
|
41
|
+
const segments = [];
|
|
42
|
+
coords.reduce((previousCoords, currentCoords) => {
|
|
43
|
+
const segment = _helpers.lineString.call(void 0, [previousCoords, currentCoords], properties);
|
|
44
|
+
segment.bbox = bbox(previousCoords, currentCoords);
|
|
45
|
+
segments.push(segment);
|
|
46
|
+
return currentCoords;
|
|
47
|
+
});
|
|
48
|
+
return segments;
|
|
49
|
+
}
|
|
50
|
+
__name(createSegments, "createSegments");
|
|
51
|
+
function bbox(coords1, coords2) {
|
|
52
|
+
const x1 = coords1[0];
|
|
53
|
+
const y1 = coords1[1];
|
|
54
|
+
const x2 = coords2[0];
|
|
55
|
+
const y2 = coords2[1];
|
|
56
|
+
const west = x1 < x2 ? x1 : x2;
|
|
57
|
+
const south = y1 < y2 ? y1 : y2;
|
|
58
|
+
const east = x1 > x2 ? x1 : x2;
|
|
59
|
+
const north = y1 > y2 ? y1 : y2;
|
|
60
|
+
return [west, south, east, north];
|
|
61
|
+
}
|
|
62
|
+
__name(bbox, "bbox");
|
|
63
|
+
var turf_line_segment_default = lineSegment;
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
exports.default = turf_line_segment_default; exports.lineSegment = lineSegment;
|
|
68
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AASA,SAAS,mBAAmB,kBAAkB;AAC9C,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAgB5B,SAAS,YAGP,SAC+B;AAC/B,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AAEA,QAAM,UAAsC,CAAC;AAC7C,cAAY,SAAS,CAAC,YAA0B;AAC9C,uBAAmB,SAAS,OAAO;AAAA,EACrC,CAAC;AACD,SAAO,kBAAkB,OAAO;AAClC;AAdS;AAwBT,SAAS,mBACP,SACA,SACA;AACA,MAAI,SAAuB,CAAC;AAC5B,QAAM,WAAW,QAAQ;AACzB,MAAI,aAAa,MAAM;AACrB,YAAQ,SAAS,MAAM;AAAA,MACrB,KAAK;AACH,iBAAS,UAAU,QAAQ;AAC3B;AAAA,MACF,KAAK;AACH,iBAAS,CAAC,UAAU,QAAQ,CAAC;AAAA,IACjC;AACA,WAAO,QAAQ,CAAC,UAAU;AACxB,YAAM,WAAW,eAAe,OAAO,QAAQ,UAAU;AACzD,eAAS,QAAQ,CAAC,YAAY;AAC5B,gBAAQ,KAAK,QAAQ;AACrB,gBAAQ,KAAK,OAAO;AAAA,MACtB,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;AAtBS;AAgCT,SAAS,eAAe,QAAoB,YAAiB;AAC3D,QAAM,WAAuC,CAAC;AAC9C,SAAO,OAAO,CAAC,gBAAgB,kBAAkB;AAC/C,UAAM,UAAU,WAAW,CAAC,gBAAgB,aAAa,GAAG,UAAU;AACtE,YAAQ,OAAO,KAAK,gBAAgB,aAAa;AACjD,aAAS,KAAK,OAAO;AACrB,WAAO;AAAA,EACT,CAAC;AACD,SAAO;AACT;AATS;AAmBT,SAAS,KAAK,SAAmB,SAAyB;AACxD,QAAM,KAAK,QAAQ,CAAC;AACpB,QAAM,KAAK,QAAQ,CAAC;AACpB,QAAM,KAAK,QAAQ,CAAC;AACpB,QAAM,KAAK,QAAQ,CAAC;AACpB,QAAM,OAAO,KAAK,KAAK,KAAK;AAC5B,QAAM,QAAQ,KAAK,KAAK,KAAK;AAC7B,QAAM,OAAO,KAAK,KAAK,KAAK;AAC5B,QAAM,QAAQ,KAAK,KAAK,KAAK;AAC7B,SAAO,CAAC,MAAM,OAAO,MAAM,KAAK;AAClC;AAVS;AAaT,IAAO,4BAAQ","sourcesContent":["import {\n BBox,\n Feature,\n FeatureCollection,\n LineString,\n MultiLineString,\n MultiPolygon,\n Polygon,\n} from \"geojson\";\nimport { featureCollection, lineString } from \"@turf/helpers\";\nimport { getCoords } from \"@turf/invariant\";\nimport { flattenEach } from \"@turf/meta\";\n\n/**\n * Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a\n * {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.\n *\n * @name lineSegment\n * @param {GeoJSON} geojson GeoJSON Polygon or LineString\n * @returns {FeatureCollection<LineString>} 2-vertex line segments\n * @example\n * var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);\n * var segments = turf.lineSegment(polygon);\n *\n * //addToMap\n * var addToMap = [polygon, segments]\n */\nfunction lineSegment<\n G extends LineString | MultiLineString | Polygon | MultiPolygon,\n>(\n geojson: Feature<G> | FeatureCollection<G> | G\n): FeatureCollection<LineString> {\n if (!geojson) {\n throw new Error(\"geojson is required\");\n }\n\n const results: Array<Feature<LineString>> = [];\n flattenEach(geojson, (feature: Feature<any>) => {\n lineSegmentFeature(feature, results);\n });\n return featureCollection(results);\n}\n\n/**\n * Line Segment\n *\n * @private\n * @param {Feature<LineString|Polygon>} geojson Line or polygon feature\n * @param {Array} results push to results\n * @returns {void}\n */\nfunction lineSegmentFeature(\n geojson: Feature<LineString | Polygon>,\n results: Array<Feature<LineString>>\n) {\n let coords: number[][][] = [];\n const geometry = geojson.geometry;\n if (geometry !== null) {\n switch (geometry.type) {\n case \"Polygon\":\n coords = getCoords(geometry);\n break;\n case \"LineString\":\n coords = [getCoords(geometry)];\n }\n coords.forEach((coord) => {\n const segments = createSegments(coord, geojson.properties);\n segments.forEach((segment) => {\n segment.id = results.length;\n results.push(segment);\n });\n });\n }\n}\n\n/**\n * Create Segments from LineString coordinates\n *\n * @private\n * @param {Array<Array<number>>} coords LineString coordinates\n * @param {*} properties GeoJSON properties\n * @returns {Array<Feature<LineString>>} line segments\n */\nfunction createSegments(coords: number[][], properties: any) {\n const segments: Array<Feature<LineString>> = [];\n coords.reduce((previousCoords, currentCoords) => {\n const segment = lineString([previousCoords, currentCoords], properties);\n segment.bbox = bbox(previousCoords, currentCoords);\n segments.push(segment);\n return currentCoords;\n });\n return segments;\n}\n\n/**\n * Create BBox between two coordinates (faster than @turf/bbox)\n *\n * @private\n * @param {Array<number>} coords1 Point coordinate\n * @param {Array<number>} coords2 Point coordinate\n * @returns {BBox} [west, south, east, north]\n */\nfunction bbox(coords1: number[], coords2: number[]): BBox {\n const x1 = coords1[0];\n const y1 = coords1[1];\n const x2 = coords2[0];\n const y2 = coords2[1];\n const west = x1 < x2 ? x1 : x2;\n const south = y1 < y2 ? y1 : y2;\n const east = x1 > x2 ? x1 : x2;\n const north = y1 > y2 ? y1 : y2;\n return [west, south, east, north];\n}\n\nexport { lineSegment };\nexport default lineSegment;\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LineString, MultiLineString, Polygon, MultiPolygon, Feature, FeatureCollection } from 'geojson';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a
|
|
4
5
|
* {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.
|
|
@@ -14,4 +15,5 @@ import { Feature, FeatureCollection, LineString, MultiLineString, MultiPolygon,
|
|
|
14
15
|
* var addToMap = [polygon, segments]
|
|
15
16
|
*/
|
|
16
17
|
declare function lineSegment<G extends LineString | MultiLineString | Polygon | MultiPolygon>(geojson: Feature<G> | FeatureCollection<G> | G): FeatureCollection<LineString>;
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
export { lineSegment as default, lineSegment };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LineString, MultiLineString, Polygon, MultiPolygon, Feature, FeatureCollection } from 'geojson';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a
|
|
5
|
+
* {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.
|
|
6
|
+
*
|
|
7
|
+
* @name lineSegment
|
|
8
|
+
* @param {GeoJSON} geojson GeoJSON Polygon or LineString
|
|
9
|
+
* @returns {FeatureCollection<LineString>} 2-vertex line segments
|
|
10
|
+
* @example
|
|
11
|
+
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
|
|
12
|
+
* var segments = turf.lineSegment(polygon);
|
|
13
|
+
*
|
|
14
|
+
* //addToMap
|
|
15
|
+
* var addToMap = [polygon, segments]
|
|
16
|
+
*/
|
|
17
|
+
declare function lineSegment<G extends LineString | MultiLineString | Polygon | MultiPolygon>(geojson: Feature<G> | FeatureCollection<G> | G): FeatureCollection<LineString>;
|
|
18
|
+
|
|
19
|
+
export { lineSegment as default, lineSegment };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import { featureCollection, lineString } from "@turf/helpers";
|
|
6
|
+
import { getCoords } from "@turf/invariant";
|
|
7
|
+
import { flattenEach } from "@turf/meta";
|
|
8
|
+
function lineSegment(geojson) {
|
|
9
|
+
if (!geojson) {
|
|
10
|
+
throw new Error("geojson is required");
|
|
11
|
+
}
|
|
12
|
+
const results = [];
|
|
13
|
+
flattenEach(geojson, (feature) => {
|
|
14
|
+
lineSegmentFeature(feature, results);
|
|
15
|
+
});
|
|
16
|
+
return featureCollection(results);
|
|
17
|
+
}
|
|
18
|
+
__name(lineSegment, "lineSegment");
|
|
19
|
+
function lineSegmentFeature(geojson, results) {
|
|
20
|
+
let coords = [];
|
|
21
|
+
const geometry = geojson.geometry;
|
|
22
|
+
if (geometry !== null) {
|
|
23
|
+
switch (geometry.type) {
|
|
24
|
+
case "Polygon":
|
|
25
|
+
coords = getCoords(geometry);
|
|
26
|
+
break;
|
|
27
|
+
case "LineString":
|
|
28
|
+
coords = [getCoords(geometry)];
|
|
29
|
+
}
|
|
30
|
+
coords.forEach((coord) => {
|
|
31
|
+
const segments = createSegments(coord, geojson.properties);
|
|
32
|
+
segments.forEach((segment) => {
|
|
33
|
+
segment.id = results.length;
|
|
34
|
+
results.push(segment);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
__name(lineSegmentFeature, "lineSegmentFeature");
|
|
40
|
+
function createSegments(coords, properties) {
|
|
41
|
+
const segments = [];
|
|
42
|
+
coords.reduce((previousCoords, currentCoords) => {
|
|
43
|
+
const segment = lineString([previousCoords, currentCoords], properties);
|
|
44
|
+
segment.bbox = bbox(previousCoords, currentCoords);
|
|
45
|
+
segments.push(segment);
|
|
46
|
+
return currentCoords;
|
|
47
|
+
});
|
|
48
|
+
return segments;
|
|
49
|
+
}
|
|
50
|
+
__name(createSegments, "createSegments");
|
|
51
|
+
function bbox(coords1, coords2) {
|
|
52
|
+
const x1 = coords1[0];
|
|
53
|
+
const y1 = coords1[1];
|
|
54
|
+
const x2 = coords2[0];
|
|
55
|
+
const y2 = coords2[1];
|
|
56
|
+
const west = x1 < x2 ? x1 : x2;
|
|
57
|
+
const south = y1 < y2 ? y1 : y2;
|
|
58
|
+
const east = x1 > x2 ? x1 : x2;
|
|
59
|
+
const north = y1 > y2 ? y1 : y2;
|
|
60
|
+
return [west, south, east, north];
|
|
61
|
+
}
|
|
62
|
+
__name(bbox, "bbox");
|
|
63
|
+
var turf_line_segment_default = lineSegment;
|
|
64
|
+
export {
|
|
65
|
+
turf_line_segment_default as default,
|
|
66
|
+
lineSegment
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import {\n BBox,\n Feature,\n FeatureCollection,\n LineString,\n MultiLineString,\n MultiPolygon,\n Polygon,\n} from \"geojson\";\nimport { featureCollection, lineString } from \"@turf/helpers\";\nimport { getCoords } from \"@turf/invariant\";\nimport { flattenEach } from \"@turf/meta\";\n\n/**\n * Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a\n * {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.\n *\n * @name lineSegment\n * @param {GeoJSON} geojson GeoJSON Polygon or LineString\n * @returns {FeatureCollection<LineString>} 2-vertex line segments\n * @example\n * var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);\n * var segments = turf.lineSegment(polygon);\n *\n * //addToMap\n * var addToMap = [polygon, segments]\n */\nfunction lineSegment<\n G extends LineString | MultiLineString | Polygon | MultiPolygon,\n>(\n geojson: Feature<G> | FeatureCollection<G> | G\n): FeatureCollection<LineString> {\n if (!geojson) {\n throw new Error(\"geojson is required\");\n }\n\n const results: Array<Feature<LineString>> = [];\n flattenEach(geojson, (feature: Feature<any>) => {\n lineSegmentFeature(feature, results);\n });\n return featureCollection(results);\n}\n\n/**\n * Line Segment\n *\n * @private\n * @param {Feature<LineString|Polygon>} geojson Line or polygon feature\n * @param {Array} results push to results\n * @returns {void}\n */\nfunction lineSegmentFeature(\n geojson: Feature<LineString | Polygon>,\n results: Array<Feature<LineString>>\n) {\n let coords: number[][][] = [];\n const geometry = geojson.geometry;\n if (geometry !== null) {\n switch (geometry.type) {\n case \"Polygon\":\n coords = getCoords(geometry);\n break;\n case \"LineString\":\n coords = [getCoords(geometry)];\n }\n coords.forEach((coord) => {\n const segments = createSegments(coord, geojson.properties);\n segments.forEach((segment) => {\n segment.id = results.length;\n results.push(segment);\n });\n });\n }\n}\n\n/**\n * Create Segments from LineString coordinates\n *\n * @private\n * @param {Array<Array<number>>} coords LineString coordinates\n * @param {*} properties GeoJSON properties\n * @returns {Array<Feature<LineString>>} line segments\n */\nfunction createSegments(coords: number[][], properties: any) {\n const segments: Array<Feature<LineString>> = [];\n coords.reduce((previousCoords, currentCoords) => {\n const segment = lineString([previousCoords, currentCoords], properties);\n segment.bbox = bbox(previousCoords, currentCoords);\n segments.push(segment);\n return currentCoords;\n });\n return segments;\n}\n\n/**\n * Create BBox between two coordinates (faster than @turf/bbox)\n *\n * @private\n * @param {Array<number>} coords1 Point coordinate\n * @param {Array<number>} coords2 Point coordinate\n * @returns {BBox} [west, south, east, north]\n */\nfunction bbox(coords1: number[], coords2: number[]): BBox {\n const x1 = coords1[0];\n const y1 = coords1[1];\n const x2 = coords2[0];\n const y2 = coords2[1];\n const west = x1 < x2 ? x1 : x2;\n const south = y1 < y2 ? y1 : y2;\n const east = x1 > x2 ? x1 : x2;\n const north = y1 > y2 ? y1 : y2;\n return [west, south, east, north];\n}\n\nexport { lineSegment };\nexport default lineSegment;\n"],"mappings":";;;;AASA,SAAS,mBAAmB,kBAAkB;AAC9C,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAgB5B,SAAS,YAGP,SAC+B;AAC/B,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AAEA,QAAM,UAAsC,CAAC;AAC7C,cAAY,SAAS,CAAC,YAA0B;AAC9C,uBAAmB,SAAS,OAAO;AAAA,EACrC,CAAC;AACD,SAAO,kBAAkB,OAAO;AAClC;AAdS;AAwBT,SAAS,mBACP,SACA,SACA;AACA,MAAI,SAAuB,CAAC;AAC5B,QAAM,WAAW,QAAQ;AACzB,MAAI,aAAa,MAAM;AACrB,YAAQ,SAAS,MAAM;AAAA,MACrB,KAAK;AACH,iBAAS,UAAU,QAAQ;AAC3B;AAAA,MACF,KAAK;AACH,iBAAS,CAAC,UAAU,QAAQ,CAAC;AAAA,IACjC;AACA,WAAO,QAAQ,CAAC,UAAU;AACxB,YAAM,WAAW,eAAe,OAAO,QAAQ,UAAU;AACzD,eAAS,QAAQ,CAAC,YAAY;AAC5B,gBAAQ,KAAK,QAAQ;AACrB,gBAAQ,KAAK,OAAO;AAAA,MACtB,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;AAtBS;AAgCT,SAAS,eAAe,QAAoB,YAAiB;AAC3D,QAAM,WAAuC,CAAC;AAC9C,SAAO,OAAO,CAAC,gBAAgB,kBAAkB;AAC/C,UAAM,UAAU,WAAW,CAAC,gBAAgB,aAAa,GAAG,UAAU;AACtE,YAAQ,OAAO,KAAK,gBAAgB,aAAa;AACjD,aAAS,KAAK,OAAO;AACrB,WAAO;AAAA,EACT,CAAC;AACD,SAAO;AACT;AATS;AAmBT,SAAS,KAAK,SAAmB,SAAyB;AACxD,QAAM,KAAK,QAAQ,CAAC;AACpB,QAAM,KAAK,QAAQ,CAAC;AACpB,QAAM,KAAK,QAAQ,CAAC;AACpB,QAAM,KAAK,QAAQ,CAAC;AACpB,QAAM,OAAO,KAAK,KAAK,KAAK;AAC5B,QAAM,QAAQ,KAAK,KAAK,KAAK;AAC7B,QAAM,OAAO,KAAK,KAAK,KAAK;AAC5B,QAAM,QAAQ,KAAK,KAAK,KAAK;AAC7B,SAAO,CAAC,MAAM,OAAO,MAAM,KAAK;AAClC;AAVS;AAaT,IAAO,4BAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/line-segment",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.110+1411d63a7",
|
|
4
4
|
"description": "turf line-segment module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,45 +21,51 @@
|
|
|
21
21
|
"line",
|
|
22
22
|
"segment"
|
|
23
23
|
],
|
|
24
|
-
"
|
|
25
|
-
"
|
|
24
|
+
"type": "commonjs",
|
|
25
|
+
"main": "dist/cjs/index.cjs",
|
|
26
|
+
"module": "dist/esm/index.mjs",
|
|
27
|
+
"types": "dist/cjs/index.d.ts",
|
|
26
28
|
"exports": {
|
|
27
29
|
"./package.json": "./package.json",
|
|
28
30
|
".": {
|
|
29
|
-
"import":
|
|
30
|
-
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/esm/index.d.mts",
|
|
33
|
+
"default": "./dist/esm/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/cjs/index.d.ts",
|
|
37
|
+
"default": "./dist/cjs/index.cjs"
|
|
38
|
+
}
|
|
31
39
|
}
|
|
32
40
|
},
|
|
33
|
-
"types": "dist/js/index.d.ts",
|
|
34
41
|
"sideEffects": false,
|
|
35
42
|
"files": [
|
|
36
43
|
"dist"
|
|
37
44
|
],
|
|
38
45
|
"scripts": {
|
|
39
|
-
"bench": "
|
|
40
|
-
"build": "
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"test": "npm-run-all test:*",
|
|
45
|
-
"test:tape": "ts-node -r esm test.js"
|
|
46
|
+
"bench": "tsx bench.ts",
|
|
47
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
48
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
49
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
50
|
+
"test:tape": "tsx test.ts"
|
|
46
51
|
},
|
|
47
52
|
"devDependencies": {
|
|
48
|
-
"@types/
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
53
|
+
"@types/benchmark": "^2.1.5",
|
|
54
|
+
"@types/tape": "^4.2.32",
|
|
55
|
+
"benchmark": "^2.1.4",
|
|
56
|
+
"load-json-file": "^7.0.1",
|
|
57
|
+
"npm-run-all": "^4.1.5",
|
|
58
|
+
"tape": "^5.7.2",
|
|
59
|
+
"tsup": "^8.0.1",
|
|
60
|
+
"tsx": "^4.6.2",
|
|
61
|
+
"typescript": "^5.2.2",
|
|
62
|
+
"write-json-file": "^5.0.0"
|
|
57
63
|
},
|
|
58
64
|
"dependencies": {
|
|
59
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
60
|
-
"@turf/invariant": "^7.0.0-alpha.
|
|
61
|
-
"@turf/meta": "^7.0.0-alpha.
|
|
62
|
-
"tslib": "^2.
|
|
65
|
+
"@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
|
|
66
|
+
"@turf/invariant": "^7.0.0-alpha.110+1411d63a7",
|
|
67
|
+
"@turf/meta": "^7.0.0-alpha.110+1411d63a7",
|
|
68
|
+
"tslib": "^2.6.2"
|
|
63
69
|
},
|
|
64
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
|
|
65
71
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { featureCollection, lineString } from "@turf/helpers";
|
|
2
|
-
import { getCoords } from "@turf/invariant";
|
|
3
|
-
import { flattenEach } from "@turf/meta";
|
|
4
|
-
/**
|
|
5
|
-
* Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a
|
|
6
|
-
* {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.
|
|
7
|
-
*
|
|
8
|
-
* @name lineSegment
|
|
9
|
-
* @param {GeoJSON} geojson GeoJSON Polygon or LineString
|
|
10
|
-
* @returns {FeatureCollection<LineString>} 2-vertex line segments
|
|
11
|
-
* @example
|
|
12
|
-
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
|
|
13
|
-
* var segments = turf.lineSegment(polygon);
|
|
14
|
-
*
|
|
15
|
-
* //addToMap
|
|
16
|
-
* var addToMap = [polygon, segments]
|
|
17
|
-
*/
|
|
18
|
-
function lineSegment(geojson) {
|
|
19
|
-
if (!geojson) {
|
|
20
|
-
throw new Error("geojson is required");
|
|
21
|
-
}
|
|
22
|
-
const results = [];
|
|
23
|
-
flattenEach(geojson, (feature) => {
|
|
24
|
-
lineSegmentFeature(feature, results);
|
|
25
|
-
});
|
|
26
|
-
return featureCollection(results);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Line Segment
|
|
30
|
-
*
|
|
31
|
-
* @private
|
|
32
|
-
* @param {Feature<LineString|Polygon>} geojson Line or polygon feature
|
|
33
|
-
* @param {Array} results push to results
|
|
34
|
-
* @returns {void}
|
|
35
|
-
*/
|
|
36
|
-
function lineSegmentFeature(geojson, results) {
|
|
37
|
-
let coords = [];
|
|
38
|
-
const geometry = geojson.geometry;
|
|
39
|
-
if (geometry !== null) {
|
|
40
|
-
switch (geometry.type) {
|
|
41
|
-
case "Polygon":
|
|
42
|
-
coords = getCoords(geometry);
|
|
43
|
-
break;
|
|
44
|
-
case "LineString":
|
|
45
|
-
coords = [getCoords(geometry)];
|
|
46
|
-
}
|
|
47
|
-
coords.forEach((coord) => {
|
|
48
|
-
const segments = createSegments(coord, geojson.properties);
|
|
49
|
-
segments.forEach((segment) => {
|
|
50
|
-
segment.id = results.length;
|
|
51
|
-
results.push(segment);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Create Segments from LineString coordinates
|
|
58
|
-
*
|
|
59
|
-
* @private
|
|
60
|
-
* @param {Array<Array<number>>} coords LineString coordinates
|
|
61
|
-
* @param {*} properties GeoJSON properties
|
|
62
|
-
* @returns {Array<Feature<LineString>>} line segments
|
|
63
|
-
*/
|
|
64
|
-
function createSegments(coords, properties) {
|
|
65
|
-
const segments = [];
|
|
66
|
-
coords.reduce((previousCoords, currentCoords) => {
|
|
67
|
-
const segment = lineString([previousCoords, currentCoords], properties);
|
|
68
|
-
segment.bbox = bbox(previousCoords, currentCoords);
|
|
69
|
-
segments.push(segment);
|
|
70
|
-
return currentCoords;
|
|
71
|
-
});
|
|
72
|
-
return segments;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Create BBox between two coordinates (faster than @turf/bbox)
|
|
76
|
-
*
|
|
77
|
-
* @private
|
|
78
|
-
* @param {Array<number>} coords1 Point coordinate
|
|
79
|
-
* @param {Array<number>} coords2 Point coordinate
|
|
80
|
-
* @returns {BBox} [west, south, east, north]
|
|
81
|
-
*/
|
|
82
|
-
function bbox(coords1, coords2) {
|
|
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
|
-
return [west, south, east, north];
|
|
92
|
-
}
|
|
93
|
-
export default lineSegment;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const helpers_1 = require("@turf/helpers");
|
|
4
|
-
const invariant_1 = require("@turf/invariant");
|
|
5
|
-
const meta_1 = require("@turf/meta");
|
|
6
|
-
/**
|
|
7
|
-
* Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a
|
|
8
|
-
* {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.
|
|
9
|
-
*
|
|
10
|
-
* @name lineSegment
|
|
11
|
-
* @param {GeoJSON} geojson GeoJSON Polygon or LineString
|
|
12
|
-
* @returns {FeatureCollection<LineString>} 2-vertex line segments
|
|
13
|
-
* @example
|
|
14
|
-
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
|
|
15
|
-
* var segments = turf.lineSegment(polygon);
|
|
16
|
-
*
|
|
17
|
-
* //addToMap
|
|
18
|
-
* var addToMap = [polygon, segments]
|
|
19
|
-
*/
|
|
20
|
-
function lineSegment(geojson) {
|
|
21
|
-
if (!geojson) {
|
|
22
|
-
throw new Error("geojson is required");
|
|
23
|
-
}
|
|
24
|
-
const results = [];
|
|
25
|
-
meta_1.flattenEach(geojson, (feature) => {
|
|
26
|
-
lineSegmentFeature(feature, results);
|
|
27
|
-
});
|
|
28
|
-
return helpers_1.featureCollection(results);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Line Segment
|
|
32
|
-
*
|
|
33
|
-
* @private
|
|
34
|
-
* @param {Feature<LineString|Polygon>} geojson Line or polygon feature
|
|
35
|
-
* @param {Array} results push to results
|
|
36
|
-
* @returns {void}
|
|
37
|
-
*/
|
|
38
|
-
function lineSegmentFeature(geojson, results) {
|
|
39
|
-
let coords = [];
|
|
40
|
-
const geometry = geojson.geometry;
|
|
41
|
-
if (geometry !== null) {
|
|
42
|
-
switch (geometry.type) {
|
|
43
|
-
case "Polygon":
|
|
44
|
-
coords = invariant_1.getCoords(geometry);
|
|
45
|
-
break;
|
|
46
|
-
case "LineString":
|
|
47
|
-
coords = [invariant_1.getCoords(geometry)];
|
|
48
|
-
}
|
|
49
|
-
coords.forEach((coord) => {
|
|
50
|
-
const segments = createSegments(coord, geojson.properties);
|
|
51
|
-
segments.forEach((segment) => {
|
|
52
|
-
segment.id = results.length;
|
|
53
|
-
results.push(segment);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Create Segments from LineString coordinates
|
|
60
|
-
*
|
|
61
|
-
* @private
|
|
62
|
-
* @param {Array<Array<number>>} coords LineString coordinates
|
|
63
|
-
* @param {*} properties GeoJSON properties
|
|
64
|
-
* @returns {Array<Feature<LineString>>} line segments
|
|
65
|
-
*/
|
|
66
|
-
function createSegments(coords, properties) {
|
|
67
|
-
const segments = [];
|
|
68
|
-
coords.reduce((previousCoords, currentCoords) => {
|
|
69
|
-
const segment = helpers_1.lineString([previousCoords, currentCoords], properties);
|
|
70
|
-
segment.bbox = bbox(previousCoords, currentCoords);
|
|
71
|
-
segments.push(segment);
|
|
72
|
-
return currentCoords;
|
|
73
|
-
});
|
|
74
|
-
return segments;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Create BBox between two coordinates (faster than @turf/bbox)
|
|
78
|
-
*
|
|
79
|
-
* @private
|
|
80
|
-
* @param {Array<number>} coords1 Point coordinate
|
|
81
|
-
* @param {Array<number>} coords2 Point coordinate
|
|
82
|
-
* @returns {BBox} [west, south, east, north]
|
|
83
|
-
*/
|
|
84
|
-
function bbox(coords1, coords2) {
|
|
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
|
-
return [west, south, east, north];
|
|
94
|
-
}
|
|
95
|
-
exports.default = lineSegment;
|