block by rveciana e0565ca3bfcebedb12bbc2d4edb9b6b3

Turf multiline and polygon intersection

Full Screen

The previous example showed how to intersect a line with a polygon, but the situations can be more complicated, as shown in this example.

The solution is using the lineSplit function for each part of the multilinestring and selecting the ones that fit the needs. The first part can be inside or outside the polygon, depending on the first point. Detecting this, is easy to get only the needed parts.