@turf/line-slice 7.3.0 → 7.3.2
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/dist/cjs/index.cjs +8 -13
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +29 -7
- package/dist/esm/index.d.ts +29 -7
- package/dist/esm/index.js +8 -13
- package/dist/esm/index.js.map +1 -1
- package/package.json +10 -9
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
|
|
2
2
|
var _invariant = require('@turf/invariant');
|
|
3
3
|
var _helpers = require('@turf/helpers');
|
|
4
4
|
var _nearestpointonline = require('@turf/nearest-point-on-line');
|
|
5
5
|
function lineSlice(startPt, stopPt, line) {
|
|
6
|
-
|
|
6
|
+
const coords = _invariant.getCoords.call(void 0, line);
|
|
7
7
|
if (_invariant.getType.call(void 0, line) !== "LineString")
|
|
8
8
|
throw new Error("line must be a LineString");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} else {
|
|
15
|
-
ends = [stopVertex, startVertex];
|
|
16
|
-
}
|
|
17
|
-
var clipCoords = [ends[0].geometry.coordinates];
|
|
18
|
-
for (var i = ends[0].properties.index + 1; i < ends[1].properties.index + 1; i++) {
|
|
9
|
+
const startVertex = _nearestpointonline.nearestPointOnLine.call(void 0, line, startPt);
|
|
10
|
+
const stopVertex = _nearestpointonline.nearestPointOnLine.call(void 0, line, stopPt);
|
|
11
|
+
const ends = startVertex.properties.index <= stopVertex.properties.index ? [startVertex, stopVertex] : [stopVertex, startVertex];
|
|
12
|
+
const clipCoords = [ends[0].geometry.coordinates];
|
|
13
|
+
for (let i = ends[0].properties.index + 1; i < ends[1].properties.index + 1; i++) {
|
|
19
14
|
clipCoords.push(coords[i]);
|
|
20
15
|
}
|
|
21
16
|
clipCoords.push(ends[1].geometry.coordinates);
|
|
22
|
-
return _helpers.lineString.call(void 0, clipCoords, line.properties);
|
|
17
|
+
return _helpers.lineString.call(void 0, clipCoords, line.type === "Feature" ? line.properties : {});
|
|
23
18
|
}
|
|
24
19
|
var index_default = lineSlice;
|
|
25
20
|
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-line-slice/dist/cjs/index.cjs","../../index.
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-line-slice/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACAA,4CAAmC;AACnC,wCAAgD;AAChD,iEAAmC;AAgCnC,SAAS,SAAA,CACP,OAAA,EACA,MAAA,EACA,IAAA,EACqB;AAErB,EAAA,MAAM,OAAA,EAAS,kCAAA,IAAc,CAAA;AAC7B,EAAA,GAAA,CAAI,gCAAA,IAAY,EAAA,IAAM,YAAA;AACpB,IAAA,MAAM,IAAI,KAAA,CAAM,2BAA2B,CAAA;AAE7C,EAAA,MAAM,YAAA,EAAc,oDAAA,IAAmB,EAAM,OAAO,CAAA;AACpD,EAAA,MAAM,WAAA,EAAa,oDAAA,IAAmB,EAAM,MAAM,CAAA;AAClD,EAAA,MAAM,KAAA,EACJ,WAAA,CAAY,UAAA,CAAW,MAAA,GAAS,UAAA,CAAW,UAAA,CAAW,MAAA,EAClD,CAAC,WAAA,EAAa,UAAU,EAAA,EACxB,CAAC,UAAA,EAAY,WAAW,CAAA;AAC9B,EAAA,MAAM,WAAA,EAAa,CAAC,IAAA,CAAK,CAAC,CAAA,CAAE,QAAA,CAAS,WAAW,CAAA;AAChD,EAAA,IAAA,CAAA,IACM,EAAA,EAAI,IAAA,CAAK,CAAC,CAAA,CAAE,UAAA,CAAW,MAAA,EAAQ,CAAA,EACnC,EAAA,EAAI,IAAA,CAAK,CAAC,CAAA,CAAE,UAAA,CAAW,MAAA,EAAQ,CAAA,EAC/B,CAAA,EAAA,EACA;AACA,IAAA,UAAA,CAAW,IAAA,CAAK,MAAA,CAAO,CAAC,CAAC,CAAA;AAAA,EAC3B;AACA,EAAA,UAAA,CAAW,IAAA,CAAK,IAAA,CAAK,CAAC,CAAA,CAAE,QAAA,CAAS,WAAW,CAAA;AAC5C,EAAA,OAAO,iCAAA,UAAW,EAAY,IAAA,CAAK,KAAA,IAAS,UAAA,EAAY,IAAA,CAAK,WAAA,EAAa,CAAC,CAAC,CAAA;AAC9E;AAGA,IAAO,cAAA,EAAQ,SAAA;AD5Cf;AACE;AACA;AACF,+DAAC","file":"/home/runner/work/turf/turf/packages/turf-line-slice/dist/cjs/index.cjs","sourcesContent":[null,"import { getCoords, getType } from \"@turf/invariant\";\nimport { Coord, lineString as linestring } from \"@turf/helpers\";\nimport { nearestPointOnLine } from \"@turf/nearest-point-on-line\";\nimport { Feature, LineString } from \"geojson\";\n\n/**\n * Takes a {@link LineString|line}, a start {@link Point}, and a stop point\n * and returns a subsection of the line in-between those points.\n * The start & stop points don't need to fall exactly on the line.\n *\n * This can be useful for extracting only the part of a route between waypoints.\n *\n * @function\n * @param {Coord} startPt starting point\n * @param {Coord} stopPt stopping point\n * @param {Feature<LineString>|LineString} line line to slice\n * @returns {Feature<LineString>} sliced line\n * @example\n * var line = turf.lineString([\n * [-77.031669, 38.878605],\n * [-77.029609, 38.881946],\n * [-77.020339, 38.884084],\n * [-77.025661, 38.885821],\n * [-77.021884, 38.889563],\n * [-77.019824, 38.892368]\n * ]);\n * var start = turf.point([-77.029609, 38.881946]);\n * var stop = turf.point([-77.021884, 38.889563]);\n *\n * var sliced = turf.lineSlice(start, stop, line);\n *\n * //addToMap\n * var addToMap = [start, stop, line]\n */\nfunction lineSlice(\n startPt: Coord,\n stopPt: Coord,\n line: Feature<LineString> | LineString\n): Feature<LineString> {\n // Validation\n const coords = getCoords(line);\n if (getType(line) !== \"LineString\")\n throw new Error(\"line must be a LineString\");\n\n const startVertex = nearestPointOnLine(line, startPt);\n const stopVertex = nearestPointOnLine(line, stopPt);\n const ends =\n startVertex.properties.index <= stopVertex.properties.index\n ? [startVertex, stopVertex]\n : [stopVertex, startVertex];\n const clipCoords = [ends[0].geometry.coordinates];\n for (\n let i = ends[0].properties.index + 1;\n i < ends[1].properties.index + 1;\n i++\n ) {\n clipCoords.push(coords[i]);\n }\n clipCoords.push(ends[1].geometry.coordinates);\n return linestring(clipCoords, line.type === \"Feature\" ? line.properties : {});\n}\n\nexport { lineSlice };\nexport default lineSlice;\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
|
-
import { Feature, LineString } from 'geojson';
|
|
2
1
|
import { Coord } from '@turf/helpers';
|
|
2
|
+
import { Feature, LineString } from 'geojson';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Takes a {@link LineString|line}, a start {@link Point}, and a stop point
|
|
6
|
+
* and returns a subsection of the line in-between those points.
|
|
7
|
+
* The start & stop points don't need to fall exactly on the line.
|
|
8
|
+
*
|
|
9
|
+
* This can be useful for extracting only the part of a route between waypoints.
|
|
10
|
+
*
|
|
11
|
+
* @function
|
|
12
|
+
* @param {Coord} startPt starting point
|
|
13
|
+
* @param {Coord} stopPt stopping point
|
|
14
|
+
* @param {Feature<LineString>|LineString} line line to slice
|
|
15
|
+
* @returns {Feature<LineString>} sliced line
|
|
16
|
+
* @example
|
|
17
|
+
* var line = turf.lineString([
|
|
18
|
+
* [-77.031669, 38.878605],
|
|
19
|
+
* [-77.029609, 38.881946],
|
|
20
|
+
* [-77.020339, 38.884084],
|
|
21
|
+
* [-77.025661, 38.885821],
|
|
22
|
+
* [-77.021884, 38.889563],
|
|
23
|
+
* [-77.019824, 38.892368]
|
|
24
|
+
* ]);
|
|
25
|
+
* var start = turf.point([-77.029609, 38.881946]);
|
|
26
|
+
* var stop = turf.point([-77.021884, 38.889563]);
|
|
27
|
+
*
|
|
28
|
+
* var sliced = turf.lineSlice(start, stop, line);
|
|
29
|
+
*
|
|
30
|
+
* //addToMap
|
|
31
|
+
* var addToMap = [start, stop, line]
|
|
6
32
|
*/
|
|
7
|
-
declare function lineSlice(
|
|
8
|
-
startPt: Coord,
|
|
9
|
-
stopPt: Coord,
|
|
10
|
-
line: Feature<LineString> | LineString
|
|
11
|
-
): Feature<LineString>;
|
|
33
|
+
declare function lineSlice(startPt: Coord, stopPt: Coord, line: Feature<LineString> | LineString): Feature<LineString>;
|
|
12
34
|
|
|
13
35
|
export { lineSlice as default, lineSlice };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
|
-
import { Feature, LineString } from 'geojson';
|
|
2
1
|
import { Coord } from '@turf/helpers';
|
|
2
|
+
import { Feature, LineString } from 'geojson';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Takes a {@link LineString|line}, a start {@link Point}, and a stop point
|
|
6
|
+
* and returns a subsection of the line in-between those points.
|
|
7
|
+
* The start & stop points don't need to fall exactly on the line.
|
|
8
|
+
*
|
|
9
|
+
* This can be useful for extracting only the part of a route between waypoints.
|
|
10
|
+
*
|
|
11
|
+
* @function
|
|
12
|
+
* @param {Coord} startPt starting point
|
|
13
|
+
* @param {Coord} stopPt stopping point
|
|
14
|
+
* @param {Feature<LineString>|LineString} line line to slice
|
|
15
|
+
* @returns {Feature<LineString>} sliced line
|
|
16
|
+
* @example
|
|
17
|
+
* var line = turf.lineString([
|
|
18
|
+
* [-77.031669, 38.878605],
|
|
19
|
+
* [-77.029609, 38.881946],
|
|
20
|
+
* [-77.020339, 38.884084],
|
|
21
|
+
* [-77.025661, 38.885821],
|
|
22
|
+
* [-77.021884, 38.889563],
|
|
23
|
+
* [-77.019824, 38.892368]
|
|
24
|
+
* ]);
|
|
25
|
+
* var start = turf.point([-77.029609, 38.881946]);
|
|
26
|
+
* var stop = turf.point([-77.021884, 38.889563]);
|
|
27
|
+
*
|
|
28
|
+
* var sliced = turf.lineSlice(start, stop, line);
|
|
29
|
+
*
|
|
30
|
+
* //addToMap
|
|
31
|
+
* var addToMap = [start, stop, line]
|
|
6
32
|
*/
|
|
7
|
-
declare function lineSlice(
|
|
8
|
-
startPt: Coord,
|
|
9
|
-
stopPt: Coord,
|
|
10
|
-
line: Feature<LineString> | LineString
|
|
11
|
-
): Feature<LineString>;
|
|
33
|
+
declare function lineSlice(startPt: Coord, stopPt: Coord, line: Feature<LineString> | LineString): Feature<LineString>;
|
|
12
34
|
|
|
13
35
|
export { lineSlice as default, lineSlice };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
// index.
|
|
1
|
+
// index.ts
|
|
2
2
|
import { getCoords, getType } from "@turf/invariant";
|
|
3
3
|
import { lineString as linestring } from "@turf/helpers";
|
|
4
4
|
import { nearestPointOnLine } from "@turf/nearest-point-on-line";
|
|
5
5
|
function lineSlice(startPt, stopPt, line) {
|
|
6
|
-
|
|
6
|
+
const coords = getCoords(line);
|
|
7
7
|
if (getType(line) !== "LineString")
|
|
8
8
|
throw new Error("line must be a LineString");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} else {
|
|
15
|
-
ends = [stopVertex, startVertex];
|
|
16
|
-
}
|
|
17
|
-
var clipCoords = [ends[0].geometry.coordinates];
|
|
18
|
-
for (var i = ends[0].properties.index + 1; i < ends[1].properties.index + 1; i++) {
|
|
9
|
+
const startVertex = nearestPointOnLine(line, startPt);
|
|
10
|
+
const stopVertex = nearestPointOnLine(line, stopPt);
|
|
11
|
+
const ends = startVertex.properties.index <= stopVertex.properties.index ? [startVertex, stopVertex] : [stopVertex, startVertex];
|
|
12
|
+
const clipCoords = [ends[0].geometry.coordinates];
|
|
13
|
+
for (let i = ends[0].properties.index + 1; i < ends[1].properties.index + 1; i++) {
|
|
19
14
|
clipCoords.push(coords[i]);
|
|
20
15
|
}
|
|
21
16
|
clipCoords.push(ends[1].geometry.coordinates);
|
|
22
|
-
return linestring(clipCoords, line.properties);
|
|
17
|
+
return linestring(clipCoords, line.type === "Feature" ? line.properties : {});
|
|
23
18
|
}
|
|
24
19
|
var index_default = lineSlice;
|
|
25
20
|
export {
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { getCoords, getType } from \"@turf/invariant\";\nimport { Coord, lineString as linestring } from \"@turf/helpers\";\nimport { nearestPointOnLine } from \"@turf/nearest-point-on-line\";\nimport { Feature, LineString } from \"geojson\";\n\n/**\n * Takes a {@link LineString|line}, a start {@link Point}, and a stop point\n * and returns a subsection of the line in-between those points.\n * The start & stop points don't need to fall exactly on the line.\n *\n * This can be useful for extracting only the part of a route between waypoints.\n *\n * @function\n * @param {Coord} startPt starting point\n * @param {Coord} stopPt stopping point\n * @param {Feature<LineString>|LineString} line line to slice\n * @returns {Feature<LineString>} sliced line\n * @example\n * var line = turf.lineString([\n * [-77.031669, 38.878605],\n * [-77.029609, 38.881946],\n * [-77.020339, 38.884084],\n * [-77.025661, 38.885821],\n * [-77.021884, 38.889563],\n * [-77.019824, 38.892368]\n * ]);\n * var start = turf.point([-77.029609, 38.881946]);\n * var stop = turf.point([-77.021884, 38.889563]);\n *\n * var sliced = turf.lineSlice(start, stop, line);\n *\n * //addToMap\n * var addToMap = [start, stop, line]\n */\nfunction lineSlice(\n startPt: Coord,\n stopPt: Coord,\n line: Feature<LineString> | LineString\n): Feature<LineString> {\n // Validation\n const coords = getCoords(line);\n if (getType(line) !== \"LineString\")\n throw new Error(\"line must be a LineString\");\n\n const startVertex = nearestPointOnLine(line, startPt);\n const stopVertex = nearestPointOnLine(line, stopPt);\n const ends =\n startVertex.properties.index <= stopVertex.properties.index\n ? [startVertex, stopVertex]\n : [stopVertex, startVertex];\n const clipCoords = [ends[0].geometry.coordinates];\n for (\n let i = ends[0].properties.index + 1;\n i < ends[1].properties.index + 1;\n i++\n ) {\n clipCoords.push(coords[i]);\n }\n clipCoords.push(ends[1].geometry.coordinates);\n return linestring(clipCoords, line.type === \"Feature\" ? line.properties : {});\n}\n\nexport { lineSlice };\nexport default lineSlice;\n"],"mappings":";AAAA,SAAS,WAAW,eAAe;AACnC,SAAgB,cAAc,kBAAkB;AAChD,SAAS,0BAA0B;AAgCnC,SAAS,UACP,SACA,QACA,MACqB;AAErB,QAAM,SAAS,UAAU,IAAI;AAC7B,MAAI,QAAQ,IAAI,MAAM;AACpB,UAAM,IAAI,MAAM,2BAA2B;AAE7C,QAAM,cAAc,mBAAmB,MAAM,OAAO;AACpD,QAAM,aAAa,mBAAmB,MAAM,MAAM;AAClD,QAAM,OACJ,YAAY,WAAW,SAAS,WAAW,WAAW,QAClD,CAAC,aAAa,UAAU,IACxB,CAAC,YAAY,WAAW;AAC9B,QAAM,aAAa,CAAC,KAAK,CAAC,EAAE,SAAS,WAAW;AAChD,WACM,IAAI,KAAK,CAAC,EAAE,WAAW,QAAQ,GACnC,IAAI,KAAK,CAAC,EAAE,WAAW,QAAQ,GAC/B,KACA;AACA,eAAW,KAAK,OAAO,CAAC,CAAC;AAAA,EAC3B;AACA,aAAW,KAAK,KAAK,CAAC,EAAE,SAAS,WAAW;AAC5C,SAAO,WAAW,YAAY,KAAK,SAAS,YAAY,KAAK,aAAa,CAAC,CAAC;AAC9E;AAGA,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/line-slice",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.2",
|
|
4
4
|
"description": "Useful for extracting only the part of a route between waypoints.",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,26 +50,27 @@
|
|
|
50
50
|
"bench": "tsx bench.ts",
|
|
51
51
|
"build": "tsup --config ../../tsup.config.ts",
|
|
52
52
|
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
53
|
-
"test": "
|
|
53
|
+
"test": "pnpm run /test:.*/",
|
|
54
54
|
"test:tape": "tsx test.ts"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@turf/truncate": "7.3.
|
|
57
|
+
"@turf/truncate": "7.3.2",
|
|
58
58
|
"@types/benchmark": "^2.1.5",
|
|
59
59
|
"@types/tape": "^5.8.1",
|
|
60
60
|
"benchmark": "^2.1.4",
|
|
61
61
|
"load-json-file": "^7.0.1",
|
|
62
|
-
"npm-run-all": "^4.1.5",
|
|
63
62
|
"tape": "^5.9.0",
|
|
64
63
|
"tsup": "^8.4.0",
|
|
65
64
|
"tsx": "^4.19.4",
|
|
65
|
+
"typescript": "^5.8.3",
|
|
66
66
|
"write-json-file": "^6.0.0"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@turf/helpers": "7.3.
|
|
70
|
-
"@turf/invariant": "7.3.
|
|
71
|
-
"@turf/nearest-point-on-line": "7.3.
|
|
72
|
-
"@types/geojson": "^7946.0.10"
|
|
69
|
+
"@turf/helpers": "7.3.2",
|
|
70
|
+
"@turf/invariant": "7.3.2",
|
|
71
|
+
"@turf/nearest-point-on-line": "7.3.2",
|
|
72
|
+
"@types/geojson": "^7946.0.10",
|
|
73
|
+
"tslib": "^2.8.1"
|
|
73
74
|
},
|
|
74
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "099d9915467bacf45d554be4533fa9998c4efc88"
|
|
75
76
|
}
|