@turf/line-split 7.0.0 → 7.1.0-alpha.70

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.
@@ -1,7 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- // index.js
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.js
5
2
  var _geojsonrbush = require('@turf/geojson-rbush');
6
3
  var _square = require('@turf/square');
7
4
  var _bbox = require('@turf/bbox');
@@ -43,7 +40,6 @@ function lineSplit(line, splitter) {
43
40
  );
44
41
  }
45
42
  }
46
- __name(lineSplit, "lineSplit");
47
43
  function splitLineWithPoints(line, splitter) {
48
44
  var results = [];
49
45
  var tree = _geojsonrbush.geojsonRbush.call(void 0, );
@@ -75,7 +71,6 @@ function splitLineWithPoints(line, splitter) {
75
71
  });
76
72
  return _helpers.featureCollection.call(void 0, results);
77
73
  }
78
- __name(splitLineWithPoints, "splitLineWithPoints");
79
74
  function splitLineWithPoint(line, splitter) {
80
75
  var results = [];
81
76
  var startPoint = _invariant.getCoords.call(void 0, line)[0];
@@ -113,7 +108,6 @@ function splitLineWithPoint(line, splitter) {
113
108
  }
114
109
  return _helpers.featureCollection.call(void 0, results);
115
110
  }
116
- __name(splitLineWithPoint, "splitLineWithPoint");
117
111
  function findClosestFeature(point, lines) {
118
112
  if (!lines.features.length)
119
113
  throw new Error("lines must contain features");
@@ -131,11 +125,9 @@ function findClosestFeature(point, lines) {
131
125
  });
132
126
  return closestFeature;
133
127
  }
134
- __name(findClosestFeature, "findClosestFeature");
135
128
  function pointsEquals(pt1, pt2) {
136
129
  return pt1[0] === pt2[0] && pt1[1] === pt2[1];
137
130
  }
138
- __name(pointsEquals, "pointsEquals");
139
131
  var turf_line_split_default = lineSplit;
140
132
 
141
133
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.js"],"names":["line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;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;AAxDS;AAkET,SAAS,mBAAmB,OAAO,OAAO;AACxC,MAAI,CAAC,MAAM,SAAS;AAAQ,UAAM,IAAI,MAAM,6BAA6B;AAEzE,MAAI,MAAM,SAAS,WAAW;AAAG,WAAO,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;AAhBS;AA0BT,SAAS,aAAa,KAAK,KAAK;AAC9B,SAAO,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC;AAC9C;AAFS;AAKT,IAAO,0BAAQ","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 * @name lineSplit\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":["../../index.js"],"names":["line"],"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,SAAS,aAAa,eAAe,mBAAmB;AACxD,SAAS,YAAY,yBAAyB;AAkB9C,SAAS,UAAU,MAAM,UAAU;AACjC,MAAI,CAAC;AAAM,UAAM,IAAI,MAAM,kBAAkB;AAC7C,MAAI,CAAC;AAAU,UAAM,IAAI,MAAM,sBAAsB;AAErD,MAAI,WAAW,QA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AW,UAAU,CAAC;AAAA,EACrC;AACA,SAAO,kBAAkB,OAAO;AAClC;AAUA,SAAS,mBAAmB,OAAO,OAAO;AACxC,MAAI,CAAC,MAAM,SAAS;AAAQ,UAAM,IAAI,MAAM,6BAA6B;AAEzE,MAAI,MAAM,SAAS,WAAW;AAAG,WAAO,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","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 * @name lineSplit\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"]}
package/dist/esm/index.js CHANGED
@@ -1,6 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
1
  // index.js
5
2
  import { geojsonRbush as rbush } from "@turf/geojson-rbush";
6
3
  import { square } from "@turf/square";
@@ -43,7 +40,6 @@ function lineSplit(line, splitter) {
43
40
  );
44
41
  }
45
42
  }
46
- __name(lineSplit, "lineSplit");
47
43
  function splitLineWithPoints(line, splitter) {
48
44
  var results = [];
49
45
  var tree = rbush();
@@ -75,7 +71,6 @@ function splitLineWithPoints(line, splitter) {
75
71
  });
76
72
  return featureCollection(results);
77
73
  }
78
- __name(splitLineWithPoints, "splitLineWithPoints");
79
74
  function splitLineWithPoint(line, splitter) {
80
75
  var results = [];
81
76
  var startPoint = getCoords(line)[0];
@@ -113,7 +108,6 @@ function splitLineWithPoint(line, splitter) {
113
108
  }
114
109
  return featureCollection(results);
115
110
  }
116
- __name(splitLineWithPoint, "splitLineWithPoint");
117
111
  function findClosestFeature(point, lines) {
118
112
  if (!lines.features.length)
119
113
  throw new Error("lines must contain features");
@@ -131,11 +125,9 @@ function findClosestFeature(point, lines) {
131
125
  });
132
126
  return closestFeature;
133
127
  }
134
- __name(findClosestFeature, "findClosestFeature");
135
128
  function pointsEquals(pt1, pt2) {
136
129
  return pt1[0] === pt2[0] && pt1[1] === pt2[1];
137
130
  }
138
- __name(pointsEquals, "pointsEquals");
139
131
  var turf_line_split_default = lineSplit;
140
132
  export {
141
133
  turf_line_split_default as default,
@@ -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 * @name lineSplit\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,q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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;AAxDS;AAkET,SAAS,mBAAmB,OAAO,OAAO;AACxC,MAAI,CAAC,MAAM,SAAS;AAAQ,UAAM,IAAI,MAAM,6BAA6B;AAEzE,MAAI,MAAM,SAAS,WAAW;AAAG,WAAO,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;AAhBS;AA0BT,SAAS,aAAa,KAAK,KAAK;AAC9B,SAAO,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC;AAC9C;AAFS;AAKT,IAAO,0BAAQ;","names":["line"]}
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 * @name lineSplit\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,SAAS,aAAa,eAAe,mBAAmB;AACxD,SAAS,YAAY,yBAAyB;AAkB9C,SAAS,UAAU,MAAM,UAAU;AACjC,MAAI,CAAC;AAAM,UAAM,IAAI,MAAM,kBAAkB;AAC7C,MAAI,CAAC;AAAU,UAAM,IAAI,MAAM,sBAAsB;AAErD,MAAI,WAAW,QAAQ,IAAI;AAC3B,MAAI,eAAe,QAAQ,QAAQ;AAEnC,MAAI,aAAa;AAAc,UAAM,IAAI,MAAM,yBAAyB;AACxE,MAAI,iBAAiB;AACnB,UAAM,I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AAM,IAAI,MAAM,6BAA6B;AAEzE,MAAI,MAAM,SAAS,WAAW;AAAG,WAAO,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/line-split",
3
- "version": "7.0.0",
3
+ "version": "7.1.0-alpha.70+948cdafaf",
4
4
  "description": "turf line-split module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -66,16 +66,17 @@
66
66
  "write-json-file": "^5.0.0"
67
67
  },
68
68
  "dependencies": {
69
- "@turf/bbox": "^7.0.0",
70
- "@turf/geojson-rbush": "^7.0.0",
71
- "@turf/helpers": "^7.0.0",
72
- "@turf/invariant": "^7.0.0",
73
- "@turf/line-intersect": "^7.0.0",
74
- "@turf/line-segment": "^7.0.0",
75
- "@turf/meta": "^7.0.0",
76
- "@turf/nearest-point-on-line": "^7.0.0",
77
- "@turf/square": "^7.0.0",
78
- "@turf/truncate": "^7.0.0"
69
+ "@turf/bbox": "^7.1.0-alpha.70+948cdafaf",
70
+ "@turf/geojson-rbush": "^7.1.0-alpha.70+948cdafaf",
71
+ "@turf/helpers": "^7.1.0-alpha.70+948cdafaf",
72
+ "@turf/invariant": "^7.1.0-alpha.70+948cdafaf",
73
+ "@turf/line-intersect": "^7.1.0-alpha.70+948cdafaf",
74
+ "@turf/line-segment": "^7.1.0-alpha.70+948cdafaf",
75
+ "@turf/meta": "^7.1.0-alpha.70+948cdafaf",
76
+ "@turf/nearest-point-on-line": "^7.1.0-alpha.70+948cdafaf",
77
+ "@turf/square": "^7.1.0-alpha.70+948cdafaf",
78
+ "@turf/truncate": "^7.1.0-alpha.70+948cdafaf",
79
+ "@types/geojson": "^7946.0.10"
79
80
  },
80
- "gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
81
+ "gitHead": "948cdafaf70606d2e27fcc79973fa48ee1182067"
81
82
  }