0

Having a linestring and a polygon, Is there a way to clip the linesegment at the boundary of the polygon and retain the shape of the linestring which runs inside the polygon?

Example Linestring

{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "LineString", "coordinates": [ [ -43.154296875, 38.34165619279595 ], [ -11.42578125, 46.13417004624326 ] ] } } ] }

Example Polygon

{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "Polygon", "coordinates": [ [ [ -35.947265625, 28.998531814051795 ], [ -21.62109375, 28.998531814051795 ], [ -21.62109375, 48.3416461723746 ], [ -35.947265625, 48.3416461723746 ], [ -35.947265625, 28.998531814051795 ] ] ] } } ] }

I want to know how I can clip the linesegment which crosses the polygon as a separate feature? I tried turf's lineSplit and lineIntersect. But was not able to combine multiple functions to get the required output. Trying to understand turfs functions. Any help will be very helpful.

Thnak you.

0

Combine multiple functions? I'm surprised that lineSplit() didn't work for you, since that's the answer to "how do you clip a line with Turf.js?" Were you receiving an error, and could you share your code here?

If the polygon is giving you trouble, you could convert it to a line first with polygonToLine().

lineIntersect() returns the points of intersection between input features, so I don't think that you'll need it to accomplish this task.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.