16

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

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
ustroetz
  • 7,994
  • 10
  • 72
  • 118
  • What version of QGIS are you using? – artwork21 Nov 28 '13 at 02:44
  • 2.0.1-Dufour on OS X 10.9. – ustroetz Nov 28 '13 at 03: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 06:57
  • can you please indicate where and how to transform from multistring to a singleparts? thanks – Patribus Apr 10 '14 at 07:49
  • 1
    @Patribo In QGIS go to Vector -> Geometry Tools -> Multipart to singleparts – ustroetz Apr 10 '14 at 12:26
  • Just a note for someone totally new to QGIS (or as dense as me in finding things!)... the polygon drawing tool is on the edit dropdown menu... took far too long to find. (And as noted, you need a layer first to put the polygon in, generally Layer>Create Layer>Temporary Scratch Layer)... then Vector>Geoprocessing Tools>Clip and pick the Input Layer you want to clip and use your temporary layer as the output. – JeopardyTempest Sep 14 '20 at 19:00

3 Answers3

14

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"

Nathan W
  • 34,706
  • 5
  • 97
  • 148
  • I tried that. I only get an empty shapefile. What could be wrong? – ustroetz Nov 28 '13 at 00:59
  • 1
    Are they the same projection? – Nathan W Nov 28 '13 at 01: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 01: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 06: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
  • Thanks Nathan, I tried your suggestion, but only Brideau's suggestion (in another answer) worked for me. Thanks anyways. – Tilek May 22 '17 at 08:31
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.

Brideau
  • 550
  • 3
  • 12
3

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.
MrXsquared
  • 34,292
  • 21
  • 67
  • 117
Joel Talay
  • 31
  • 1