Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/turf-line-overlap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { nearestPointOnLine } from "@turf/nearest-point-on-line";
import { booleanPointOnLine } from "@turf/boolean-point-on-line";
import { getCoords } from "@turf/invariant";
import { featureEach, segmentEach } from "@turf/meta";
import { bbox } from "@turf/bbox";
import {
FeatureCollection,
Feature,
Expand Down Expand Up @@ -69,6 +70,11 @@ function lineOverlap<
return;
}

// Expand segment bounding box by the tolerance to create overlap in horizontal/vertical segments
var bb = bbox(segment);
bb = [bb[0]-tolerance, bb[1]-tolerance, bb[2]+tolerance, bb[3]+tolerance];
segment.bbox = bb;

// Iterate over each segments which falls within the same bounds
featureEach(tree.search(segment), function (match) {
if (doesOverlaps === false) {
Expand Down
3 changes: 2 additions & 1 deletion packages/turf-line-overlap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Takes any LineString or Polygon and returns the overlapping lines between both features.",
"author": "Turf Authors",
"contributors": [
"Denis Carriere <@DenisCarriere>"
"Denis Carriere <@DenisCarriere>", "Johannes Novotny <@jonovotny>"
],
"license": "MIT",
"bugs": {
Expand Down Expand Up @@ -66,6 +66,7 @@
"write-json-file": "^6.0.0"
},
"dependencies": {
"@turf/bbox": "workspace:*",
"@turf/boolean-point-on-line": "workspace:*",
"@turf/geojson-rbush": "workspace:*",
"@turf/helpers": "workspace:*",
Expand Down
56 changes: 56 additions & 0 deletions packages/turf-line-overlap/test/in/issue-#2582.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"type": "FeatureCollection",
"properties": {
"tolerance": 0.5
},
"features": [
{
"type": "Feature",
"properties": {
"stroke": "#F00",
"fill": "#F00",
"stroke-width": 10,
"stroke-opacity": 1,
"fill-opacity": 0.1,
"description": "triangle with one horizontal and one vertical side"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-75.17098005568795, 25.347140710069592],
[-74.06346334926921, 25.347140710069592],
[-74.06346334926921, 26.453856979730748],
[-75.17098005568795, 25.347140710069592]
]
]
}
},
{
"type": "Feature",
"properties": {
"stroke": "#00F",
"fill": "#00F",
"stroke-width": 3,
"stroke-opacity": 1,
"fill-opacity": 0.1,
"description": "polygon with segments parallel to the horizontal and vertical sides of the triangle, offset within overlap tolerance."
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-75.77433328502653, 24.801355223074808],
[-75.09510282010693, 25.344703228173987],
[-74.22891563805884, 25.344703228173987],
[-74.05974780288312, 25.19753021415865],
[-74.05974780288312, 26.642828790428396],
[-73.31725580493922, 27.286000671432706],
[-73.31725580493922, 24.80135522307481],
[-75.77433328502653, 24.801355223074808]
]
]
}
}
]
}
144 changes: 144 additions & 0 deletions packages/turf-line-overlap/test/out/issue-#2582.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"stroke": "#0F0",
"fill": "#0F0",
"stroke-width": 25
},
"geometry": {
"type": "LineString",
"coordinates": [
[
-74.22891563805884,
25.344703228173987
],
[
-75.09510282010693,
25.344703228173987
]
]
},
"bbox": [
-75.59510282010693,
24.844703228173987,
-73.72891563805884,
25.844703228173987
]
},
{
"type": "Feature",
"properties": {
"stroke": "#0F0",
"fill": "#0F0",
"stroke-width": 25
},
"geometry": {
"type": "LineString",
"coordinates": [
[
-74.06346334926921,
25.347140710069592
],
[
-74.06346334926921,
26.453856979730748
]
]
},
"bbox": [
-74.06346334926921,
25.347140710069592,
-74.06346334926921,
26.453856979730748
],
"id": 1
},
{
"type": "Feature",
"properties": {
"stroke": "#F00",
"fill": "#F00",
"stroke-width": 10,
"stroke-opacity": 1,
"fill-opacity": 0.1,
"description": "triangle with one horizontal and one vertical side"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-75.17098005568795,
25.347140710069592
],
[
-74.06346334926921,
25.347140710069592
],
[
-74.06346334926921,
26.453856979730748
],
[
-75.17098005568795,
25.347140710069592
]
]
]
}
},
{
"type": "Feature",
"properties": {
"stroke": "#00F",
"fill": "#00F",
"stroke-width": 3,
"stroke-opacity": 1,
"fill-opacity": 0.1,
"description": "polygon with segments parallel to the horizontal and vertical sides of the triangle, offset within overlap tolerance."
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-75.77433328502653,
24.801355223074808
],
[
-75.09510282010693,
25.344703228173987
],
[
-74.22891563805884,
25.344703228173987
],
[
-74.05974780288312,
25.19753021415865
],
[
-74.05974780288312,
26.642828790428396
],
[
-73.31725580493922,
27.286000671432706
],
[
-73.31725580493922,
24.80135522307481
],
[
-75.77433328502653,
24.801355223074808
]
]
]
}
}
]
}