@turf/line-split 7.2.0 → 7.3.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 CHANGED
@@ -20,7 +20,10 @@ var splitter = turf.lineString([[130, -15], [130, -35]]);
20
20
  var split = turf.lineSplit(line, splitter);
21
21
 
22
22
  //addToMap
23
- var addToMap = [line, splitter]
23
+ var addToMap = [line, splitter, split]
24
+
25
+ split.features[0].properties.stroke = "red";
26
+ split.features[1].properties.stroke = "blue";
24
27
  ```
25
28
 
26
29
  Returns **[FeatureCollection][3]<[LineString][2]>** Split LineStrings
@@ -1,7 +1,5 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.js
2
2
  var _geojsonrbush = require('@turf/geojson-rbush');
3
- var _square = require('@turf/square');
4
- var _bbox = require('@turf/bbox');
5
3
  var _truncate = require('@turf/truncate');
6
4
  var _linesegment = require('@turf/line-segment');
7
5
  var _lineintersect = require('@turf/line-intersect');
@@ -46,9 +44,6 @@ function splitLineWithPoints(line, splitter) {
46
44
  });
47
45
  if (!results.length) {
48
46
  results = splitLineWithPoint(line, point).features;
49
- results.forEach(function(feature) {
50
- if (!feature.bbox) feature.bbox = _square.square.call(void 0, _bbox.bbox.call(void 0, feature));
51
- });
52
47
  tree.load(_helpers.featureCollection.call(void 0, results));
53
48
  } else {
54
49
  var search = tree.search(point);
@@ -121,9 +116,9 @@ function findClosestFeature(point, lines) {
121
116
  function pointsEquals(pt1, pt2) {
122
117
  return pt1[0] === pt2[0] && pt1[1] === pt2[1];
123
118
  }
124
- var turf_line_split_default = lineSplit;
119
+ var index_default = lineSplit;
125
120
 
126
121
 
127
122
 
128
- exports.default = turf_line_split_default; exports.lineSplit = lineSplit;
123
+ exports.default = index_default; exports.lineSplit = lineSplit;
129
124
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-line-split/dist/cjs/index.cjs","../../index.js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,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,wBAAA,EAAQ,SAAA;ADhGf;AACE;AACA;AACF,yEAAC","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 { square } from \"@turf/square\";\nimport { bbox } from \"@turf/bbox\";\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]\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\n // Add Square BBox to each feature for GeoJSON-RBush\n results.forEach(function (feature) {\n if (!feature.bbox) feature.bbox = square(bbox(feature));\n });\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.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,GAAA,CAAI,aAAA,IAAiB,oBAAA;AACnB,IAAA,MAAM,IAAI,KAAA,CAAM,yCAAyC,CAAA;AAI3D,EAAA,IAAI,kBAAA,EAAoB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,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"]}
package/dist/esm/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // index.js
2
2
  import { geojsonRbush as rbush } from "@turf/geojson-rbush";
3
- import { square } from "@turf/square";
4
- import { bbox } from "@turf/bbox";
5
3
  import { truncate } from "@turf/truncate";
6
4
  import { lineSegment } from "@turf/line-segment";
7
5
  import { lineIntersect } from "@turf/line-intersect";
@@ -46,9 +44,6 @@ function splitLineWithPoints(line, splitter) {
46
44
  });
47
45
  if (!results.length) {
48
46
  results = splitLineWithPoint(line, point).features;
49
- results.forEach(function(feature) {
50
- if (!feature.bbox) feature.bbox = square(bbox(feature));
51
- });
52
47
  tree.load(featureCollection(results));
53
48
  } else {
54
49
  var search = tree.search(point);
@@ -121,9 +116,9 @@ function findClosestFeature(point, lines) {
121
116
  function pointsEquals(pt1, pt2) {
122
117
  return pt1[0] === pt2[0] && pt1[1] === pt2[1];
123
118
  }
124
- var turf_line_split_default = lineSplit;
119
+ var index_default = lineSplit;
125
120
  export {
126
- turf_line_split_default as default,
121
+ index_default as default,
127
122
  lineSplit
128
123
  };
129
124
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.js"],"sourcesContent":["import { geojsonRbush as rbush } from \"@turf/geojson-rbush\";\nimport { square } from \"@turf/square\";\nimport { bbox } from \"@turf/bbox\";\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]\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\n // Add Square BBox to each feature for GeoJSON-RBush\n results.forEach(function (feature) {\n if (!feature.bbox) feature.bbox = square(bbox(feature));\n });\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,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AACnC,SAAS,WAAW,UAAU,eAAe;AAC7C,SAA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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,0BAAQ;","names":["line"]}
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,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AAK;AAC9B,SAAO,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC;AAC9C;AAGA,IAAO,gBAAQ;","names":["line"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@turf/line-split",
3
- "version": "7.2.0",
4
- "description": "turf line-split module",
3
+ "version": "7.3.0",
4
+ "description": "Split a LineString by another GeoJSON Feature.",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
7
7
  "Denis Carriere <@DenisCarriere>"
@@ -56,27 +56,26 @@
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/benchmark": "^2.1.5",
59
- "@types/tape": "^4.13.4",
59
+ "@types/tape": "^5.8.1",
60
60
  "benchmark": "^2.1.4",
61
61
  "load-json-file": "^7.0.1",
62
62
  "npm-run-all": "^4.1.5",
63
63
  "tape": "^5.9.0",
64
- "tsup": "^8.3.5",
65
- "tsx": "^4.19.2",
66
- "write-json-file": "^5.0.0"
64
+ "tsup": "^8.4.0",
65
+ "tsx": "^4.19.4",
66
+ "write-json-file": "^6.0.0"
67
67
  },
68
68
  "dependencies": {
69
- "@turf/bbox": "^7.2.0",
70
- "@turf/geojson-rbush": "^7.2.0",
71
- "@turf/helpers": "^7.2.0",
72
- "@turf/invariant": "^7.2.0",
73
- "@turf/line-intersect": "^7.2.0",
74
- "@turf/line-segment": "^7.2.0",
75
- "@turf/meta": "^7.2.0",
76
- "@turf/nearest-point-on-line": "^7.2.0",
77
- "@turf/square": "^7.2.0",
78
- "@turf/truncate": "^7.2.0",
69
+ "@turf/bbox": "7.3.0",
70
+ "@turf/geojson-rbush": "7.3.0",
71
+ "@turf/helpers": "7.3.0",
72
+ "@turf/invariant": "7.3.0",
73
+ "@turf/line-intersect": "7.3.0",
74
+ "@turf/line-segment": "7.3.0",
75
+ "@turf/meta": "7.3.0",
76
+ "@turf/nearest-point-on-line": "7.3.0",
77
+ "@turf/truncate": "7.3.0",
79
78
  "@types/geojson": "^7946.0.10"
80
79
  },
81
- "gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
80
+ "gitHead": "9f58a103e8f9a587ab640307ed03ba5233913ddd"
82
81
  }