turf: lineSplit doesn't split correctly
LineSplit is a great feature but it doesn’t work as expected. I use a simple Polygon (triangle) as a splitter to split a simple four-point LineString. This should result in three LineStrings but only two are produced:
var line = {
type: "Feature",
geometry: {
type: "LineString",
coordinates: [[13.8716,56.2783],[13.8715,56.2785],[13.8743,56.2794],[13.8796,56.2746]]
}
};
var splitter = {
type: "Feature",
geometry: {
type: "Polygon",
coordinates: [[[13.8726,56.2786],[13.8716,56.2786],[13.8713,56.2784],[13.8726,56.2786]]]
}
};
var split = turf.lineSplit(line, splitter);
Returns this collection:
{
type: "FeatureCollection",
features: [{
type: "Feature",
geometry: {
type: "LineString",
coordinates: [[13.8716, 56.2783], [13.871532142857145, 56.27843571428571]]
}
},
{
type: "Feature",
geometry: {
type: "LineString",
coordinates: [[13.871532142857145, 56.27843571428571], [13.8715, 56.2785], [13.8743, 56.2794], [13.8796, 56.2746]]
}
}]
}
Instead of this:
{
type: "FeatureCollection",
features: [{
type: "Feature",
geometry: {
type: "LineString",
coordinates: [[13.8716, 56.2783], [13.871532142857145, 56.27843571428571]]
}
},
{
type: "Feature",
geometry: {
type: "LineString",
coordinates: [[13.871532142857145, 56.27843571428571], [13.8715, 56.2785], [13.871811111111098, 56.2786]]
}
},
{
type: "Feature",
geometry: {
type: "LineString",
coordinates: [[13.871811111111098, 56.2786], [13.8743, 56.2794], [13.8796, 56.2746]]
}
}]
}
This is my first post ever on GitHub, so please be kind if I’m doing something wrong. Have searched earlier issues and haven’t seen this bug report.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 5
- Comments: 16 (3 by maintainers)
Commits related to this issue
- No longer need to reference @turf/square. Added tests for examples mentioned in issue #1232, as well as #2288 which this PR also helps address. Tidied up some test file Typescript errors. — committed to hanneshdc/turf by smallsaucepan a year ago
- No longer need to reference @turf/square. Added tests for examples mentioned in issue #1232, as well as #2288 which this PR also helps address. Tidied up some test file Typescript errors. — committed to ltkum/turf by smallsaucepan a year ago
Time for me to pile on. We are also running into this same issue. Example:
resultshould contain 3 line strings but ends up only having two.The fix proposed by @hanneshdc within PR #2460 solves the issue for us in this case. As they call out, this is possibly better achieved via #1727.
Is there any follow up on this issue? Or hope of it getting merged into an upcoming release?
Hey @andersfalk
Thanks for a great first bug report, test cases like you provided are always super helpful!
When I’ve got a computer turned on i’ll take a look into things and report back.