[GIS] QGIS split line into segments on polygon

linepolygonqgissplitting

Is it possible in QGIS to split a line into segments given which polygon it falls within? I am using 2.8.

For example, a line that passes through three polygons will become three separate lines. Each time it crosses from one polygon into another it'd become a new line.

So in this case, where the green is a line, I would like to split it into three separate lines. Once for each time it crosses the black border of a polygon.

Line to be split

Best Answer

[QGIS 2.8] Use the Intersect tool menu : "Vector / Geoprocessing tools / Intersect" (from Miro's answer in comments)

[QGIS 2.18] Use the Intersection Tool in the processing toolbox/panel :

Intersect tool

This algorithm extracts the overlapping portions of features in the Input and Intersect layers. Features in the Intersection layer are assigned the attributes of the overlapping features from both the Input and Intersect layers. Attributes are not modified.