Clipping line layer to every feature of polygon layer in QGIS?

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..


Python would be the best way to do this. If you perform one clip you can copy the python snippet from the Geoprocessing results and 'build' code snippets for the remaining 59 using concatenate in excel


Using ArcGis, no programming needed:

1 - Apply intersect, so all your network will take a unique cod for each district.

2 - Open model builder, under menu insert chose "Iterators\Row Selections"

3 - Right click on row selection and create two Model Variable (1-Input Table 2-Group By Field)

4 - Double click on Input table and chose created shapefile from Intersect command.

5 - Double click on group by field and chose the unique key of districts.

6 - open toolbox under Data management\Feature chose copy feature drag and drop it into model space.

7 - Link your selected feature of "Row Selections" with "Copy Feature" as input feature.

8 - On output chose your geodatabase where u want to save your shapefile dont forget to rename it "....your path.gdb\yourname_%VALUE%". %VALUE% is very import to rename all your new shape file with your unique code.

Your model would look like.

enter image description here