I have a line layer and a polygon layer. Both files have the same SRS. I want in a new shape file only the lines covered by the polygons.

I tried in QGIS the Vector -> Geoprocessing -> Clip tool but I only get an empty shapefile.

How do I do this with QGIS?

enter image description here

  • What version of QGIS are you using? – artwork21 Nov 28 '13 at 2:44
  • 2.0.1-Dufour on OS X 10.9. – ustroetz Nov 28 '13 at 3:47
  • 2
    It turned out that my line layer is a multistring and the QGIS clipper doesn't process multistring properly. I converted it to singleparts and then it worked. – ustroetz Nov 28 '13 at 6:57
  • can you please indicate where and how to transform from multistring to a singleparts? thanks – Patribus Apr 10 '14 at 7:49
  • 1
    @Patribo In QGIS go to Vector -> Geometry Tools -> Multipart to singleparts – ustroetz Apr 10 '14 at 12:26

Use the Vector -> Geoprocessing -> Clip tool

Input is your roads layer, clip layer is the polygon layer.

enter image description here

Put the line's layer in "input vector layer" and the polygon's layer in "Clip layer"

  • I tried that. I only get an empty shapefile. What could be wrong? – ustroetz Nov 28 '13 at 0:59
  • 1
    Are they the same projection? – Nathan W Nov 28 '13 at 1:02
  • Yes, they are. And if I do it the way you showed (Input vector layer = polygon, Clip layer = line), I get the same polygon layer in return as I put in. – ustroetz Nov 28 '13 at 1:07
  • 2
    The problem was that my line layer was multistring and the clipper didn't process that properly. After converting it to singleparts it worked they way you described it. – ustroetz Nov 28 '13 at 6:58
  • I was also returning an empty shapefile. My problem was I had failed to stop editing my newly created mask layer. – Ben Mayo Mar 26 '15 at 10:13

This gave me endless hours of frustration, and the above answers (even the ones in the comments) didn't work for me either, but I found my own solution that did the trick.

It turns out that to do an intersection or a clip between two layers, they must be saved on disk with the same CRS. So even if they look like they overlap in QGIS, it may be doing it's own "On the Fly" transformation to align them.

To fix this, do this for each layer:

  1. Right click, Save as...
  2. Set the format to ESRI Shapefile, pick a file name, and pick a CRS that you will use for all the layers. Click OK to save, and load that file.
  3. Repeat for the other layer, selecting the same CRS.
  4. Use the clip tool with the new layers. This should do the trick.

If you want to see if the 'On the Fly' transformation is what's causing you trouble, do this:

  1. Go to the Project menu, and click Project properties...
  2. Go to the CRS tab
  3. Uncheck Enable 'on the fly' CRS transformation and click Apply, OK

If your CRS's weren't the same, the layers should no longer overlap. You can see the position of either layer by right-clicking the layer and going to Zoom to Layer. When you load the two files with identical CRS, they should align perfectly.

  • Suggestion by Nathan W did not work for me and your suggestion worked, thanks. – Tilek May 22 '17 at 8:30

Use the intersect feature. Vector > Geoprocessing Tools > Intersect.

  • Input layer is your line
  • Intersect layer is your polygon
  • browse a document folder and save (preferred filename) in the Output Shapefile.

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.