Skip to content

Split polygon by LineString #2844

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

Open
sasos90 opened this issue Feb 24, 2025 · 1 comment
Open

Split polygon by LineString #2844

sasos90 opened this issue Feb 24, 2025 · 1 comment

Comments

@sasos90
Copy link

sasos90 commented Feb 24, 2025

Hey!

I am busting my head off for a few days already. So I am trying to split the polygon with the LineStrings and nothing on the internet can really help, as for what I have found is usually using the turf.union(polyLine, line) operation, which clearly is not possible. Union only works with Polygons and i have checked all the version in the past, and I haven't found the way where I could simply provide two lines to union function.
What I usually find is a process like this:

const polyAsLine = turf.polygonToLine(poly);
const unionedLines = turf.union(polyAsLine, line);
const polygonized = turf.polygonize(unionedLines);

So what is the best way to split polygon with the line?
Please help my day :D

Thanks a lot!

@tohu12
Copy link

tohu12 commented Mar 24, 2025

You can try this:

const bufferedLine = buffer(line, 0.000001)
const splittedPolygon = difference(featureCollection([polygon, bufferedLine]))
const flattenPolygons = flatten(splittedPolygon)

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

2 participants