Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sliver Polygons #18

Open
leonthoma opened this issue Dec 21, 2023 · 6 comments
Open

Sliver Polygons #18

leonthoma opened this issue Dec 21, 2023 · 6 comments

Comments

@leonthoma
Copy link

First up, thanks for creating and maintaining this great package !

I've been using the smooth function on some SpatVectors containing polygons with different values, and noticed that it introduces sliver polygons. The geometry itself is valid, but running terra::gaps() returns said sliver polygons. Unfortunately, the sliver polygons can become quite large, especially when three or more polygons with different values are next to each other, so using terra::snap() couldn't solve the problem.

Here's a sample of the unsmoothed polygons I found the smoothing function has an especially hard time with
unsmoothed

Here's a picture of the same polygons after smoothing and the different sliver polygons that were introduced.
slivers

Finally here's what the result I'm striving for would look like (using the ArcGIS Smooth Polygon tool).
arc_smooth

I'm not sure if this is beyond the intended scope of the package, but I thought it won't hurt to point out the issue. I would love to help working on the issue, so please let me know if you are interested in solving the issue.

@mstrimas
Copy link
Owner

Thanks for pointing this out, it's definitely not ideal! I'm not too surprised this happens since the package treats every polygon individually, so there's essentially no effort to preserve the topology between features. It would definitely be nice to solve this, but to be honest, I don't have any ideas for ways to do this in a simple way. Do you have any thoughts?

@odgersn
Copy link

odgersn commented Jan 15, 2024

I thought I would chime in and say that I haven't noticed sliver polygons, but I do get gaps between polygons like in the second image above.

In terms of solving the issue: it has been suggested to me that a way to do it would be to decompose the polygons into shared line segments and do the smoothing on the line segments. Then you would have to reconstruct the polygons afterward.

@mstrimas
Copy link
Owner

Thanks for the suggestion! I doubt I'll have the time to implement a fix, but if I do have some spare time, this seems like a viable path.

@leonthoma
Copy link
Author

leonthoma commented Jan 17, 2024

Sorry for the late reply ! Didn't find as much time as I expected in my current project.. Anyways as @odgersn pointed out, using linesmoothing does help, albeit only in situations where there are a no more than two polygons of different classes.
Original polygons (2 classes)
line_2_poly

Smoothing decomposed lines instead of polygons (2 classes)
linesmooth_2_poly

Original polygons (3 classes)
line_3_poly

Still problematic smoothed polygons (3 classes)
linesmooth_3_poly

One problem that still persists even with linesmoothing and only two unique polygon classes is which polygons should be connected (see 2nd example). This could be solved by an additional argument, such as connect largest/smallest/etc. polygons

@leonthoma
Copy link
Author

Also I'm curious as to why @odgersn didn't get sliver polygons. Have you checked it with terra::gaps() ? Would be very interested since this could mean there is something wrong with my data..

@FraLessard
Copy link

I'm also interrested in the issue and an implemented version of polygon snapping among smoothr package. For now, I'm using the ms_simplify function from the rmapshaper package with a keep parameter of 1 (100 %) and a snap_interval of 10.

polygons_selected %>% smoothr::smooth(method = "ksmooth", smoothness = 1) %>% rmapshaper::ms_simplify(keep = 1, snap = TRUE, snap_interval = 10) -> polygons_simplified

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants