I am in the process of making the database for 9 consecutive years in 150 local administrative units. To do that I have to clip 9 line layers (roads for 9 years) with 150 polygon layers.

So far I have been doing it with the clipping tool in Batch process, but there are several problem I would like to solve a bit more easier.

Problem 1) When I clip the line layers I have to manually update the length of the lines. Since there are 1350 cases (9 years x 150 administrative units), it would take me a 2-3 days of repetitive and boring work that I would like to avoid. (Question 1) So the question is if there is any tool/plugin that can clip multiple line layers with multiple polygon layers and create separate new line layers for every year and administrative area. (Question 2) Or, is there any tool/plugin to update all the new layers at the same time

Problem 2) When I am done with clipping and updating of the line lengths, (Question 3) is there any tool/plugin that allows me to export all the line layers into one excel or CSV file?

I am using QGIS Desktop 3.10.2 with GRASS 7.8.2

  • 1
    I dont understand exactly what data you have (a screenshot would help) but: Why dont you merge the 9 line layers into 1, and the 150 polygon layers into 1 and then clip or intersect once? Then calculate line length and split the output by year and adm unit?
    – BERA
    Mar 31, 2020 at 11:06
  • My data is about roads. If I merge it into 1 layer, will each line merge into one? Each road has the same label in each year, but not the same length. Also, I do have one layer with 150 polygons, but I do not know how to get such table: Area 1
    – Josip G
    Mar 31, 2020 at 11:11
  • 1
    No they will still be separate lines but in the same layer. But you would have to have some attribute (for example year) to later be able to split by. Add a year field to the 9 line layers and field calculate Before merge.
    – BERA
    Mar 31, 2020 at 11:12
  • Great. I did not came to that idea. And how am I going to get data for every area when they are in the same polygon layer?
    – Josip G
    Mar 31, 2020 at 11:19
  • 1
    I think Intersect should work.
    – BERA
    Mar 31, 2020 at 11:22

1 Answer 1


If I were you, I would say that your easiest and best bet is creating a new data column that attributes year (for the lines) and administrative units (for your polygons) and merge all layers that have the same geo type (lines all clump together and polys all clump together). Once this is done, you can easily extract your outputs layers and drop the busy work.

Line lengths are easily automatically calculated using the QGIS field calculator (built in function called length). Once you have combined everything with your new data columns you can just do one clip and one length calculation. Then where the work comes out is simply with some queries('Select features using an expression) so export these new CSVs for each year (or however you are exporting them).

Hope this helps.

  • Thanks. User BARA gave me that idea. I have done the first part (merging of lines). Merging of polygons would make it much more easier for me, but I don't know the function that would calculate the line lenghts in 150 areas of the merged polygon. Intersection was not it, or i am doing something wrong. Field calculator functio is $length/1000 (for km).
    – Josip G
    Apr 1, 2020 at 5:28
  • 1
    Are you trying to find the total length of lines inside each of the 150 polygons? Like for every line that falls within this polygon, what is the total length? Or the length of each line which falls inside of each polygon?
    – Sven
    Apr 1, 2020 at 10:12
  • Length of each line which falls inside of each polygon. It means, if one line goes throught three polygons, i want to calculate the length of the line for each poygon.
    – Josip G
    Apr 1, 2020 at 13:06
  • 1
    Yeah so this works then. You make a new piece of data to be pull things back out and smush all polygons together and all lines together and then do a clip of the lines by polygons, calculate the lengths of each ( you will have to name the length column with the polygon number/name) then combined the lines again using their defining feature (name, ID, etc.). When you do this you will have your original lines with new columns of their lengths in each of the different polygons they cross. The table will be large but that should work
    – Sven
    Apr 10, 2020 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.