Skip to content

unkinkPolygon cant deal with duplicate coordinates #2912

@laundmo

Description

@laundmo

This is basically a re-opening of:

As that was closed by the author without any fix 6 years ago.

unkinkPolygon throws an error The input polygon may not have duplicate vertices (except for the first and last vertex of each ring) when run on a polygon with duplicate vertices.

Reproduction using an hourglass shape, where the center has 2 stacked vertices:

const hourglass = turf.polygon( [[
    [0,0],
    [1,1], // center
    [2,2],
    [0,2],
    [1,1], // center
    [2,0],
    [0,0]
]]);

// all of these error
turf.unkinkPolygon(hourglass)
turf.unkinkPolygon(turf.cleanCoords(hourglass))
turf.unkinkPolygon(turf.simplify(hourglass, {tolerance: 0.5}))
turf.unkinkPolygon(turf.simplify(hourglass, {tolerance: 0.5, highQuality: true}))
Image of the shape

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions