Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue #1232 - Bug in turf-line-split #2460

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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: 0 additions & 6 deletions packages/turf-line-split/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { geojsonRbush as rbush } from "@turf/geojson-rbush";
import { square } from "@turf/square";
import { bbox } from "@turf/bbox";
import { truncate } from "@turf/truncate";
import { lineSegment } from "@turf/line-segment";
import { lineIntersect } from "@turf/line-intersect";
Expand Down Expand Up @@ -80,11 +79,6 @@ function splitLineWithPoints(line, splitter) {
// First Point - doesn't need to handle any previous line results
if (!results.length) {
results = splitLineWithPoint(line, point).features;

// Add Square BBox to each feature for GeoJSON-RBush
results.forEach(function (feature) {
if (!feature.bbox) feature.bbox = square(bbox(feature));
});
tree.load(featureCollection(results));
// Split with remaining points - lines might needed to be split multiple times
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-line-split/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let fixtures = fs.readdirSync(directories.in).map((filename) => {
geojson: loadJsonFileSync(directories.in + filename),
};
});
// fixtures = fixtures.filter(name => name === 'issue-#1075')
// fixtures = fixtures.filter(({ name }) => name === 'issue-#1075')

test("turf-line-split", (t) => {
for (const { filename, name, geojson } of fixtures) {
Expand Down
33 changes: 33 additions & 0 deletions packages/turf-line-split/test/in/issue-#1232.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[13.8716, 56.2783],
[13.8715, 56.2785],
[13.8743, 56.2794],
[13.8796, 56.2746]
]
},
"properties": {}
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[13.8726, 56.2786],
[13.8716, 56.2786],
[13.8713, 56.2784],
[13.8726, 56.2786]
]
]
},
"properties": {}
}
]
}
4 changes: 2 additions & 2 deletions packages/turf-line-split/test/out/issue-#1075-1.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[-87.168446, 37.947929]
]
},
"bbox": [-87.1693575, 37.946093, -87.1675215, 37.947929],
"bbox": [-87.168446, 37.946093, -87.168433, 37.947929],
"id": 0
},
{
Expand All @@ -30,7 +30,7 @@
[-87.16851, 37.960085]
]
},
"bbox": [-87.174556, 37.947929, -87.16239999999999, 37.960085],
"bbox": [-87.16851, 37.947929, -87.168446, 37.960085],
"id": 1
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-line-split/test/out/issue-#1075-2.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[-87.1684432, 37.9479288]
]
},
"bbox": [-87.16935600000001, 37.946093, -87.1675202, 37.9479288],
"bbox": [-87.1684432, 37.946093, -87.168433, 37.9479288],
"id": 0
},
{
Expand Down
4 changes: 2 additions & 2 deletions packages/turf-line-split/test/out/issue-#1075-3.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[-87.1684432, 37.9479288]
]
},
"bbox": [-87.16935600000001, 37.946093, -87.1675202, 37.9479288],
"bbox": [-87.1684432, 37.946093, -87.168433, 37.9479288],
"id": 0
},
{
Expand All @@ -30,7 +30,7 @@
[-87.16851, 37.960085]
]
},
"bbox": [-87.17455469999999, 37.9479288, -87.1623985, 37.960085],
"bbox": [-87.16851, 37.9479288, -87.1684432, 37.960085],
"id": 1
},
{
Expand Down
81 changes: 81 additions & 0 deletions packages/turf-line-split/test/out/issue-#1232.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"stroke": "#F00",
"stroke-width": 10
},
"geometry": {
"type": "LineString",
"coordinates": [
[13.8716, 56.2783],
[13.871532142857145, 56.27843571428571]
]
},
"bbox": [13.871532142857145, 56.2783, 13.8716, 56.27843571428571],
"id": 0
},
{
"type": "Feature",
"properties": {
"stroke": "#00F",
"stroke-width": 10
},
"geometry": {
"type": "LineString",
"coordinates": [
[13.871532142857145, 56.27843571428571],
[13.8715, 56.2785],
[13.871811111111098, 56.2786]
]
},
"bbox": [13.8715, 56.27843571428571, 13.871811111111098, 56.2786]
},
{
"type": "Feature",
"properties": {
"stroke": "#F00",
"stroke-width": 10
},
"geometry": {
"type": "LineString",
"coordinates": [
[13.871811111111098, 56.2786],
[13.8743, 56.2794],
[13.8796, 56.2746]
]
},
"bbox": [13.871811111111098, 56.2746, 13.8796, 56.2794]
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[13.8716, 56.2783],
[13.8715, 56.2785],
[13.8743, 56.2794],
[13.8796, 56.2746]
]
},
"properties": {}
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[13.8726, 56.2786],
[13.8716, 56.2786],
[13.8713, 56.2784],
[13.8726, 56.2786]
]
]
},
"properties": {}
}
]
}
7 changes: 6 additions & 1 deletion packages/turf-line-split/test/out/linestrings.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
[118.6090049242457, -27.06938170764152]
]
},
"bbox": [118.6090049242457, -34.00655617152344, 126.5625, -26.05306109576914],
"bbox": [
118.6090049242457,
-32.99023555965107,
126.5625,
-27.06938170764152
],
"id": 0
},
{
Expand Down
5 changes: 4 additions & 1 deletion packages/turf-line-split/test/out/multi-linestring.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
]
},
"bbox": [
115.400390625, -29.81495016405105, 124.99610755509275, -20.219233233958303
115.400390625,
-27.215556209029675,
124.99610755509275,
-22.81862718897968
],
"id": 0
},
Expand Down
7 changes: 6 additions & 1 deletion packages/turf-line-split/test/out/multi-polygon.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
[119.2236328, -26.207788245559954]
]
},
"bbox": [115.400390625, -28.623293314794815, 119.2236328, -24.80005113979481],
"bbox": [
115.400390625,
-27.215556209029675,
119.2236328,
-26.207788245559954
],
"id": 0
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
]
},
"bbox": [
116.98242187499999, -35.54005060293165, 127.35351562499999, -25.16895685293165
116.98242187499999,
-32.249974455863295,
127.35351562499999,
-28.459033
],
"id": 0
},
Expand Down
5 changes: 4 additions & 1 deletion packages/turf-line-split/test/out/polygon-with-holes.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
]
},
"bbox": [
113.99414062499999, -34.855911539501186, 115.5887281750802, -33.261323989420966
113.99414062499999,
-34.45221847282653,
115.5887281750802,
-33.66501705609563
],
"id": 0
},
Expand Down
5 changes: 4 additions & 1 deletion packages/turf-line-split/test/out/polygon.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
]
},
"bbox": [
129.64242518496138, -37.85750715625203, 134.26374260800708, -33.23618973320634
131.66015625,
-37.85750715625203,
132.24601154296846,
-33.23618973320634
],
"id": 1
},
Expand Down