Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

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

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

Already on GitHub? # to your account

Round corners of LineString/Polygon #2352

Closed
asindl opened this issue Oct 18, 2022 · 6 comments
Closed

Round corners of LineString/Polygon #2352

asindl opened this issue Oct 18, 2022 · 6 comments
Labels

Comments

@asindl
Copy link

asindl commented Oct 18, 2022

Hi there,
I am looking for an easy to use way to round corners of linestrings or polygons. Similar to the bezierSpline function, one could apply the "roundCorner" function to a linestring or polygon with a defined radius in the options which would then return the linestring/polygon with rounded corners.

Is that a meaningful feature for turf?

@rowanwins
Copy link
Member

Hi @asindl

You might want to take a look at the @turf/polygonSmooth module.

It currently doesn't work with LineString's but from memory the underlying algorithm could be extended to support that.

And there is probably other algorithms out there for smoothing which might output slightly different shapes - as there isn't really one 'correct' output, it just depends a bit on what you're expecting.

Hope that helps

@asindl
Copy link
Author

asindl commented Nov 7, 2022

Thanks, @rowanwins.
The polygonSmooth isn't exactly doing, what I am looking for (defined curve radius to smooth corners), but thanks for the suggestion to look at the source code and adapting it to my needs.

@deflectn
Copy link

deflectn commented Oct 16, 2024

It is possible to achieve this with multiple buffer operations.

const feature: Feature = 
const cornerRadius = 8;

// 1. increase geometry by radius without smoothing
feature.geometry = turf.buffer(feature.geometry, cornerRadius, { steps: 0 }).geometry;

// 2. decrease it by doubled radius with smoothing
feature.geometry = turf.buffer(feature.geometry, -(cornerRadius * 2), { steps: 8 }).geometry;

// 3. finally increase geometry again by radius with smoothing
feature.geometry = turf.buffer(feature.geometry, cornerRadius, { steps: 8 }).geometry;

Logical Steps

Maybe this logic could get wraped into a default function.

@smallsaucepan
Copy link
Member

@deflectn this might be enough justification for us to start a "tips and techniques" section on the website.

@smallsaucepan
Copy link
Member

Or perhaps @deflectn would you like to put together a PR for a new roundCorners module?

@deflectn
Copy link

Probably I could schedule it for Christmas time. 😉

@Turfjs Turfjs locked and limited conversation to collaborators Dec 25, 2024
@smallsaucepan smallsaucepan converted this issue into discussion #2794 Dec 25, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

5 participants