Skip to content

lineSplit doesn't split correctly #1232

@andersfalk

Description

@andersfalk

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions