@turf/line-split 7.3.1 → 7.3.3
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 +45 -28
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +19 -9
- package/dist/esm/index.d.ts +19 -9
- package/dist/esm/index.js +46 -29
- package/dist/esm/index.js.map +1 -1
- package/package.json +14 -12
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
|
|
2
2
|
var _geojsonrbush = require('@turf/geojson-rbush');
|
|
3
3
|
var _truncate = require('@turf/truncate');
|
|
4
4
|
var _linesegment = require('@turf/line-segment');
|
|
@@ -10,56 +10,73 @@ var _helpers = require('@turf/helpers');
|
|
|
10
10
|
function lineSplit(line, splitter) {
|
|
11
11
|
if (!line) throw new Error("line is required");
|
|
12
12
|
if (!splitter) throw new Error("splitter is required");
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const lineType = _invariant.getType.call(void 0, line);
|
|
14
|
+
const splitterType = _invariant.getType.call(void 0, splitter);
|
|
15
15
|
if (lineType !== "LineString") throw new Error("line must be LineString");
|
|
16
16
|
if (splitterType === "FeatureCollection")
|
|
17
17
|
throw new Error("splitter cannot be a FeatureCollection");
|
|
18
18
|
if (splitterType === "GeometryCollection")
|
|
19
19
|
throw new Error("splitter cannot be a GeometryCollection");
|
|
20
20
|
var truncatedSplitter = _truncate.truncate.call(void 0, splitter, { precision: 7 });
|
|
21
|
+
if (line.type !== "Feature") {
|
|
22
|
+
line = _helpers.feature.call(void 0, line);
|
|
23
|
+
}
|
|
21
24
|
switch (splitterType) {
|
|
22
25
|
case "Point":
|
|
23
|
-
return splitLineWithPoint(
|
|
26
|
+
return splitLineWithPoint(
|
|
27
|
+
line,
|
|
28
|
+
truncatedSplitter
|
|
29
|
+
);
|
|
24
30
|
case "MultiPoint":
|
|
25
|
-
return splitLineWithPoints(
|
|
31
|
+
return splitLineWithPoints(
|
|
32
|
+
line,
|
|
33
|
+
truncatedSplitter
|
|
34
|
+
);
|
|
26
35
|
case "LineString":
|
|
27
36
|
case "MultiLineString":
|
|
28
37
|
case "Polygon":
|
|
29
38
|
case "MultiPolygon":
|
|
30
39
|
return splitLineWithPoints(
|
|
31
40
|
line,
|
|
32
|
-
_lineintersect.lineIntersect.call(void 0,
|
|
33
|
-
|
|
34
|
-
|
|
41
|
+
_lineintersect.lineIntersect.call(void 0,
|
|
42
|
+
line,
|
|
43
|
+
truncatedSplitter,
|
|
44
|
+
{
|
|
45
|
+
ignoreSelfIntersections: true
|
|
46
|
+
}
|
|
47
|
+
)
|
|
35
48
|
);
|
|
36
49
|
}
|
|
37
50
|
}
|
|
38
51
|
function splitLineWithPoints(line, splitter) {
|
|
39
52
|
var results = [];
|
|
40
53
|
var tree = _geojsonrbush.geojsonRbush.call(void 0, );
|
|
41
|
-
_meta.flattenEach.call(void 0,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
tree.
|
|
59
|
-
|
|
54
|
+
_meta.flattenEach.call(void 0,
|
|
55
|
+
splitter,
|
|
56
|
+
// this cast should be unnecessary (and is wrong, it could contain MultiPoints), but is a workaround for bad flattenEach typings
|
|
57
|
+
function(point) {
|
|
58
|
+
results.forEach(function(feature2, index) {
|
|
59
|
+
feature2.id = index;
|
|
60
|
+
});
|
|
61
|
+
if (!results.length) {
|
|
62
|
+
results = splitLineWithPoint(line, point).features;
|
|
63
|
+
tree.load(_helpers.featureCollection.call(void 0, results));
|
|
64
|
+
} else {
|
|
65
|
+
var search = tree.search(point);
|
|
66
|
+
if (search.features.length) {
|
|
67
|
+
var closestLine = findClosestFeature(point, search);
|
|
68
|
+
results = results.filter(function(feature2) {
|
|
69
|
+
return feature2.id !== closestLine.id;
|
|
70
|
+
});
|
|
71
|
+
tree.remove(closestLine);
|
|
72
|
+
_meta.featureEach.call(void 0, splitLineWithPoint(closestLine, point), function(line2) {
|
|
73
|
+
results.push(line2);
|
|
74
|
+
tree.insert(line2);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
60
77
|
}
|
|
61
78
|
}
|
|
62
|
-
|
|
79
|
+
);
|
|
63
80
|
return _helpers.featureCollection.call(void 0, results);
|
|
64
81
|
}
|
|
65
82
|
function splitLineWithPoint(line, splitter) {
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-line-split/dist/cjs/index.cjs","../../index.js"],"names":["line"],"mappings":"AAAA;ACAA,mDAAsC;AACtC,0CAAyB;AACzB,iDAA4B;AAC5B,qDAA8B;AAC9B,iEAAmC;AACnC,4CAA6C;AAC7C,kCAAwD;AACxD,wCAA8C;AAqB9C,SAAS,SAAA,CAAU,IAAA,EAAM,QAAA,EAAU;AACjC,EAAA,GAAA,CAAI,CAAC,IAAA,EAAM,MAAM,IAAI,KAAA,CAAM,kBAAkB,CAAA;AAC7C,EAAA,GAAA,CAAI,CAAC,QAAA,EAAU,MAAM,IAAI,KAAA,CAAM,sBAAsB,CAAA;AAErD,EAAA,IAAI,SAAA,EAAW,gCAAA,IAAY,CAAA;AAC3B,EAAA,IAAI,aAAA,EAAe,gCAAA,QAAgB,CAAA;AAEnC,EAAA,GAAA,CAAI,SAAA,IAAa,YAAA,EAAc,MAAM,IAAI,KAAA,CAAM,yBAAyB,CAAA;AACxE,EAAA,GAAA,CAAI,aAAA,IAAiB,mBAAA;AACnB,IAAA,MAAM,IAAI,KAAA,CAAM,wCAAwC,CAAA;AAC1D,EAAA,GA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S,kBAAA,CAAmB,KAAA,EAAO,KAAA,EAAO;AACxC,EAAA,GAAA,CAAI,CAAC,KAAA,CAAM,QAAA,CAAS,MAAA,EAAQ,MAAM,IAAI,KAAA,CAAM,6BAA6B,CAAA;AAEzE,EAAA,GAAA,CAAI,KAAA,CAAM,QAAA,CAAS,OAAA,IAAW,CAAA,EAAG,OAAO,KAAA,CAAM,QAAA,CAAS,CAAC,CAAA;AAExD,EAAA,IAAI,cAAA;AACJ,EAAA,IAAI,gBAAA,EAAkB,QAAA;AACtB,EAAA,+BAAA,KAAY,EAAO,QAAA,CAAU,OAAA,EAAS;AACpC,IAAA,IAAI,GAAA,EAAK,oDAAA,OAAmB,EAAS,KAAK,CAAA;AAC1C,IAAA,IAAI,KAAA,EAAO,EAAA,CAAG,UAAA,CAAW,IAAA;AACzB,IAAA,GAAA,CAAI,KAAA,EAAO,eAAA,EAAiB;AAC1B,MAAA,eAAA,EAAiB,OAAA;AACjB,MAAA,gBAAA,EAAkB,IAAA;AAAA,IACpB;AAAA,EACF,CAAC,CAAA;AACD,EAAA,OAAO,cAAA;AACT;AAUA,SAAS,YAAA,CAAa,GAAA,EAAK,GAAA,EAAK;AAC9B,EAAA,OAAO,GAAA,CAAI,CAAC,EAAA,IAAM,GAAA,CAAI,CAAC,EAAA,GAAK,GAAA,CAAI,CAAC,EAAA,IAAM,GAAA,CAAI,CAAC,CAAA;AAC9C;AAGA,IAAO,cAAA,EAAQ,SAAA;ADjGf;AACE;AACA;AACF,+DAAC","file":"/home/runner/work/turf/turf/packages/turf-line-split/dist/cjs/index.cjs","sourcesContent":[null,"import { geojsonRbush as rbush } from \"@turf/geojson-rbush\";\nimport { truncate } from \"@turf/truncate\";\nimport { lineSegment } from \"@turf/line-segment\";\nimport { lineIntersect } from \"@turf/line-intersect\";\nimport { nearestPointOnLine } from \"@turf/nearest-point-on-line\";\nimport { getCoords, getCoord, getType } from \"@turf/invariant\";\nimport { featureEach, featureReduce, flattenEach } from \"@turf/meta\";\nimport { lineString, featureCollection } from \"@turf/helpers\";\n\n/**\n * Split a LineString by another GeoJSON Feature.\n *\n * @function\n * @param {Feature<LineString>} line LineString Feature to split\n * @param {Feature<any>} splitter Feature used to split line\n * @returns {FeatureCollection<LineString>} Split LineStrings\n * @example\n * var line = turf.lineString([[120, -25], [145, -25]]);\n * var splitter = turf.lineString([[130, -15], [130, -35]]);\n *\n * var split = turf.lineSplit(line, splitter);\n *\n * //addToMap\n * var addToMap = [line, splitter, split]\n *\n * split.features[0].properties.stroke = \"red\";\n * split.features[1].properties.stroke = \"blue\";\n */\nfunction lineSplit(line, splitter) {\n if (!line) throw new Error(\"line is required\");\n if (!splitter) throw new Error(\"splitter is required\");\n\n var lineType = getType(line);\n var splitterType = getType(splitter);\n\n if (lineType !== \"LineString\") throw new Error(\"line must be LineString\");\n if (splitterType === \"FeatureCollection\")\n throw new Error(\"splitter cannot be a FeatureCollection\");\n if (splitterType === \"GeometryCollection\")\n throw new Error(\"splitter cannot be a GeometryCollection\");\n\n // remove excessive decimals from splitter\n // to avoid possible approximation issues in rbush\n var truncatedSplitter = truncate(splitter, { precision: 7 });\n\n switch (splitterType) {\n case \"Point\":\n return splitLineWithPoint(line, truncatedSplitter);\n case \"MultiPoint\":\n return splitLineWithPoints(line, truncatedSplitter);\n case \"LineString\":\n case \"MultiLineString\":\n case \"Polygon\":\n case \"MultiPolygon\":\n return splitLineWithPoints(\n line,\n lineIntersect(line, truncatedSplitter, {\n ignoreSelfIntersections: true,\n })\n );\n }\n}\n\n/**\n * Split LineString with MultiPoint\n *\n * @private\n * @param {Feature<LineString>} line LineString\n * @param {FeatureCollection<Point>} splitter Point\n * @returns {FeatureCollection<LineString>} split LineStrings\n */\nfunction splitLineWithPoints(line, splitter) {\n var results = [];\n var tree = rbush();\n\n flattenEach(splitter, function (point) {\n // Add index/id to features (needed for filter)\n results.forEach(function (feature, index) {\n feature.id = index;\n });\n // First Point - doesn't need to handle any previous line results\n if (!results.length) {\n results = splitLineWithPoint(line, point).features;\n tree.load(featureCollection(results));\n // Split with remaining points - lines might needed to be split multiple times\n } else {\n // Find all lines that are within the splitter's bbox\n var search = tree.search(point);\n\n if (search.features.length) {\n // RBush might return multiple lines - only process the closest line to splitter\n var closestLine = findClosestFeature(point, search);\n\n // Remove closest line from results since this will be split into two lines\n // This removes any duplicates inside the results & index\n results = results.filter(function (feature) {\n return feature.id !== closestLine.id;\n });\n tree.remove(closestLine);\n\n // Append the two newly split lines into the results\n featureEach(splitLineWithPoint(closestLine, point), function (line) {\n results.push(line);\n tree.insert(line);\n });\n }\n }\n });\n return featureCollection(results);\n}\n\n/**\n * Split LineString with Point\n *\n * @private\n * @param {Feature<LineString>} line LineString\n * @param {Feature<Point>} splitter Point\n * @returns {FeatureCollection<LineString>} split LineStrings\n */\nfunction splitLineWithPoint(line, splitter) {\n var results = [];\n\n // handle endpoints\n var startPoint = getCoords(line)[0];\n var endPoint = getCoords(line)[line.geometry.coordinates.length - 1];\n if (\n pointsEquals(startPoint, getCoord(splitter)) ||\n pointsEquals(endPoint, getCoord(splitter))\n )\n return featureCollection([line]);\n\n // Create spatial index\n var tree = rbush();\n var segments = lineSegment(line);\n tree.load(segments);\n\n // Find all segments that are within bbox of splitter\n var search = tree.search(splitter);\n\n // Return itself if point is not within spatial index\n if (!search.features.length) return featureCollection([line]);\n\n // RBush might return multiple lines - only process the closest line to splitter\n var closestSegment = findClosestFeature(splitter, search);\n\n // Initial value is the first point of the first segments (beginning of line)\n var initialValue = [startPoint];\n var lastCoords = featureReduce(\n segments,\n function (previous, current, index) {\n var currentCoords = getCoords(current)[1];\n var splitterCoords = getCoord(splitter);\n\n // Location where segment intersects with line\n if (index === closestSegment.id) {\n previous.push(splitterCoords);\n results.push(lineString(previous));\n // Don't duplicate splitter coordinate (Issue #688)\n if (pointsEquals(splitterCoords, currentCoords))\n return [splitterCoords];\n return [splitterCoords, currentCoords];\n\n // Keep iterating over coords until finished or intersection is found\n } else {\n previous.push(currentCoords);\n return previous;\n }\n },\n initialValue\n );\n // Append last line to final split results\n if (lastCoords.length > 1) {\n results.push(lineString(lastCoords));\n }\n return featureCollection(results);\n}\n\n/**\n * Find Closest Feature\n *\n * @private\n * @param {Feature<Point>} point Feature must be closest to this point\n * @param {FeatureCollection<LineString>} lines Collection of Features\n * @returns {Feature<LineString>} closest LineString\n */\nfunction findClosestFeature(point, lines) {\n if (!lines.features.length) throw new Error(\"lines must contain features\");\n // Filter to one segment that is the closest to the line\n if (lines.features.length === 1) return lines.features[0];\n\n var closestFeature;\n var closestDistance = Infinity;\n featureEach(lines, function (segment) {\n var pt = nearestPointOnLine(segment, point);\n var dist = pt.properties.dist;\n if (dist < closestDistance) {\n closestFeature = segment;\n closestDistance = dist;\n }\n });\n return closestFeature;\n}\n\n/**\n * Compares two points and returns if they are equals\n *\n * @private\n * @param {Array<number>} pt1 point\n * @param {Array<number>} pt2 point\n * @returns {boolean} true if they are equals\n */\nfunction pointsEquals(pt1, pt2) {\n return pt1[0] === pt2[0] && pt1[1] === pt2[1];\n}\n\nexport { lineSplit };\nexport default lineSplit;\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-line-split/dist/cjs/index.cjs","../../index.ts"],"names":["feature","line"],"mappings":"AAAA;ACAA,mDAAsC;AACtC,0CAAyB;AACzB,iDAA4B;AAC5B,qDAA8B;AAC9B,iEAAmC;AACnC,4CAA6C;AAC7C,kCAAwD;AACxD,wCAAuD;AAoCvD,SAAS,SAAA,CACP,IAAA,EACA,QAAA,EACsB;AACtB,EAAA,GAAA,CAAI,CAAC,IAAA,EAAM,MAAM,IAAI,KAAA,CAAM,kBAAkB,CAAA;AAC7C,EAAA,GAAA,CAAI,CAAC,QAAA,EAAU,MAAM,IAAI,KAAA,CAAM,sBAAsB,CAAA;AAErD,EAAA,MAAM,SAAA,EAAW,gCAAA,IAAY,CAAA;AAC7B,EAAA,MAAM,aAAA,EAAe,gCAAA,QAAgB,CAAA;AAErC,EAAA,GAAA,CAAI,SAAA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AO,cAAA,EAAQ,SAAA;AD/Hf;AACE;AACA;AACF,+DAAC","file":"/home/runner/work/turf/turf/packages/turf-line-split/dist/cjs/index.cjs","sourcesContent":[null,"import { geojsonRbush as rbush } from \"@turf/geojson-rbush\";\nimport { truncate } from \"@turf/truncate\";\nimport { lineSegment } from \"@turf/line-segment\";\nimport { lineIntersect } from \"@turf/line-intersect\";\nimport { nearestPointOnLine } from \"@turf/nearest-point-on-line\";\nimport { getCoords, getCoord, getType } from \"@turf/invariant\";\nimport { featureEach, featureReduce, flattenEach } from \"@turf/meta\";\nimport { lineString, featureCollection, feature } from \"@turf/helpers\";\nimport {\n Feature,\n FeatureCollection,\n GeoJsonTypes,\n LineString,\n MultiLineString,\n MultiPoint,\n MultiPolygon,\n Point,\n Polygon,\n} from \"geojson\";\n\ntype Splitter = Feature<\n Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon\n>;\n\n/**\n * Split a LineString by another GeoJSON Feature.\n *\n * @function\n * @param {Feature<LineString>} line LineString Feature to split\n * @param {Feature<any>} splitter Feature used to split line\n * @returns {FeatureCollection<LineString>} Split LineStrings\n * @example\n * var line = turf.lineString([[120, -25], [145, -25]]);\n * var splitter = turf.lineString([[130, -15], [130, -35]]);\n *\n * var split = turf.lineSplit(line, splitter);\n *\n * //addToMap\n * var addToMap = [line, splitter, split]\n *\n * split.features[0].properties.stroke = \"red\";\n * split.features[1].properties.stroke = \"blue\";\n */\nfunction lineSplit<T extends LineString>(\n line: Feature<T> | T,\n splitter: Splitter\n): FeatureCollection<T> {\n if (!line) throw new Error(\"line is required\");\n if (!splitter) throw new Error(\"splitter is required\");\n\n const lineType = getType(line) as Exclude<GeoJsonTypes, \"Feature\">;\n const splitterType = getType(splitter) as Exclude<GeoJsonTypes, \"Feature\">;\n\n if (lineType !== \"LineString\") throw new Error(\"line must be LineString\");\n if (splitterType === \"FeatureCollection\")\n throw new Error(\"splitter cannot be a FeatureCollection\");\n if (splitterType === \"GeometryCollection\")\n throw new Error(\"splitter cannot be a GeometryCollection\");\n\n // remove excessive decimals from splitter\n // to avoid possible approximation issues in rbush\n var truncatedSplitter = truncate(splitter, { precision: 7 });\n\n // Ensure we're consistently sending Feature<LineString> into the splitLine methods.\n if (line.type !== \"Feature\") {\n line = feature(line);\n }\n\n switch (splitterType) {\n case \"Point\":\n return splitLineWithPoint(\n line as Feature<LineString>,\n truncatedSplitter as Feature<Point>\n ) as FeatureCollection<T>;\n case \"MultiPoint\":\n return splitLineWithPoints(\n line as Feature<LineString>,\n truncatedSplitter as Feature<MultiPoint>\n ) as FeatureCollection<T>;\n case \"LineString\":\n case \"MultiLineString\":\n case \"Polygon\":\n case \"MultiPolygon\":\n return splitLineWithPoints(\n line as Feature<LineString>,\n lineIntersect(\n line,\n truncatedSplitter as Feature<\n LineString | MultiLineString | Polygon | MultiPolygon\n >,\n {\n ignoreSelfIntersections: true,\n }\n )\n ) as FeatureCollection<T>;\n }\n}\n\n/**\n * Split LineString with MultiPoint\n *\n * @private\n * @param {Feature<LineString>} line LineString\n * @param {FeatureCollection<Point>} splitter Point\n * @returns {FeatureCollection<LineString>} split LineStrings\n */\nfunction splitLineWithPoints(\n line: Feature<LineString>,\n splitter: FeatureCollection<Point> | Feature<MultiPoint>\n) {\n var results: Feature<LineString>[] = [];\n var tree = rbush<LineString>();\n\n flattenEach(\n splitter as FeatureCollection<Point>, // this cast should be unnecessary (and is wrong, it could contain MultiPoints), but is a workaround for bad flattenEach typings\n function (point: Feature<Point>) {\n // Add index/id to features (needed for filter)\n results.forEach(function (feature, index) {\n feature.id = index;\n });\n // First Point - doesn't need to handle any previous line results\n if (!results.length) {\n results = splitLineWithPoint(line, point).features;\n tree.load(featureCollection(results));\n // Split with remaining points - lines might needed to be split multiple times\n } else {\n // Find all lines that are within the splitter's bbox\n var search = tree.search(point);\n\n if (search.features.length) {\n // RBush might return multiple lines - only process the closest line to splitter\n var closestLine = findClosestFeature(point, search);\n\n // Remove closest line from results since this will be split into two lines\n // This removes any duplicates inside the results & index\n results = results.filter(function (feature) {\n return feature.id !== closestLine.id;\n });\n tree.remove(closestLine);\n\n // Append the two newly split lines into the results\n featureEach(splitLineWithPoint(closestLine, point), function (line) {\n results.push(line);\n tree.insert(line);\n });\n }\n }\n }\n );\n return featureCollection(results);\n}\n\n/**\n * Split LineString with Point\n *\n * @private\n * @param {Feature<LineString>} line LineString\n * @param {Feature<Point>} splitter Point\n * @returns {FeatureCollection<LineString>} split LineStrings\n */\nfunction splitLineWithPoint(\n line: Feature<LineString>,\n splitter: Feature<Point>\n) {\n var results = [];\n\n // handle endpoints\n var startPoint = getCoords(line)[0];\n var endPoint = getCoords(line)[line.geometry.coordinates.length - 1];\n if (\n pointsEquals(startPoint, getCoord(splitter)) ||\n pointsEquals(endPoint, getCoord(splitter))\n )\n return featureCollection([line]);\n\n // Create spatial index\n var tree = rbush<LineString>();\n var segments = lineSegment(line);\n tree.load(segments);\n\n // Find all segments that are within bbox of splitter\n var search = tree.search(splitter);\n\n // Return itself if point is not within spatial index\n if (!search.features.length) return featureCollection([line]);\n\n // RBush might return multiple lines - only process the closest line to splitter\n var closestSegment = findClosestFeature(splitter, search);\n\n // Initial value is the first point of the first segments (beginning of line)\n var initialValue = [startPoint];\n var lastCoords = featureReduce(\n segments,\n function (previous, current, index) {\n var currentCoords = getCoords(current)[1];\n var splitterCoords = getCoord(splitter);\n\n // Location where segment intersects with line\n if (index === closestSegment.id) {\n previous.push(splitterCoords);\n results.push(lineString(previous));\n // Don't duplicate splitter coordinate (Issue #688)\n if (pointsEquals(splitterCoords, currentCoords))\n return [splitterCoords];\n return [splitterCoords, currentCoords];\n\n // Keep iterating over coords until finished or intersection is found\n } else {\n previous.push(currentCoords);\n return previous;\n }\n },\n initialValue\n );\n // Append last line to final split results\n if (lastCoords.length > 1) {\n results.push(lineString(lastCoords));\n }\n return featureCollection(results);\n}\n\n/**\n * Find Closest Feature\n *\n * @private\n * @param {Feature<Point>} point Feature must be closest to this point\n * @param {FeatureCollection<LineString>} lines Collection of Features\n * @returns {Feature<LineString>} closest LineString\n */\nfunction findClosestFeature(\n point: Feature<Point>,\n lines: FeatureCollection<LineString>\n): Feature<LineString> {\n if (!lines.features.length) throw new Error(\"lines must contain features\");\n // Filter to one segment that is the closest to the line\n if (lines.features.length === 1) return lines.features[0];\n\n var closestFeature;\n var closestDistance = Infinity;\n featureEach(lines, function (segment) {\n var pt = nearestPointOnLine(segment, point);\n var dist = pt.properties.dist;\n if (dist < closestDistance) {\n closestFeature = segment;\n closestDistance = dist;\n }\n });\n return closestFeature!;\n}\n\n/**\n * Compares two points and returns if they are equals\n *\n * @private\n * @param {Array<number>} pt1 point\n * @param {Array<number>} pt2 point\n * @returns {boolean} true if they are equals\n */\nfunction pointsEquals(pt1: number[], pt2: number[]) {\n return pt1[0] === pt2[0] && pt1[1] === pt2[1];\n}\n\nexport { Splitter, lineSplit };\nexport default lineSplit;\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import { Feature, Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, FeatureCollection } from 'geojson';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon
|
|
5
|
-
>;
|
|
6
|
-
|
|
3
|
+
type Splitter = Feature<Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon>;
|
|
7
4
|
/**
|
|
8
|
-
*
|
|
5
|
+
* Split a LineString by another GeoJSON Feature.
|
|
6
|
+
*
|
|
7
|
+
* @function
|
|
8
|
+
* @param {Feature<LineString>} line LineString Feature to split
|
|
9
|
+
* @param {Feature<any>} splitter Feature used to split line
|
|
10
|
+
* @returns {FeatureCollection<LineString>} Split LineStrings
|
|
11
|
+
* @example
|
|
12
|
+
* var line = turf.lineString([[120, -25], [145, -25]]);
|
|
13
|
+
* var splitter = turf.lineString([[130, -15], [130, -35]]);
|
|
14
|
+
*
|
|
15
|
+
* var split = turf.lineSplit(line, splitter);
|
|
16
|
+
*
|
|
17
|
+
* //addToMap
|
|
18
|
+
* var addToMap = [line, splitter, split]
|
|
19
|
+
*
|
|
20
|
+
* split.features[0].properties.stroke = "red";
|
|
21
|
+
* split.features[1].properties.stroke = "blue";
|
|
9
22
|
*/
|
|
10
|
-
declare function lineSplit<T extends LineString>(
|
|
11
|
-
line: Feature<T> | T,
|
|
12
|
-
splitter: Splitter
|
|
13
|
-
): FeatureCollection<T>;
|
|
23
|
+
declare function lineSplit<T extends LineString>(line: Feature<T> | T, splitter: Splitter): FeatureCollection<T>;
|
|
14
24
|
|
|
15
25
|
export { type Splitter, lineSplit as default, lineSplit };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import { Feature, Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, FeatureCollection } from 'geojson';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon
|
|
5
|
-
>;
|
|
6
|
-
|
|
3
|
+
type Splitter = Feature<Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon>;
|
|
7
4
|
/**
|
|
8
|
-
*
|
|
5
|
+
* Split a LineString by another GeoJSON Feature.
|
|
6
|
+
*
|
|
7
|
+
* @function
|
|
8
|
+
* @param {Feature<LineString>} line LineString Feature to split
|
|
9
|
+
* @param {Feature<any>} splitter Feature used to split line
|
|
10
|
+
* @returns {FeatureCollection<LineString>} Split LineStrings
|
|
11
|
+
* @example
|
|
12
|
+
* var line = turf.lineString([[120, -25], [145, -25]]);
|
|
13
|
+
* var splitter = turf.lineString([[130, -15], [130, -35]]);
|
|
14
|
+
*
|
|
15
|
+
* var split = turf.lineSplit(line, splitter);
|
|
16
|
+
*
|
|
17
|
+
* //addToMap
|
|
18
|
+
* var addToMap = [line, splitter, split]
|
|
19
|
+
*
|
|
20
|
+
* split.features[0].properties.stroke = "red";
|
|
21
|
+
* split.features[1].properties.stroke = "blue";
|
|
9
22
|
*/
|
|
10
|
-
declare function lineSplit<T extends LineString>(
|
|
11
|
-
line: Feature<T> | T,
|
|
12
|
-
splitter: Splitter
|
|
13
|
-
): FeatureCollection<T>;
|
|
23
|
+
declare function lineSplit<T extends LineString>(line: Feature<T> | T, splitter: Splitter): FeatureCollection<T>;
|
|
14
24
|
|
|
15
25
|
export { type Splitter, lineSplit as default, lineSplit };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// index.
|
|
1
|
+
// index.ts
|
|
2
2
|
import { geojsonRbush as rbush } from "@turf/geojson-rbush";
|
|
3
3
|
import { truncate } from "@turf/truncate";
|
|
4
4
|
import { lineSegment } from "@turf/line-segment";
|
|
@@ -6,60 +6,77 @@ import { lineIntersect } from "@turf/line-intersect";
|
|
|
6
6
|
import { nearestPointOnLine } from "@turf/nearest-point-on-line";
|
|
7
7
|
import { getCoords, getCoord, getType } from "@turf/invariant";
|
|
8
8
|
import { featureEach, featureReduce, flattenEach } from "@turf/meta";
|
|
9
|
-
import { lineString, featureCollection } from "@turf/helpers";
|
|
9
|
+
import { lineString, featureCollection, feature } from "@turf/helpers";
|
|
10
10
|
function lineSplit(line, splitter) {
|
|
11
11
|
if (!line) throw new Error("line is required");
|
|
12
12
|
if (!splitter) throw new Error("splitter is required");
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const lineType = getType(line);
|
|
14
|
+
const splitterType = getType(splitter);
|
|
15
15
|
if (lineType !== "LineString") throw new Error("line must be LineString");
|
|
16
16
|
if (splitterType === "FeatureCollection")
|
|
17
17
|
throw new Error("splitter cannot be a FeatureCollection");
|
|
18
18
|
if (splitterType === "GeometryCollection")
|
|
19
19
|
throw new Error("splitter cannot be a GeometryCollection");
|
|
20
20
|
var truncatedSplitter = truncate(splitter, { precision: 7 });
|
|
21
|
+
if (line.type !== "Feature") {
|
|
22
|
+
line = feature(line);
|
|
23
|
+
}
|
|
21
24
|
switch (splitterType) {
|
|
22
25
|
case "Point":
|
|
23
|
-
return splitLineWithPoint(
|
|
26
|
+
return splitLineWithPoint(
|
|
27
|
+
line,
|
|
28
|
+
truncatedSplitter
|
|
29
|
+
);
|
|
24
30
|
case "MultiPoint":
|
|
25
|
-
return splitLineWithPoints(
|
|
31
|
+
return splitLineWithPoints(
|
|
32
|
+
line,
|
|
33
|
+
truncatedSplitter
|
|
34
|
+
);
|
|
26
35
|
case "LineString":
|
|
27
36
|
case "MultiLineString":
|
|
28
37
|
case "Polygon":
|
|
29
38
|
case "MultiPolygon":
|
|
30
39
|
return splitLineWithPoints(
|
|
31
40
|
line,
|
|
32
|
-
lineIntersect(
|
|
33
|
-
|
|
34
|
-
|
|
41
|
+
lineIntersect(
|
|
42
|
+
line,
|
|
43
|
+
truncatedSplitter,
|
|
44
|
+
{
|
|
45
|
+
ignoreSelfIntersections: true
|
|
46
|
+
}
|
|
47
|
+
)
|
|
35
48
|
);
|
|
36
49
|
}
|
|
37
50
|
}
|
|
38
51
|
function splitLineWithPoints(line, splitter) {
|
|
39
52
|
var results = [];
|
|
40
53
|
var tree = rbush();
|
|
41
|
-
flattenEach(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
tree.
|
|
59
|
-
|
|
54
|
+
flattenEach(
|
|
55
|
+
splitter,
|
|
56
|
+
// this cast should be unnecessary (and is wrong, it could contain MultiPoints), but is a workaround for bad flattenEach typings
|
|
57
|
+
function(point) {
|
|
58
|
+
results.forEach(function(feature2, index) {
|
|
59
|
+
feature2.id = index;
|
|
60
|
+
});
|
|
61
|
+
if (!results.length) {
|
|
62
|
+
results = splitLineWithPoint(line, point).features;
|
|
63
|
+
tree.load(featureCollection(results));
|
|
64
|
+
} else {
|
|
65
|
+
var search = tree.search(point);
|
|
66
|
+
if (search.features.length) {
|
|
67
|
+
var closestLine = findClosestFeature(point, search);
|
|
68
|
+
results = results.filter(function(feature2) {
|
|
69
|
+
return feature2.id !== closestLine.id;
|
|
70
|
+
});
|
|
71
|
+
tree.remove(closestLine);
|
|
72
|
+
featureEach(splitLineWithPoint(closestLine, point), function(line2) {
|
|
73
|
+
results.push(line2);
|
|
74
|
+
tree.insert(line2);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
60
77
|
}
|
|
61
78
|
}
|
|
62
|
-
|
|
79
|
+
);
|
|
63
80
|
return featureCollection(results);
|
|
64
81
|
}
|
|
65
82
|
function splitLineWithPoint(line, splitter) {
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.js"],"sourcesContent":["import { geojsonRbush as rbush } from \"@turf/geojson-rbush\";\nimport { truncate } from \"@turf/truncate\";\nimport { lineSegment } from \"@turf/line-segment\";\nimport { lineIntersect } from \"@turf/line-intersect\";\nimport { nearestPointOnLine } from \"@turf/nearest-point-on-line\";\nimport { getCoords, getCoord, getType } from \"@turf/invariant\";\nimport { featureEach, featureReduce, flattenEach } from \"@turf/meta\";\nimport { lineString, featureCollection } from \"@turf/helpers\";\n\n/**\n * Split a LineString by another GeoJSON Feature.\n *\n * @function\n * @param {Feature<LineString>} line LineString Feature to split\n * @param {Feature<any>} splitter Feature used to split line\n * @returns {FeatureCollection<LineString>} Split LineStrings\n * @example\n * var line = turf.lineString([[120, -25], [145, -25]]);\n * var splitter = turf.lineString([[130, -15], [130, -35]]);\n *\n * var split = turf.lineSplit(line, splitter);\n *\n * //addToMap\n * var addToMap = [line, splitter, split]\n *\n * split.features[0].properties.stroke = \"red\";\n * split.features[1].properties.stroke = \"blue\";\n */\nfunction lineSplit(line, splitter) {\n if (!line) throw new Error(\"line is required\");\n if (!splitter) throw new Error(\"splitter is required\");\n\n var lineType = getType(line);\n var splitterType = getType(splitter);\n\n if (lineType !== \"LineString\") throw new Error(\"line must be LineString\");\n if (splitterType === \"FeatureCollection\")\n throw new Error(\"splitter cannot be a FeatureCollection\");\n if (splitterType === \"GeometryCollection\")\n throw new Error(\"splitter cannot be a GeometryCollection\");\n\n // remove excessive decimals from splitter\n // to avoid possible approximation issues in rbush\n var truncatedSplitter = truncate(splitter, { precision: 7 });\n\n switch (splitterType) {\n case \"Point\":\n return splitLineWithPoint(line, truncatedSplitter);\n case \"MultiPoint\":\n return splitLineWithPoints(line, truncatedSplitter);\n case \"LineString\":\n case \"MultiLineString\":\n case \"Polygon\":\n case \"MultiPolygon\":\n return splitLineWithPoints(\n line,\n lineIntersect(line, truncatedSplitter, {\n ignoreSelfIntersections: true,\n })\n );\n }\n}\n\n/**\n * Split LineString with MultiPoint\n *\n * @private\n * @param {Feature<LineString>} line LineString\n * @param {FeatureCollection<Point>} splitter Point\n * @returns {FeatureCollection<LineString>} split LineStrings\n */\nfunction splitLineWithPoints(line, splitter) {\n var results = [];\n var tree = rbush();\n\n flattenEach(splitter, function (point) {\n // Add index/id to features (needed for filter)\n results.forEach(function (feature, index) {\n feature.id = index;\n });\n // First Point - doesn't need to handle any previous line results\n if (!results.length) {\n results = splitLineWithPoint(line, point).features;\n tree.load(featureCollection(results));\n // Split with remaining points - lines might needed to be split multiple times\n } else {\n // Find all lines that are within the splitter's bbox\n var search = tree.search(point);\n\n if (search.features.length) {\n // RBush might return multiple lines - only process the closest line to splitter\n var closestLine = findClosestFeature(point, search);\n\n // Remove closest line from results since this will be split into two lines\n // This removes any duplicates inside the results & index\n results = results.filter(function (feature) {\n return feature.id !== closestLine.id;\n });\n tree.remove(closestLine);\n\n // Append the two newly split lines into the results\n featureEach(splitLineWithPoint(closestLine, point), function (line) {\n results.push(line);\n tree.insert(line);\n });\n }\n }\n });\n return featureCollection(results);\n}\n\n/**\n * Split LineString with Point\n *\n * @private\n * @param {Feature<LineString>} line LineString\n * @param {Feature<Point>} splitter Point\n * @returns {FeatureCollection<LineString>} split LineStrings\n */\nfunction splitLineWithPoint(line, splitter) {\n var results = [];\n\n // handle endpoints\n var startPoint = getCoords(line)[0];\n var endPoint = getCoords(line)[line.geometry.coordinates.length - 1];\n if (\n pointsEquals(startPoint, getCoord(splitter)) ||\n pointsEquals(endPoint, getCoord(splitter))\n )\n return featureCollection([line]);\n\n // Create spatial index\n var tree = rbush();\n var segments = lineSegment(line);\n tree.load(segments);\n\n // Find all segments that are within bbox of splitter\n var search = tree.search(splitter);\n\n // Return itself if point is not within spatial index\n if (!search.features.length) return featureCollection([line]);\n\n // RBush might return multiple lines - only process the closest line to splitter\n var closestSegment = findClosestFeature(splitter, search);\n\n // Initial value is the first point of the first segments (beginning of line)\n var initialValue = [startPoint];\n var lastCoords = featureReduce(\n segments,\n function (previous, current, index) {\n var currentCoords = getCoords(current)[1];\n var splitterCoords = getCoord(splitter);\n\n // Location where segment intersects with line\n if (index === closestSegment.id) {\n previous.push(splitterCoords);\n results.push(lineString(previous));\n // Don't duplicate splitter coordinate (Issue #688)\n if (pointsEquals(splitterCoords, currentCoords))\n return [splitterCoords];\n return [splitterCoords, currentCoords];\n\n // Keep iterating over coords until finished or intersection is found\n } else {\n previous.push(currentCoords);\n return previous;\n }\n },\n initialValue\n );\n // Append last line to final split results\n if (lastCoords.length > 1) {\n results.push(lineString(lastCoords));\n }\n return featureCollection(results);\n}\n\n/**\n * Find Closest Feature\n *\n * @private\n * @param {Feature<Point>} point Feature must be closest to this point\n * @param {FeatureCollection<LineString>} lines Collection of Features\n * @returns {Feature<LineString>} closest LineString\n */\nfunction findClosestFeature(point, lines) {\n if (!lines.features.length) throw new Error(\"lines must contain features\");\n // Filter to one segment that is the closest to the line\n if (lines.features.length === 1) return lines.features[0];\n\n var closestFeature;\n var closestDistance = Infinity;\n featureEach(lines, function (segment) {\n var pt = nearestPointOnLine(segment, point);\n var dist = pt.properties.dist;\n if (dist < closestDistance) {\n closestFeature = segment;\n closestDistance = dist;\n }\n });\n return closestFeature;\n}\n\n/**\n * Compares two points and returns if they are equals\n *\n * @private\n * @param {Array<number>} pt1 point\n * @param {Array<number>} pt2 point\n * @returns {boolean} true if they are equals\n */\nfunction pointsEquals(pt1, pt2) {\n return pt1[0] === pt2[0] && pt1[1] === pt2[1];\n}\n\nexport { lineSplit };\nexport default lineSplit;\n"],"mappings":";AAAA,SAAS,gBAAgB,aAAa;AACtC,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AACnC,SAAS,WAAW,UAAU,eAAe;AAC7C,SAAS,aAAa,eAAe,mBAAmB;AACxD,SAAS,YAAY,yBAAyB;AAqB9C,SAAS,UAAU,MAAM,UAAU;AACjC,MAAI,CAAC,KAAM,OAAM,IAAI,MAAM,kBAAkB;AAC7C,MAAI,CAAC,SAAU,OAAM,IAAI,MAAM,sBAAsB;AAErD,MAAI,WAAW,QAAQ,IAAI;AAC3B,MAAI,eAAe,QAAQ,QAAQ;AAEnC,MAAI,aAAa,aAAc,OAAM,IAAI,MAAM,yBAAyB;AACxE,MAAI,iBAAiB;AACnB,UAAM,IAAI,MAAM,wCAAwC;AAC1D,MAAI,iBAAiB;AACnB,UAAM,IAAI,MAAM,yCAAyC;AAI3D,MAAI,oBAAoB,SAAS,UAAU,EAAE,WAAW,EAAE,CAAC;AAE3D,UAAQ,cAAc;AAAA,IACpB,KAAK;AACH,aAAO,mBAAmB,MAAM,iBAAiB;AAAA,IACnD,KAAK;AACH,aAAO,oBAAoB,MAAM,iBAAiB;AAAA,IACpD,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,QACL;AAAA,QACA,cAAc,MAAM,mBAAmB;AAAA,UACrC,yBAAyB;AAAA,QAC3B,CAAC;AAAA,MACH;AAAA,EACJ;AACF;AAUA,SAAS,oBAAoB,MAAM,UAAU;AAC3C,MAAI,UAAU,CAAC;AACf,MAAI,OAAO,MAAM;AAEjB,cAAY,UAAU,SAAU,OAA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S,OAAO;AAClC,UAAI,gBAAgB,UAAU,OAAO,EAAE,CAAC;AACxC,UAAI,iBAAiB,SAAS,QAAQ;AAGtC,UAAI,UAAU,eAAe,IAAI;AAC/B,iBAAS,KAAK,cAAc;AAC5B,gBAAQ,KAAK,WAAW,QAAQ,CAAC;AAEjC,YAAI,aAAa,gBAAgB,aAAa;AAC5C,iBAAO,CAAC,cAAc;AACxB,eAAO,CAAC,gBAAgB,aAAa;AAAA,MAGvC,OAAO;AACL,iBAAS,KAAK,aAAa;AAC3B,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA;AAAA,EACF;AAEA,MAAI,WAAW,SAAS,GAAG;AACzB,YAAQ,KAAK,WAAW,UAAU,CAAC;AAAA,EACrC;AACA,SAAO,kBAAkB,OAAO;AAClC;AAUA,SAAS,mBAAmB,OAAO,OAAO;AACxC,MAAI,CAAC,MAAM,SAAS,OAAQ,OAAM,IAAI,MAAM,6BAA6B;AAEzE,MAAI,MAAM,SAAS,WAAW,EAAG,QAAO,MAAM,SAAS,CAAC;AAExD,MAAI;AACJ,MAAI,kBAAkB;AACtB,cAAY,OAAO,SAAU,SAAS;AACpC,QAAI,KAAK,mBAAmB,SAAS,KAAK;AAC1C,QAAI,OAAO,GAAG,WAAW;AACzB,QAAI,OAAO,iBAAiB;AAC1B,uBAAiB;AACjB,wBAAkB;AAAA,IACpB;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAUA,SAAS,aAAa,KAAK,KAAK;AAC9B,SAAO,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC;AAC9C;AAGA,IAAO,gBAAQ;","names":["line"]}
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { geojsonRbush as rbush } from \"@turf/geojson-rbush\";\nimport { truncate } from \"@turf/truncate\";\nimport { lineSegment } from \"@turf/line-segment\";\nimport { lineIntersect } from \"@turf/line-intersect\";\nimport { nearestPointOnLine } from \"@turf/nearest-point-on-line\";\nimport { getCoords, getCoord, getType } from \"@turf/invariant\";\nimport { featureEach, featureReduce, flattenEach } from \"@turf/meta\";\nimport { lineString, featureCollection, feature } from \"@turf/helpers\";\nimport {\n Feature,\n FeatureCollection,\n GeoJsonTypes,\n LineString,\n MultiLineString,\n MultiPoint,\n MultiPolygon,\n Point,\n Polygon,\n} from \"geojson\";\n\ntype Splitter = Feature<\n Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon\n>;\n\n/**\n * Split a LineString by another GeoJSON Feature.\n *\n * @function\n * @param {Feature<LineString>} line LineString Feature to split\n * @param {Feature<any>} splitter Feature used to split line\n * @returns {FeatureCollection<LineString>} Split LineStrings\n * @example\n * var line = turf.lineString([[120, -25], [145, -25]]);\n * var splitter = turf.lineString([[130, -15], [130, -35]]);\n *\n * var split = turf.lineSplit(line, splitter);\n *\n * //addToMap\n * var addToMap = [line, splitter, split]\n *\n * split.features[0].properties.stroke = \"red\";\n * split.features[1].properties.stroke = \"blue\";\n */\nfunction lineSplit<T extends LineString>(\n line: Feature<T> | T,\n splitter: Splitter\n): FeatureCollection<T> {\n if (!line) throw new Error(\"line is required\");\n if (!splitter) throw new Error(\"splitter is required\");\n\n const lineType = getType(line) as Exclude<GeoJsonTypes, \"Feature\">;\n const splitterType = getType(splitter) as Exclude<GeoJsonTypes, \"Feature\">;\n\n if (lineType !== \"LineString\") throw new Error(\"line must be LineString\");\n if (splitterType === \"FeatureCollection\")\n throw new Error(\"splitter cannot be a FeatureCollection\");\n if (splitterType === \"GeometryCollection\")\n throw new Error(\"splitter cannot be a GeometryCollection\");\n\n // remove excessive decimals from splitter\n // to avoid possible approximation issues in rbush\n var truncatedSplitter = truncate(splitter, { precision: 7 });\n\n // Ensure we're consistently sending Feature<LineString> into the splitLine methods.\n if (line.type !== \"Feature\") {\n line = feature(line);\n }\n\n switch (splitterType) {\n case \"Point\":\n return splitLineWithPoint(\n line as Feature<LineString>,\n truncatedSplitter as Feature<Point>\n ) as FeatureCollection<T>;\n case \"MultiPoint\":\n return splitLineWithPoints(\n line as Feature<LineString>,\n truncatedSplitter as Feature<MultiPoint>\n ) as FeatureCollection<T>;\n case \"LineString\":\n case \"MultiLineString\":\n case \"Polygon\":\n case \"MultiPolygon\":\n return splitLineWithPoints(\n line as Feature<LineString>,\n lineIntersect(\n line,\n truncatedSplitter as Feature<\n LineString | MultiLineString | Polygon | MultiPolygon\n >,\n {\n ignoreSelfIntersections: true,\n }\n )\n ) as FeatureCollection<T>;\n }\n}\n\n/**\n * Split LineString with MultiPoint\n *\n * @private\n * @param {Feature<LineString>} line LineString\n * @param {FeatureCollection<Point>} splitter Point\n * @returns {FeatureCollection<LineString>} split LineStrings\n */\nfunction splitLineWithPoints(\n line: Feature<LineString>,\n splitter: FeatureCollection<Point> | Feature<MultiPoint>\n) {\n var results: Feature<LineString>[] = [];\n var tree = rbush<LineString>();\n\n flattenEach(\n splitter as FeatureCollection<Point>, // this cast should be unnecessary (and is wrong, it could contain MultiPoints), but is a workaround for bad flattenEach typings\n function (point: Feature<Point>) {\n // Add index/id to features (needed for filter)\n results.forEach(function (feature, index) {\n feature.id = index;\n });\n // First Point - doesn't need to handle any previous line results\n if (!results.length) {\n results = splitLineWithPoint(line, point).features;\n tree.load(featureCollection(results));\n // Split with remaining points - lines might needed to be split multiple times\n } else {\n // Find all lines that are within the splitter's bbox\n var search = tree.search(point);\n\n if (search.features.length) {\n // RBush might return multiple lines - only process the closest line to splitter\n var closestLine = findClosestFeature(point, search);\n\n // Remove closest line from results since this will be split into two lines\n // This removes any duplicates inside the results & index\n results = results.filter(function (feature) {\n return feature.id !== closestLine.id;\n });\n tree.remove(closestLine);\n\n // Append the two newly split lines into the results\n featureEach(splitLineWithPoint(closestLine, point), function (line) {\n results.push(line);\n tree.insert(line);\n });\n }\n }\n }\n );\n return featureCollection(results);\n}\n\n/**\n * Split LineString with Point\n *\n * @private\n * @param {Feature<LineString>} line LineString\n * @param {Feature<Point>} splitter Point\n * @returns {FeatureCollection<LineString>} split LineStrings\n */\nfunction splitLineWithPoint(\n line: Feature<LineString>,\n splitter: Feature<Point>\n) {\n var results = [];\n\n // handle endpoints\n var startPoint = getCoords(line)[0];\n var endPoint = getCoords(line)[line.geometry.coordinates.length - 1];\n if (\n pointsEquals(startPoint, getCoord(splitter)) ||\n pointsEquals(endPoint, getCoord(splitter))\n )\n return featureCollection([line]);\n\n // Create spatial index\n var tree = rbush<LineString>();\n var segments = lineSegment(line);\n tree.load(segments);\n\n // Find all segments that are within bbox of splitter\n var search = tree.search(splitter);\n\n // Return itself if point is not within spatial index\n if (!search.features.length) return featureCollection([line]);\n\n // RBush might return multiple lines - only process the closest line to splitter\n var closestSegment = findClosestFeature(splitter, search);\n\n // Initial value is the first point of the first segments (beginning of line)\n var initialValue = [startPoint];\n var lastCoords = featureReduce(\n segments,\n function (previous, current, index) {\n var currentCoords = getCoords(current)[1];\n var splitterCoords = getCoord(splitter);\n\n // Location where segment intersects with line\n if (index === closestSegment.id) {\n previous.push(splitterCoords);\n results.push(lineString(previous));\n // Don't duplicate splitter coordinate (Issue #688)\n if (pointsEquals(splitterCoords, currentCoords))\n return [splitterCoords];\n return [splitterCoords, currentCoords];\n\n // Keep iterating over coords until finished or intersection is found\n } else {\n previous.push(currentCoords);\n return previous;\n }\n },\n initialValue\n );\n // Append last line to final split results\n if (lastCoords.length > 1) {\n results.push(lineString(lastCoords));\n }\n return featureCollection(results);\n}\n\n/**\n * Find Closest Feature\n *\n * @private\n * @param {Feature<Point>} point Feature must be closest to this point\n * @param {FeatureCollection<LineString>} lines Collection of Features\n * @returns {Feature<LineString>} closest LineString\n */\nfunction findClosestFeature(\n point: Feature<Point>,\n lines: FeatureCollection<LineString>\n): Feature<LineString> {\n if (!lines.features.length) throw new Error(\"lines must contain features\");\n // Filter to one segment that is the closest to the line\n if (lines.features.length === 1) return lines.features[0];\n\n var closestFeature;\n var closestDistance = Infinity;\n featureEach(lines, function (segment) {\n var pt = nearestPointOnLine(segment, point);\n var dist = pt.properties.dist;\n if (dist < closestDistance) {\n closestFeature = segment;\n closestDistance = dist;\n }\n });\n return closestFeature!;\n}\n\n/**\n * Compares two points and returns if they are equals\n *\n * @private\n * @param {Array<number>} pt1 point\n * @param {Array<number>} pt2 point\n * @returns {boolean} true if they are equals\n */\nfunction pointsEquals(pt1: number[], pt2: number[]) {\n return pt1[0] === pt2[0] && pt1[1] === pt2[1];\n}\n\nexport { Splitter, lineSplit };\nexport default lineSplit;\n"],"mappings":";AAAA,SAAS,gBAAgB,aAAa;AACtC,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AACnC,SAAS,WAAW,UAAU,eAAe;AAC7C,SAAS,aAAa,eAAe,mBAAmB;AACxD,SAAS,YAAY,mBAAmB,eAAe;AAoCvD,SAAS,UACP,MACA,UACsB;AACtB,MAAI,CAAC,KAAM,OAAM,IAAI,MAAM,kBAAkB;AAC7C,MAAI,CAAC,SAAU,OAAM,IAAI,MAAM,sBAAsB;AAErD,QAAM,WAAW,QAAQ,IAAI;AAC7B,QAAM,eAAe,QAAQ,QAAQ;AAErC,MAAI,aAAa,aAAc,OAAM,IAAI,MAAM,yBAAyB;AACxE,MAAI,iBAAiB;AACnB,UAAM,IAAI,MAAM,wCAAwC;AAC1D,MAAI,iBAAiB;AACnB,UAAM,IAAI,MAAM,yCAAyC;AAI3D,MAAI,oBAAoB,SAAS,UAAU,EAAE,WAAW,EAAE,CAAC;AAG3D,MAAI,KAAK,SAAS,WAAW;AAC3B,WAAO,QAAQ,IAAI;AAAA,EACrB;AAEA,UAAQ,cAAc;AAAA,IACpB,KAAK;AACH,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,IACF,KAAK;AACH,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,IACF,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,QACL;AAAA,QACA;AAAA,UACE;A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gBAAQ;","names":["feature","line"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/line-split",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.3",
|
|
4
4
|
"description": "Split a LineString by another GeoJSON Feature.",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -62,19 +62,21 @@
|
|
|
62
62
|
"tape": "^5.9.0",
|
|
63
63
|
"tsup": "^8.4.0",
|
|
64
64
|
"tsx": "^4.19.4",
|
|
65
|
+
"typescript": "^5.8.3",
|
|
65
66
|
"write-json-file": "^6.0.0"
|
|
66
67
|
},
|
|
67
68
|
"dependencies": {
|
|
68
|
-
"@turf/bbox": "7.3.
|
|
69
|
-
"@turf/geojson-rbush": "7.3.
|
|
70
|
-
"@turf/helpers": "7.3.
|
|
71
|
-
"@turf/invariant": "7.3.
|
|
72
|
-
"@turf/line-intersect": "7.3.
|
|
73
|
-
"@turf/line-segment": "7.3.
|
|
74
|
-
"@turf/meta": "7.3.
|
|
75
|
-
"@turf/nearest-point-on-line": "7.3.
|
|
76
|
-
"@turf/truncate": "7.3.
|
|
77
|
-
"@types/geojson": "^7946.0.10"
|
|
69
|
+
"@turf/bbox": "7.3.3",
|
|
70
|
+
"@turf/geojson-rbush": "7.3.3",
|
|
71
|
+
"@turf/helpers": "7.3.3",
|
|
72
|
+
"@turf/invariant": "7.3.3",
|
|
73
|
+
"@turf/line-intersect": "7.3.3",
|
|
74
|
+
"@turf/line-segment": "7.3.3",
|
|
75
|
+
"@turf/meta": "7.3.3",
|
|
76
|
+
"@turf/nearest-point-on-line": "7.3.3",
|
|
77
|
+
"@turf/truncate": "7.3.3",
|
|
78
|
+
"@types/geojson": "^7946.0.10",
|
|
79
|
+
"tslib": "^2.8.1"
|
|
78
80
|
},
|
|
79
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "fa0e2da8ce02d9a82720eae922f89c9386596e04"
|
|
80
82
|
}
|