@turf/line-overlap 6.5.0 → 7.0.0-alpha.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 +8 -7
- package/dist/es/index.js +29 -11
- package/dist/js/index.d.ts +1 -1
- package/dist/js/index.js +36 -20
- package/package.json +11 -10
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
|
-
|
|
9
|
+
### Parameters
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
**
|
|
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]
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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;
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FeatureCollection, Feature, LineString, MultiLineString, Polygon, MultiPolygon } from "
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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": "
|
|
3
|
+
"version": "7.0.0-alpha.0",
|
|
4
4
|
"description": "turf line-overlap module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"docs": "node ../../scripts/generate-readmes",
|
|
49
49
|
"test": "npm-run-all test:*",
|
|
50
50
|
"test:tape": "ts-node -r esm test.js",
|
|
51
|
-
"test:types": "tsc --esModuleInterop --noEmit types.ts"
|
|
51
|
+
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/deep-equal": "^1.0.1",
|
|
@@ -63,14 +63,15 @@
|
|
|
63
63
|
"write-json-file": "*"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@turf/boolean-point-on-line": "^
|
|
67
|
-
"@turf/
|
|
68
|
-
"@turf/
|
|
69
|
-
"@turf/
|
|
70
|
-
"@turf/
|
|
71
|
-
"@turf/
|
|
66
|
+
"@turf/boolean-point-on-line": "^7.0.0-alpha.0",
|
|
67
|
+
"@turf/geojson-rbush": "^3.2.0",
|
|
68
|
+
"@turf/helpers": "^7.0.0-alpha.0",
|
|
69
|
+
"@turf/invariant": "^7.0.0-alpha.0",
|
|
70
|
+
"@turf/line-segment": "^7.0.0-alpha.0",
|
|
71
|
+
"@turf/meta": "^7.0.0-alpha.0",
|
|
72
|
+
"@turf/nearest-point-on-line": "^7.0.0-alpha.0",
|
|
72
73
|
"deep-equal": "1.x",
|
|
73
|
-
"
|
|
74
|
+
"tslib": "^2.3.0"
|
|
74
75
|
},
|
|
75
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
76
77
|
}
|