@turf/line-chunk 7.0.0-alpha.2 → 7.0.0
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 +54 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +21 -0
- package/{index.d.ts → dist/esm/index.d.ts} +5 -9
- package/dist/esm/index.js +54 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +35 -28
- package/dist/es/index.js +0 -87
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -95
package/README.md
CHANGED
|
@@ -49,26 +49,21 @@ Returns **[FeatureCollection][2]<[LineString][5]>** collection of line segments
|
|
|
49
49
|
|
|
50
50
|
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
51
51
|
|
|
52
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
53
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
54
|
-
./scripts/generate-readmes in the turf project. -->
|
|
52
|
+
<!-- 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. -->
|
|
55
53
|
|
|
56
54
|
---
|
|
57
55
|
|
|
58
|
-
This module is part of the [Turfjs project](
|
|
59
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
60
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
61
|
-
PRs and issues.
|
|
56
|
+
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.
|
|
62
57
|
|
|
63
58
|
### Installation
|
|
64
59
|
|
|
65
|
-
Install this module individually:
|
|
60
|
+
Install this single module individually:
|
|
66
61
|
|
|
67
62
|
```sh
|
|
68
63
|
$ npm install @turf/line-chunk
|
|
69
64
|
```
|
|
70
65
|
|
|
71
|
-
Or install the
|
|
66
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
72
67
|
|
|
73
68
|
```sh
|
|
74
69
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,54 @@
|
|
|
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.js
|
|
5
|
+
var _length = require('@turf/length');
|
|
6
|
+
var _lineslicealong = require('@turf/line-slice-along');
|
|
7
|
+
var _meta = require('@turf/meta');
|
|
8
|
+
var _helpers = require('@turf/helpers');
|
|
9
|
+
function lineChunk(geojson, segmentLength, options) {
|
|
10
|
+
options = options || {};
|
|
11
|
+
if (!_helpers.isObject.call(void 0, options))
|
|
12
|
+
throw new Error("options is invalid");
|
|
13
|
+
var units = options.units;
|
|
14
|
+
var reverse = options.reverse;
|
|
15
|
+
if (!geojson)
|
|
16
|
+
throw new Error("geojson is required");
|
|
17
|
+
if (segmentLength <= 0)
|
|
18
|
+
throw new Error("segmentLength must be greater than 0");
|
|
19
|
+
var results = [];
|
|
20
|
+
_meta.flattenEach.call(void 0, geojson, function(feature) {
|
|
21
|
+
if (reverse)
|
|
22
|
+
feature.geometry.coordinates = feature.geometry.coordinates.reverse();
|
|
23
|
+
sliceLineSegments(feature, segmentLength, units, function(segment) {
|
|
24
|
+
results.push(segment);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return _helpers.featureCollection.call(void 0, results);
|
|
28
|
+
}
|
|
29
|
+
__name(lineChunk, "lineChunk");
|
|
30
|
+
function sliceLineSegments(line, segmentLength, units, callback) {
|
|
31
|
+
var lineLength = _length.length.call(void 0, line, { units });
|
|
32
|
+
if (lineLength <= segmentLength)
|
|
33
|
+
return callback(line);
|
|
34
|
+
var numberOfSegments = lineLength / segmentLength;
|
|
35
|
+
if (!Number.isInteger(numberOfSegments)) {
|
|
36
|
+
numberOfSegments = Math.floor(numberOfSegments) + 1;
|
|
37
|
+
}
|
|
38
|
+
for (var i = 0; i < numberOfSegments; i++) {
|
|
39
|
+
var outline = _lineslicealong.lineSliceAlong.call(void 0,
|
|
40
|
+
line,
|
|
41
|
+
segmentLength * i,
|
|
42
|
+
segmentLength * (i + 1),
|
|
43
|
+
{ units }
|
|
44
|
+
);
|
|
45
|
+
callback(outline, i);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
__name(sliceLineSegments, "sliceLineSegments");
|
|
49
|
+
var turf_line_chunk_default = lineChunk;
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
exports.default = turf_line_chunk_default; exports.lineChunk = lineChunk;
|
|
54
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"names":[],"mappings":";;;;AAAA,SAAS,cAAc;AACvB,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB,gBAAgB;AAqB5C,SAAS,UAAU,SAAS,eAAe,SAAS;AAElD,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,QAAQ,QAAQ;AACpB,MAAI,UAAU,QAAQ;AAGtB,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,iBAAiB;AACnB,UAAM,IAAI,MAAM,sCAAsC;AAGxD,MAAI,UAAU,CAAC;AAGf,cAAY,SAAS,SAAU,SAAS;AAEtC,QAAI;AACF,cAAQ,SAAS,cAAc,QAAQ,SAAS,YAAY,QAAQ;AAEtE,sBAAkB,SAAS,eAAe,OAAO,SAAU,SAAS;AAClE,cAAQ,KAAK,OAAO;AAAA,IACtB,CAAC;AAAA,EACH,CAAC;AACD,SAAO,kBAAkB,OAAO;AAClC;AA1BS;AAsCT,SAAS,kBAAkB,MAAM,eAAe,OAAO,UAAU;AAC/D,MAAI,aAAa,OAAO,MAAM,EAAE,MAAa,CAAC;AAG9C,MAAI,cAAc;AAAe,WAAO,SAAS,IAAI;AAErD,MAAI,mBAAmB,aAAa;AAGpC,MAAI,CAAC,OAAO,UAAU,gBAAgB,GAAG;AACvC,uBAAmB,KAAK,MAAM,gBAAgB,IAAI;AAAA,EACpD;AAEA,WAAS,IAAI,GAAG,IAAI,kBAAkB,KAAK;AACzC,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,gBAAgB;AAAA,MAChB,iBAAiB,IAAI;AAAA,MACrB,EAAE,MAAa;AAAA,IACjB;AACA,aAAS,SAAS,CAAC;AAAA,EACrB;AACF;AAtBS;AAyBT,IAAO,0BAAQ","sourcesContent":["import { length } from \"@turf/length\";\nimport { lineSliceAlong } from \"@turf/line-slice-along\";\nimport { flattenEach } from \"@turf/meta\";\nimport { featureCollection, isObject } from \"@turf/helpers\";\n\n/**\n * Divides a {@link LineString} into chunks of a specified length.\n * If the line is shorter than the segment length then the original line is returned.\n *\n * @name lineChunk\n * @param {FeatureCollection|Geometry|Feature<LineString|MultiLineString>} geojson the lines to split\n * @param {number} segmentLength how long to make each segment\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] units can be degrees, radians, miles, or kilometers\n * @param {boolean} [options.reverse=false] reverses coordinates to start the first chunked segment at the end\n * @returns {FeatureCollection<LineString>} collection of line segments\n * @example\n * var line = turf.lineString([[-95, 40], [-93, 45], [-85, 50]]);\n *\n * var chunk = turf.lineChunk(line, 15, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [chunk];\n */\nfunction lineChunk(geojson, segmentLength, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var units = options.units;\n var reverse = options.reverse;\n\n // Validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (segmentLength <= 0)\n throw new Error(\"segmentLength must be greater than 0\");\n\n // Container\n var results = [];\n\n // Flatten each feature to simple LineString\n flattenEach(geojson, function (feature) {\n // reverses coordinates to start the first chunked segment at the end\n if (reverse)\n feature.geometry.coordinates = feature.geometry.coordinates.reverse();\n\n sliceLineSegments(feature, segmentLength, units, function (segment) {\n results.push(segment);\n });\n });\n return featureCollection(results);\n}\n\n/**\n * Slice Line Segments\n *\n * @private\n * @param {Feature<LineString>} line GeoJSON LineString\n * @param {number} segmentLength how long to make each segment\n * @param {string}[units='kilometers'] units can be degrees, radians, miles, or kilometers\n * @param {Function} callback iterate over sliced line segments\n * @returns {void}\n */\nfunction sliceLineSegments(line, segmentLength, units, callback) {\n var lineLength = length(line, { units: units });\n\n // If the line is shorter than the segment length then the orginal line is returned.\n if (lineLength <= segmentLength) return callback(line);\n\n var numberOfSegments = lineLength / segmentLength;\n\n // If numberOfSegments is integer, no need to plus 1\n if (!Number.isInteger(numberOfSegments)) {\n numberOfSegments = Math.floor(numberOfSegments) + 1;\n }\n\n for (var i = 0; i < numberOfSegments; i++) {\n var outline = lineSliceAlong(\n line,\n segmentLength * i,\n segmentLength * (i + 1),\n { units: units }\n );\n callback(outline, i);\n }\n}\n\nexport { lineChunk };\nexport default lineChunk;\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LineString, MultiLineString, Feature, FeatureCollection, GeometryCollection } from 'geojson';
|
|
2
|
+
import { Units } from '@turf/helpers';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* http://turfjs.org/docs/#lineChunk
|
|
6
|
+
*/
|
|
7
|
+
declare function lineChunk<T extends LineString | MultiLineString>(
|
|
8
|
+
geojson:
|
|
9
|
+
| Feature<T>
|
|
10
|
+
| FeatureCollection<T>
|
|
11
|
+
| T
|
|
12
|
+
| GeometryCollection
|
|
13
|
+
| Feature<GeometryCollection>,
|
|
14
|
+
segmentLength: number,
|
|
15
|
+
options?: {
|
|
16
|
+
units?: Units;
|
|
17
|
+
reverse?: boolean;
|
|
18
|
+
}
|
|
19
|
+
): FeatureCollection<LineString>;
|
|
20
|
+
|
|
21
|
+
export { lineChunk as default, lineChunk };
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
MultiLineString,
|
|
4
|
-
GeometryCollection,
|
|
5
|
-
Feature,
|
|
6
|
-
FeatureCollection,
|
|
7
|
-
} from "geojson";
|
|
8
|
-
import { Units } from "@turf/helpers";
|
|
1
|
+
import { LineString, MultiLineString, Feature, FeatureCollection, GeometryCollection } from 'geojson';
|
|
2
|
+
import { Units } from '@turf/helpers';
|
|
9
3
|
|
|
10
4
|
/**
|
|
11
5
|
* http://turfjs.org/docs/#lineChunk
|
|
12
6
|
*/
|
|
13
|
-
|
|
7
|
+
declare function lineChunk<T extends LineString | MultiLineString>(
|
|
14
8
|
geojson:
|
|
15
9
|
| Feature<T>
|
|
16
10
|
| FeatureCollection<T>
|
|
@@ -23,3 +17,5 @@ export default function lineChunk<T extends LineString | MultiLineString>(
|
|
|
23
17
|
reverse?: boolean;
|
|
24
18
|
}
|
|
25
19
|
): FeatureCollection<LineString>;
|
|
20
|
+
|
|
21
|
+
export { lineChunk as default, lineChunk };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.js
|
|
5
|
+
import { length } from "@turf/length";
|
|
6
|
+
import { lineSliceAlong } from "@turf/line-slice-along";
|
|
7
|
+
import { flattenEach } from "@turf/meta";
|
|
8
|
+
import { featureCollection, isObject } from "@turf/helpers";
|
|
9
|
+
function lineChunk(geojson, segmentLength, options) {
|
|
10
|
+
options = options || {};
|
|
11
|
+
if (!isObject(options))
|
|
12
|
+
throw new Error("options is invalid");
|
|
13
|
+
var units = options.units;
|
|
14
|
+
var reverse = options.reverse;
|
|
15
|
+
if (!geojson)
|
|
16
|
+
throw new Error("geojson is required");
|
|
17
|
+
if (segmentLength <= 0)
|
|
18
|
+
throw new Error("segmentLength must be greater than 0");
|
|
19
|
+
var results = [];
|
|
20
|
+
flattenEach(geojson, function(feature) {
|
|
21
|
+
if (reverse)
|
|
22
|
+
feature.geometry.coordinates = feature.geometry.coordinates.reverse();
|
|
23
|
+
sliceLineSegments(feature, segmentLength, units, function(segment) {
|
|
24
|
+
results.push(segment);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return featureCollection(results);
|
|
28
|
+
}
|
|
29
|
+
__name(lineChunk, "lineChunk");
|
|
30
|
+
function sliceLineSegments(line, segmentLength, units, callback) {
|
|
31
|
+
var lineLength = length(line, { units });
|
|
32
|
+
if (lineLength <= segmentLength)
|
|
33
|
+
return callback(line);
|
|
34
|
+
var numberOfSegments = lineLength / segmentLength;
|
|
35
|
+
if (!Number.isInteger(numberOfSegments)) {
|
|
36
|
+
numberOfSegments = Math.floor(numberOfSegments) + 1;
|
|
37
|
+
}
|
|
38
|
+
for (var i = 0; i < numberOfSegments; i++) {
|
|
39
|
+
var outline = lineSliceAlong(
|
|
40
|
+
line,
|
|
41
|
+
segmentLength * i,
|
|
42
|
+
segmentLength * (i + 1),
|
|
43
|
+
{ units }
|
|
44
|
+
);
|
|
45
|
+
callback(outline, i);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
__name(sliceLineSegments, "sliceLineSegments");
|
|
49
|
+
var turf_line_chunk_default = lineChunk;
|
|
50
|
+
export {
|
|
51
|
+
turf_line_chunk_default as default,
|
|
52
|
+
lineChunk
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"sourcesContent":["import { length } from \"@turf/length\";\nimport { lineSliceAlong } from \"@turf/line-slice-along\";\nimport { flattenEach } from \"@turf/meta\";\nimport { featureCollection, isObject } from \"@turf/helpers\";\n\n/**\n * Divides a {@link LineString} into chunks of a specified length.\n * If the line is shorter than the segment length then the original line is returned.\n *\n * @name lineChunk\n * @param {FeatureCollection|Geometry|Feature<LineString|MultiLineString>} geojson the lines to split\n * @param {number} segmentLength how long to make each segment\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.units='kilometers'] units can be degrees, radians, miles, or kilometers\n * @param {boolean} [options.reverse=false] reverses coordinates to start the first chunked segment at the end\n * @returns {FeatureCollection<LineString>} collection of line segments\n * @example\n * var line = turf.lineString([[-95, 40], [-93, 45], [-85, 50]]);\n *\n * var chunk = turf.lineChunk(line, 15, {units: 'miles'});\n *\n * //addToMap\n * var addToMap = [chunk];\n */\nfunction lineChunk(geojson, segmentLength, options) {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n var units = options.units;\n var reverse = options.reverse;\n\n // Validation\n if (!geojson) throw new Error(\"geojson is required\");\n if (segmentLength <= 0)\n throw new Error(\"segmentLength must be greater than 0\");\n\n // Container\n var results = [];\n\n // Flatten each feature to simple LineString\n flattenEach(geojson, function (feature) {\n // reverses coordinates to start the first chunked segment at the end\n if (reverse)\n feature.geometry.coordinates = feature.geometry.coordinates.reverse();\n\n sliceLineSegments(feature, segmentLength, units, function (segment) {\n results.push(segment);\n });\n });\n return featureCollection(results);\n}\n\n/**\n * Slice Line Segments\n *\n * @private\n * @param {Feature<LineString>} line GeoJSON LineString\n * @param {number} segmentLength how long to make each segment\n * @param {string}[units='kilometers'] units can be degrees, radians, miles, or kilometers\n * @param {Function} callback iterate over sliced line segments\n * @returns {void}\n */\nfunction sliceLineSegments(line, segmentLength, units, callback) {\n var lineLength = length(line, { units: units });\n\n // If the line is shorter than the segment length then the orginal line is returned.\n if (lineLength <= segmentLength) return callback(line);\n\n var numberOfSegments = lineLength / segmentLength;\n\n // If numberOfSegments is integer, no need to plus 1\n if (!Number.isInteger(numberOfSegments)) {\n numberOfSegments = Math.floor(numberOfSegments) + 1;\n }\n\n for (var i = 0; i < numberOfSegments; i++) {\n var outline = lineSliceAlong(\n line,\n segmentLength * i,\n segmentLength * (i + 1),\n { units: units }\n );\n callback(outline, i);\n }\n}\n\nexport { lineChunk };\nexport default lineChunk;\n"],"mappings":";;;;AAAA,SAAS,cAAc;AACvB,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB,gBAAgB;AAqB5C,SAAS,UAAU,SAAS,eAAe,SAAS;AAElD,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,MAAI,QAAQ,QAAQ;AACpB,MAAI,UAAU,QAAQ;AAGtB,MAAI,CAAC;AAAS,UAAM,IAAI,MAAM,qBAAqB;AACnD,MAAI,iBAAiB;AACnB,UAAM,IAAI,MAAM,sCAAsC;AAGxD,MAAI,UAAU,CAAC;AAGf,cAAY,SAAS,SAAU,SAAS;AAEtC,QAAI;AACF,cAAQ,SAAS,cAAc,QAAQ,SAAS,YAAY,QAAQ;AAEtE,sBAAkB,SAAS,eAAe,OAAO,SAAU,SAAS;AAClE,cAAQ,KAAK,OAAO;AAAA,IACtB,CAAC;AAAA,EACH,CAAC;AACD,SAAO,kBAAkB,OAAO;AAClC;AA1BS;AAsCT,SAAS,kBAAkB,MAAM,eAAe,OAAO,UAAU;AAC/D,MAAI,aAAa,OAAO,MAAM,EAAE,MAAa,CAAC;AAG9C,MAAI,cAAc;AAAe,WAAO,SAAS,IAAI;AAErD,MAAI,mBAAmB,aAAa;AAGpC,MAAI,CAAC,OAAO,UAAU,gBAAgB,GAAG;AACvC,uBAAmB,KAAK,MAAM,gBAAgB,IAAI;AAAA,EACpD;AAEA,WAAS,IAAI,GAAG,IAAI,kBAAkB,KAAK;AACzC,QAAI,UAAU;AAAA,MACZ;AAAA,MACA,gBAAgB;AAAA,MAChB,iBAAiB,IAAI;AAAA,MACrB,EAAE,MAAa;AAAA,IACjB;AACA,aAAS,SAAS,CAAC;AAAA,EACrB;AACF;AAtBS;AAyBT,IAAO,0BAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/line-chunk",
|
|
3
|
-
"version": "7.0.0
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "turf line-chunk module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -29,45 +29,52 @@
|
|
|
29
29
|
"linestring",
|
|
30
30
|
"line segment"
|
|
31
31
|
],
|
|
32
|
-
"
|
|
33
|
-
"
|
|
32
|
+
"type": "module",
|
|
33
|
+
"main": "dist/cjs/index.cjs",
|
|
34
|
+
"module": "dist/esm/index.js",
|
|
35
|
+
"types": "dist/esm/index.d.ts",
|
|
34
36
|
"exports": {
|
|
35
37
|
"./package.json": "./package.json",
|
|
36
38
|
".": {
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/esm/index.d.ts",
|
|
41
|
+
"default": "./dist/esm/index.js"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/cjs/index.d.cts",
|
|
45
|
+
"default": "./dist/cjs/index.cjs"
|
|
46
|
+
}
|
|
40
47
|
}
|
|
41
48
|
},
|
|
42
|
-
"types": "index.d.ts",
|
|
43
49
|
"sideEffects": false,
|
|
44
50
|
"files": [
|
|
45
|
-
"dist"
|
|
46
|
-
"index.d.ts"
|
|
51
|
+
"dist"
|
|
47
52
|
],
|
|
48
53
|
"scripts": {
|
|
49
|
-
"bench": "tsx bench.
|
|
50
|
-
"build": "
|
|
51
|
-
"docs": "tsx ../../scripts/generate-readmes",
|
|
52
|
-
"test": "npm-run-all test:*",
|
|
53
|
-
"test:tape": "tsx test.
|
|
54
|
-
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
54
|
+
"bench": "tsx bench.ts",
|
|
55
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
56
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
57
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
58
|
+
"test:tape": "tsx test.ts",
|
|
59
|
+
"test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
|
|
55
60
|
},
|
|
56
61
|
"devDependencies": {
|
|
57
|
-
"@turf/truncate": "^7.0.0
|
|
58
|
-
"benchmark": "
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
62
|
+
"@turf/truncate": "^7.0.0",
|
|
63
|
+
"@types/benchmark": "^2.1.5",
|
|
64
|
+
"@types/tape": "^4.2.32",
|
|
65
|
+
"benchmark": "^2.1.4",
|
|
66
|
+
"load-json-file": "^7.0.1",
|
|
67
|
+
"npm-run-all": "^4.1.5",
|
|
68
|
+
"tape": "^5.7.2",
|
|
69
|
+
"tsup": "^8.0.1",
|
|
70
|
+
"tsx": "^4.6.2",
|
|
71
|
+
"write-json-file": "^5.0.0"
|
|
65
72
|
},
|
|
66
73
|
"dependencies": {
|
|
67
|
-
"@turf/helpers": "^7.0.0
|
|
68
|
-
"@turf/length": "^7.0.0
|
|
69
|
-
"@turf/line-slice-along": "^7.0.0
|
|
70
|
-
"@turf/meta": "^7.0.0
|
|
74
|
+
"@turf/helpers": "^7.0.0",
|
|
75
|
+
"@turf/length": "^7.0.0",
|
|
76
|
+
"@turf/line-slice-along": "^7.0.0",
|
|
77
|
+
"@turf/meta": "^7.0.0"
|
|
71
78
|
},
|
|
72
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
|
|
73
80
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import length from '@turf/length';
|
|
2
|
-
import lineSliceAlong from '@turf/line-slice-along';
|
|
3
|
-
import { flattenEach } from '@turf/meta';
|
|
4
|
-
import { isObject, featureCollection } from '@turf/helpers';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Divides a {@link LineString} into chunks of a specified length.
|
|
8
|
-
* If the line is shorter than the segment length then the original line is returned.
|
|
9
|
-
*
|
|
10
|
-
* @name lineChunk
|
|
11
|
-
* @param {FeatureCollection|Geometry|Feature<LineString|MultiLineString>} geojson the lines to split
|
|
12
|
-
* @param {number} segmentLength how long to make each segment
|
|
13
|
-
* @param {Object} [options={}] Optional parameters
|
|
14
|
-
* @param {string} [options.units='kilometers'] units can be degrees, radians, miles, or kilometers
|
|
15
|
-
* @param {boolean} [options.reverse=false] reverses coordinates to start the first chunked segment at the end
|
|
16
|
-
* @returns {FeatureCollection<LineString>} collection of line segments
|
|
17
|
-
* @example
|
|
18
|
-
* var line = turf.lineString([[-95, 40], [-93, 45], [-85, 50]]);
|
|
19
|
-
*
|
|
20
|
-
* var chunk = turf.lineChunk(line, 15, {units: 'miles'});
|
|
21
|
-
*
|
|
22
|
-
* //addToMap
|
|
23
|
-
* var addToMap = [chunk];
|
|
24
|
-
*/
|
|
25
|
-
function lineChunk(geojson, segmentLength, options) {
|
|
26
|
-
// Optional parameters
|
|
27
|
-
options = options || {};
|
|
28
|
-
if (!isObject(options)) throw new Error("options is invalid");
|
|
29
|
-
var units = options.units;
|
|
30
|
-
var reverse = options.reverse;
|
|
31
|
-
|
|
32
|
-
// Validation
|
|
33
|
-
if (!geojson) throw new Error("geojson is required");
|
|
34
|
-
if (segmentLength <= 0)
|
|
35
|
-
throw new Error("segmentLength must be greater than 0");
|
|
36
|
-
|
|
37
|
-
// Container
|
|
38
|
-
var results = [];
|
|
39
|
-
|
|
40
|
-
// Flatten each feature to simple LineString
|
|
41
|
-
flattenEach(geojson, function (feature) {
|
|
42
|
-
// reverses coordinates to start the first chunked segment at the end
|
|
43
|
-
if (reverse)
|
|
44
|
-
feature.geometry.coordinates = feature.geometry.coordinates.reverse();
|
|
45
|
-
|
|
46
|
-
sliceLineSegments(feature, segmentLength, units, function (segment) {
|
|
47
|
-
results.push(segment);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
return featureCollection(results);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Slice Line Segments
|
|
55
|
-
*
|
|
56
|
-
* @private
|
|
57
|
-
* @param {Feature<LineString>} line GeoJSON LineString
|
|
58
|
-
* @param {number} segmentLength how long to make each segment
|
|
59
|
-
* @param {string}[units='kilometers'] units can be degrees, radians, miles, or kilometers
|
|
60
|
-
* @param {Function} callback iterate over sliced line segments
|
|
61
|
-
* @returns {void}
|
|
62
|
-
*/
|
|
63
|
-
function sliceLineSegments(line, segmentLength, units, callback) {
|
|
64
|
-
var lineLength = length(line, { units: units });
|
|
65
|
-
|
|
66
|
-
// If the line is shorter than the segment length then the orginal line is returned.
|
|
67
|
-
if (lineLength <= segmentLength) return callback(line);
|
|
68
|
-
|
|
69
|
-
var numberOfSegments = lineLength / segmentLength;
|
|
70
|
-
|
|
71
|
-
// If numberOfSegments is integer, no need to plus 1
|
|
72
|
-
if (!Number.isInteger(numberOfSegments)) {
|
|
73
|
-
numberOfSegments = Math.floor(numberOfSegments) + 1;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
for (var i = 0; i < numberOfSegments; i++) {
|
|
77
|
-
var outline = lineSliceAlong(
|
|
78
|
-
line,
|
|
79
|
-
segmentLength * i,
|
|
80
|
-
segmentLength * (i + 1),
|
|
81
|
-
{ units: units }
|
|
82
|
-
);
|
|
83
|
-
callback(outline, i);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export default lineChunk;
|
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
|
-
|
|
3
|
-
var length = require('@turf/length');
|
|
4
|
-
var lineSliceAlong = require('@turf/line-slice-along');
|
|
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 length__default = /*#__PURE__*/_interopDefaultLegacy(length);
|
|
11
|
-
var lineSliceAlong__default = /*#__PURE__*/_interopDefaultLegacy(lineSliceAlong);
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Divides a {@link LineString} into chunks of a specified length.
|
|
15
|
-
* If the line is shorter than the segment length then the original line is returned.
|
|
16
|
-
*
|
|
17
|
-
* @name lineChunk
|
|
18
|
-
* @param {FeatureCollection|Geometry|Feature<LineString|MultiLineString>} geojson the lines to split
|
|
19
|
-
* @param {number} segmentLength how long to make each segment
|
|
20
|
-
* @param {Object} [options={}] Optional parameters
|
|
21
|
-
* @param {string} [options.units='kilometers'] units can be degrees, radians, miles, or kilometers
|
|
22
|
-
* @param {boolean} [options.reverse=false] reverses coordinates to start the first chunked segment at the end
|
|
23
|
-
* @returns {FeatureCollection<LineString>} collection of line segments
|
|
24
|
-
* @example
|
|
25
|
-
* var line = turf.lineString([[-95, 40], [-93, 45], [-85, 50]]);
|
|
26
|
-
*
|
|
27
|
-
* var chunk = turf.lineChunk(line, 15, {units: 'miles'});
|
|
28
|
-
*
|
|
29
|
-
* //addToMap
|
|
30
|
-
* var addToMap = [chunk];
|
|
31
|
-
*/
|
|
32
|
-
function lineChunk(geojson, segmentLength, options) {
|
|
33
|
-
// Optional parameters
|
|
34
|
-
options = options || {};
|
|
35
|
-
if (!helpers.isObject(options)) throw new Error("options is invalid");
|
|
36
|
-
var units = options.units;
|
|
37
|
-
var reverse = options.reverse;
|
|
38
|
-
|
|
39
|
-
// Validation
|
|
40
|
-
if (!geojson) throw new Error("geojson is required");
|
|
41
|
-
if (segmentLength <= 0)
|
|
42
|
-
throw new Error("segmentLength must be greater than 0");
|
|
43
|
-
|
|
44
|
-
// Container
|
|
45
|
-
var results = [];
|
|
46
|
-
|
|
47
|
-
// Flatten each feature to simple LineString
|
|
48
|
-
meta.flattenEach(geojson, function (feature) {
|
|
49
|
-
// reverses coordinates to start the first chunked segment at the end
|
|
50
|
-
if (reverse)
|
|
51
|
-
feature.geometry.coordinates = feature.geometry.coordinates.reverse();
|
|
52
|
-
|
|
53
|
-
sliceLineSegments(feature, segmentLength, units, function (segment) {
|
|
54
|
-
results.push(segment);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
return helpers.featureCollection(results);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Slice Line Segments
|
|
62
|
-
*
|
|
63
|
-
* @private
|
|
64
|
-
* @param {Feature<LineString>} line GeoJSON LineString
|
|
65
|
-
* @param {number} segmentLength how long to make each segment
|
|
66
|
-
* @param {string}[units='kilometers'] units can be degrees, radians, miles, or kilometers
|
|
67
|
-
* @param {Function} callback iterate over sliced line segments
|
|
68
|
-
* @returns {void}
|
|
69
|
-
*/
|
|
70
|
-
function sliceLineSegments(line, segmentLength, units, callback) {
|
|
71
|
-
var lineLength = length__default['default'](line, { units: units });
|
|
72
|
-
|
|
73
|
-
// If the line is shorter than the segment length then the orginal line is returned.
|
|
74
|
-
if (lineLength <= segmentLength) return callback(line);
|
|
75
|
-
|
|
76
|
-
var numberOfSegments = lineLength / segmentLength;
|
|
77
|
-
|
|
78
|
-
// If numberOfSegments is integer, no need to plus 1
|
|
79
|
-
if (!Number.isInteger(numberOfSegments)) {
|
|
80
|
-
numberOfSegments = Math.floor(numberOfSegments) + 1;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
for (var i = 0; i < numberOfSegments; i++) {
|
|
84
|
-
var outline = lineSliceAlong__default['default'](
|
|
85
|
-
line,
|
|
86
|
-
segmentLength * i,
|
|
87
|
-
segmentLength * (i + 1),
|
|
88
|
-
{ units: units }
|
|
89
|
-
);
|
|
90
|
-
callback(outline, i);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
module.exports = lineChunk;
|
|
95
|
-
module.exports.default = lineChunk;
|