@turf/line-overlap 6.5.0 → 7.0.0-alpha.1

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
@@ -6,14 +6,15 @@
6
6
 
7
7
  Takes any LineString or Polygon and returns the overlapping lines between both features.
8
8
 
9
- **Parameters**
9
+ ### Parameters
10
10
 
11
- - `line1` **([Geometry][1] \| [Feature][2]<([LineString][3] \| [MultiLineString][4] \| [Polygon][5] \| [MultiPolygon][6])>)** any LineString or Polygon
12
- - `line2` **([Geometry][1] \| [Feature][2]<([LineString][3] \| [MultiLineString][4] \| [Polygon][5] \| [MultiPolygon][6])>)** any LineString or Polygon
13
- - `options` **[Object][7]** Optional parameters (optional, default `{}`)
14
- - `options.tolerance` **[number][8]** Tolerance distance to match overlapping line segments (in kilometers) (optional, default `0`)
11
+ * `line1` **([Geometry][1] | [Feature][2]<([LineString][3] | [MultiLineString][4] | [Polygon][5] | [MultiPolygon][6])>)** any LineString or Polygon
12
+ * `line2` **([Geometry][1] | [Feature][2]<([LineString][3] | [MultiLineString][4] | [Polygon][5] | [MultiPolygon][6])>)** any LineString or Polygon
13
+ * `options` **[Object][7]** Optional parameters (optional, default `{}`)
15
14
 
16
- **Examples**
15
+ * `options.tolerance` **[number][8]** Tolerance distance to match overlapping line segments (in kilometers) (optional, default `0`)
16
+
17
+ ### Examples
17
18
 
18
19
  ```javascript
19
20
  var line1 = turf.lineString([[115, -35], [125, -30], [135, -30], [145, -35]]);
@@ -25,7 +26,7 @@ var overlapping = turf.lineOverlap(line1, line2);
25
26
  var addToMap = [line1, line2, overlapping]
26
27
  ```
27
28
 
28
- Returns **[FeatureCollection][9]&lt;[LineString][3]>** lines(s) that are overlapping between both features
29
+ Returns **[FeatureCollection][9]<[LineString][3]>** lines(s) that are overlapping between both features
29
30
 
30
31
  [1]: https://tools.ietf.org/html/rfc7946#section-3.1
31
32
 
package/dist/es/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import rbush from "geojson-rbush";
1
+ import rbush from "@turf/geojson-rbush";
2
2
  import lineSegment from "@turf/line-segment";
3
3
  import nearestPointOnLine from "@turf/nearest-point-on-line";
4
4
  import booleanPointOnLine from "@turf/boolean-point-on-line";
5
5
  import { getCoords } from "@turf/invariant";
6
6
  import { featureEach, segmentEach } from "@turf/meta";
7
- import { featureCollection, isObject, } from "@turf/helpers";
7
+ import { featureCollection, isObject } from "@turf/helpers";
8
8
  import equal from "deep-equal";
9
9
  /**
10
10
  * Takes any LineString or Polygon and returns the overlapping lines between both features.
@@ -24,8 +24,7 @@ import equal from "deep-equal";
24
24
  * //addToMap
25
25
  * var addToMap = [line1, line2, overlapping]
26
26
  */
27
- function lineOverlap(line1, line2, options) {
28
- if (options === void 0) { options = {}; }
27
+ function lineOverlap(line1, line2, options = {}) {
29
28
  // Optional parameters
30
29
  options = options || {};
31
30
  if (!isObject(options))
@@ -36,9 +35,10 @@ function lineOverlap(line1, line2, options) {
36
35
  // Create Spatial Index
37
36
  var tree = rbush();
38
37
  // To-Do -- HACK way to support typescript
39
- var line = lineSegment(line1);
38
+ const line = lineSegment(line1);
40
39
  tree.load(line);
41
40
  var overlapSegment;
41
+ let additionalSegments = [];
42
42
  // Line Intersection
43
43
  // Iterate over line segments
44
44
  segmentEach(line2, function (segment) {
@@ -55,8 +55,10 @@ function lineOverlap(line1, line2, options) {
55
55
  if (equal(coordsSegment, coordsMatch)) {
56
56
  doesOverlaps = true;
57
57
  // Overlaps already exists - only append last coordinate of segment
58
- if (overlapSegment)
59
- overlapSegment = concatSegment(overlapSegment, segment);
58
+ if (overlapSegment) {
59
+ overlapSegment =
60
+ concatSegment(overlapSegment, segment) || overlapSegment;
61
+ }
60
62
  else
61
63
  overlapSegment = segment;
62
64
  // Match segments which don't share nodes (Issue #901)
@@ -69,8 +71,10 @@ function lineOverlap(line1, line2, options) {
69
71
  nearestPointOnLine(match, coordsSegment[1]).properties.dist <=
70
72
  tolerance) {
71
73
  doesOverlaps = true;
72
- if (overlapSegment)
73
- overlapSegment = concatSegment(overlapSegment, segment);
74
+ if (overlapSegment) {
75
+ overlapSegment =
76
+ concatSegment(overlapSegment, segment) || overlapSegment;
77
+ }
74
78
  else
75
79
  overlapSegment = segment;
76
80
  }
@@ -83,8 +87,15 @@ function lineOverlap(line1, line2, options) {
83
87
  tolerance) {
84
88
  // Do not define (doesOverlap = true) since more matches can occur within the same segment
85
89
  // doesOverlaps = true;
86
- if (overlapSegment)
87
- overlapSegment = concatSegment(overlapSegment, match);
90
+ if (overlapSegment) {
91
+ const combinedSegment = concatSegment(overlapSegment, match);
92
+ if (combinedSegment) {
93
+ overlapSegment = combinedSegment;
94
+ }
95
+ else {
96
+ additionalSegments.push(match);
97
+ }
98
+ }
88
99
  else
89
100
  overlapSegment = match;
90
101
  }
@@ -93,6 +104,10 @@ function lineOverlap(line1, line2, options) {
93
104
  // Segment doesn't overlap - add overlaps to results & reset
94
105
  if (doesOverlaps === false && overlapSegment) {
95
106
  features.push(overlapSegment);
107
+ if (additionalSegments.length) {
108
+ features = features.concat(additionalSegments);
109
+ additionalSegments = [];
110
+ }
96
111
  overlapSegment = undefined;
97
112
  }
98
113
  });
@@ -123,6 +138,9 @@ function concatSegment(line, segment) {
123
138
  geom.unshift(coords[0]);
124
139
  else if (equal(coords[1], end))
125
140
  geom.push(coords[0]);
141
+ else
142
+ return; // If the overlap leaves the segment unchanged, return undefined so that this can be identified.
143
+ // Otherwise return the mutated line.
126
144
  return line;
127
145
  }
128
146
  export default lineOverlap;
@@ -1,4 +1,4 @@
1
- import { FeatureCollection, Feature, LineString, MultiLineString, Polygon, MultiPolygon } from "@turf/helpers";
1
+ import { FeatureCollection, Feature, LineString, MultiLineString, Polygon, MultiPolygon } from "geojson";
2
2
  /**
3
3
  * Takes any LineString or Polygon and returns the overlapping lines between both features.
4
4
  *
package/dist/js/index.js CHANGED
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var geojson_rbush_1 = __importDefault(require("geojson-rbush"));
7
- var line_segment_1 = __importDefault(require("@turf/line-segment"));
8
- var nearest_point_on_line_1 = __importDefault(require("@turf/nearest-point-on-line"));
9
- var boolean_point_on_line_1 = __importDefault(require("@turf/boolean-point-on-line"));
10
- var invariant_1 = require("@turf/invariant");
11
- var meta_1 = require("@turf/meta");
12
- var helpers_1 = require("@turf/helpers");
13
- var deep_equal_1 = __importDefault(require("deep-equal"));
3
+ const tslib_1 = require("tslib");
4
+ const geojson_rbush_1 = tslib_1.__importDefault(require("@turf/geojson-rbush"));
5
+ const line_segment_1 = tslib_1.__importDefault(require("@turf/line-segment"));
6
+ const nearest_point_on_line_1 = tslib_1.__importDefault(require("@turf/nearest-point-on-line"));
7
+ const boolean_point_on_line_1 = tslib_1.__importDefault(require("@turf/boolean-point-on-line"));
8
+ const invariant_1 = require("@turf/invariant");
9
+ const meta_1 = require("@turf/meta");
10
+ const helpers_1 = require("@turf/helpers");
11
+ const deep_equal_1 = tslib_1.__importDefault(require("deep-equal"));
14
12
  /**
15
13
  * Takes any LineString or Polygon and returns the overlapping lines between both features.
16
14
  *
@@ -29,8 +27,7 @@ var deep_equal_1 = __importDefault(require("deep-equal"));
29
27
  * //addToMap
30
28
  * var addToMap = [line1, line2, overlapping]
31
29
  */
32
- function lineOverlap(line1, line2, options) {
33
- if (options === void 0) { options = {}; }
30
+ function lineOverlap(line1, line2, options = {}) {
34
31
  // Optional parameters
35
32
  options = options || {};
36
33
  if (!helpers_1.isObject(options))
@@ -41,9 +38,10 @@ function lineOverlap(line1, line2, options) {
41
38
  // Create Spatial Index
42
39
  var tree = geojson_rbush_1.default();
43
40
  // To-Do -- HACK way to support typescript
44
- var line = line_segment_1.default(line1);
41
+ const line = line_segment_1.default(line1);
45
42
  tree.load(line);
46
43
  var overlapSegment;
44
+ let additionalSegments = [];
47
45
  // Line Intersection
48
46
  // Iterate over line segments
49
47
  meta_1.segmentEach(line2, function (segment) {
@@ -60,8 +58,10 @@ function lineOverlap(line1, line2, options) {
60
58
  if (deep_equal_1.default(coordsSegment, coordsMatch)) {
61
59
  doesOverlaps = true;
62
60
  // Overlaps already exists - only append last coordinate of segment
63
- if (overlapSegment)
64
- overlapSegment = concatSegment(overlapSegment, segment);
61
+ if (overlapSegment) {
62
+ overlapSegment =
63
+ concatSegment(overlapSegment, segment) || overlapSegment;
64
+ }
65
65
  else
66
66
  overlapSegment = segment;
67
67
  // Match segments which don't share nodes (Issue #901)
@@ -74,8 +74,10 @@ function lineOverlap(line1, line2, options) {
74
74
  nearest_point_on_line_1.default(match, coordsSegment[1]).properties.dist <=
75
75
  tolerance) {
76
76
  doesOverlaps = true;
77
- if (overlapSegment)
78
- overlapSegment = concatSegment(overlapSegment, segment);
77
+ if (overlapSegment) {
78
+ overlapSegment =
79
+ concatSegment(overlapSegment, segment) || overlapSegment;
80
+ }
79
81
  else
80
82
  overlapSegment = segment;
81
83
  }
@@ -88,8 +90,15 @@ function lineOverlap(line1, line2, options) {
88
90
  tolerance) {
89
91
  // Do not define (doesOverlap = true) since more matches can occur within the same segment
90
92
  // doesOverlaps = true;
91
- if (overlapSegment)
92
- overlapSegment = concatSegment(overlapSegment, match);
93
+ if (overlapSegment) {
94
+ const combinedSegment = concatSegment(overlapSegment, match);
95
+ if (combinedSegment) {
96
+ overlapSegment = combinedSegment;
97
+ }
98
+ else {
99
+ additionalSegments.push(match);
100
+ }
101
+ }
93
102
  else
94
103
  overlapSegment = match;
95
104
  }
@@ -98,6 +107,10 @@ function lineOverlap(line1, line2, options) {
98
107
  // Segment doesn't overlap - add overlaps to results & reset
99
108
  if (doesOverlaps === false && overlapSegment) {
100
109
  features.push(overlapSegment);
110
+ if (additionalSegments.length) {
111
+ features = features.concat(additionalSegments);
112
+ additionalSegments = [];
113
+ }
101
114
  overlapSegment = undefined;
102
115
  }
103
116
  });
@@ -128,6 +141,9 @@ function concatSegment(line, segment) {
128
141
  geom.unshift(coords[0]);
129
142
  else if (deep_equal_1.default(coords[1], end))
130
143
  geom.push(coords[0]);
144
+ else
145
+ return; // If the overlap leaves the segment unchanged, return undefined so that this can be identified.
146
+ // Otherwise return the mutated line.
131
147
  return line;
132
148
  }
133
149
  exports.default = lineOverlap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/line-overlap",
3
- "version": "6.5.0",
3
+ "version": "7.0.0-alpha.1",
4
4
  "description": "turf line-overlap module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -31,6 +31,7 @@
31
31
  "exports": {
32
32
  "./package.json": "./package.json",
33
33
  ".": {
34
+ "types": "./dist/js/index.d.ts",
34
35
  "import": "./dist/es/index.js",
35
36
  "require": "./dist/js/index.js"
36
37
  }
@@ -41,14 +42,14 @@
41
42
  "dist"
42
43
  ],
43
44
  "scripts": {
44
- "bench": "ts-node bench.js",
45
+ "bench": "tsx bench.js",
45
46
  "build": "npm-run-all build:*",
46
47
  "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
47
48
  "build:js": "tsc",
48
- "docs": "node ../../scripts/generate-readmes",
49
+ "docs": "tsx ../../scripts/generate-readmes",
49
50
  "test": "npm-run-all test:*",
50
- "test:tape": "ts-node -r esm test.js",
51
- "test:types": "tsc --esModuleInterop --noEmit types.ts"
51
+ "test:tape": "tsx test.js",
52
+ "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@types/deep-equal": "^1.0.1",
@@ -57,20 +58,21 @@
57
58
  "load-json-file": "*",
58
59
  "npm-run-all": "*",
59
60
  "tape": "*",
60
- "ts-node": "*",
61
61
  "tslint": "*",
62
+ "tsx": "*",
62
63
  "typescript": "*",
63
64
  "write-json-file": "*"
64
65
  },
65
66
  "dependencies": {
66
- "@turf/boolean-point-on-line": "^6.5.0",
67
- "@turf/helpers": "^6.5.0",
68
- "@turf/invariant": "^6.5.0",
69
- "@turf/line-segment": "^6.5.0",
70
- "@turf/meta": "^6.5.0",
71
- "@turf/nearest-point-on-line": "^6.5.0",
67
+ "@turf/boolean-point-on-line": "^7.0.0-alpha.1",
68
+ "@turf/geojson-rbush": "^3.2.0",
69
+ "@turf/helpers": "^7.0.0-alpha.1",
70
+ "@turf/invariant": "^7.0.0-alpha.1",
71
+ "@turf/line-segment": "^7.0.0-alpha.1",
72
+ "@turf/meta": "^7.0.0-alpha.1",
73
+ "@turf/nearest-point-on-line": "^7.0.0-alpha.1",
72
74
  "deep-equal": "1.x",
73
- "geojson-rbush": "3.x"
75
+ "tslib": "^2.3.0"
74
76
  },
75
- "gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
77
+ "gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
76
78
  }