question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

lineSplit doesn't split correctly

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rowanwinscommented, Jan 22, 2018

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.

0reactions
crubiercommented, Jan 27, 2021

Related issue: https://github.com/Turfjs/turf/issues/2023

The function above uses lineSlice, but lineSlice is super imprecise

Read more comments on GitHub >

github_iconTop Results From Across the Web

The line is splitting at the wrong place - python - Stack Overflow
I want the line to split at the ',' but it splits each character even when the .split() function has a parameter. Can...
Read more >
Line feeds not splitting correctly - Power Platform Community
Solved: Hi, Further to my previous post regarding importing a text file that has been converted from a csv file, microsoft sees the...
Read more >
String split function not working properly. Any suggestions ...
Specifying -1 as the second parameter in the split method considers the "empty" while splitting a string to a list or an array....
Read more >
string.Split doesn't work with multiple separator characters
My gut feeling is that @('x', 'y') is converted to a string and an incorrect overload of String.Split from the runtime is called...
Read more >
Split a String Only on the First Occurrence of Delimiter
User management is very complex, when implemented properly. No surprise here. Not having to roll all of that out manually, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found