mapshaper icon indicating copy to clipboard operation
mapshaper copied to clipboard

Spikes/Slivers inside Polygons Not Cleaned Perfectly

Open bsaid97 opened this issue 5 months ago • 4 comments

I am trying to clean some polygons that have, what I would call, spikes or slivers within the outer boundary.

Image

Closer look

Image

-clean does a good job at handling most of these but this example seems to be a bit more stubborn, I haven't been able to clean it successfully. Any help would be appreciated.

Polygon is attached

problematic.json

bsaid97 avatar Jul 22 '25 09:07 bsaid97

Thanks for this, I'll investigate.

mbloch avatar Jul 23 '25 17:07 mbloch

I think I see what's happening. A spike along the boundary of a polygon can have one of two forms: an overlap or a cut-in shape. If you zoom in to your example area, you can see that the spike that wasn't removed forms a cut:

Image

The -clean command does not remove cuts, only overlaps. (The common definition of a clean or valid polygon requires that boundaries do not self-intersect, so overlaps are not allowed but cuts are allowed).

I can convert the cut into an overlap using the "draw/edit polygons" option:

Image Image

... if you run -clean again, then the overlap is removed:

Image

... this isn't a practical solution to your problem, however...

mbloch avatar Jul 24 '25 17:07 mbloch

I'd like to add the ability to remove sliver-shaped cuts, but that will require a bit of R&D work.

mbloch avatar Jul 24 '25 17:07 mbloch

Thank you for your investigation @mbloch !

For a little more context, my main issue is that when I try to insert this feature into my mongo database I get the folowing error.

] Edges 1420 and 1422 cross. Edge locations in degrees: [51.3480136, 3.8869813]-[51.3478703, 3.8861762] and [51.3479016, 3.8863525]-[51.3479427, 3.8863429]

Here are the supposed edges that cross. Might there be some function already available that would fix these edges?

Image

So it might not even be the sliver necessarily I think, just some way the coordinates are ordered perhaps.

bsaid97 avatar Aug 26 '25 07:08 bsaid97