[GIS] Clipping line layer to every feature of polygon layer in QGIS

clippolygonqgisqgis-modeler

I have a line layer (roads) and a polygon layer which represents districts/counties. I want to clip the roads according to every one different county. That means that I must repeat the procedure sixty times as the total count of districts is 60. (I must select one different district (feature of polygon) every time and then Vector -> Geoprocessing -> Clip). Is there any possible way this procedure to become automatic? I work in QGIS (and ArcGIS).

Best Answer

You can create a model from the Processing Toolbox which allows you to automate a number of tasks.

You can create one by going to the menubar:

Processing > Graphical Modeler...

From the Inputs tab (shown in the red box), you will need two Vector layer parameters (shown in the blue box) for both your line and polygon layers.

Model

Then from the Algorithms tab (shown in the red box), type in "clip" to search for your Clip tool. Then select the relevant options:

Clip options

Don't forget to type a name for the model and group shown in the green box. Save it and load the Processing Toolbox interface which can be enabled from the menubar: Processing > Toolbox.

Then find your model from the toolbox which should be under Models (or you can type in the name of your model in the search box). Now when you run it, click the green round-arrow button next to the polygon input layer to iterate through each polygon feature:

Running model

When you run it, the road layer will clip onto each polygon feature and the results will be loaded.


Note: I have tested this on a simple example and it worked fine. Tested with QGIS 2.16.0-Nødebo with Processing plugin v2.12.2, Win7 64-bit..

Related Question