2

In QGIS I create some lines that cross three polygons. By using intersection, it will create a new shapefile that gives me as a result the lines inside the three polygons.

If I open the attribute of the intersection layer I can see that different line ID have same polygon ID (obviously because multiple lines cross the same polygon). By looking I can tell how many lines are inside a polygon but how can I do this automatically?

I would like to modify the polygon layer attributes by adding a new column with the number of lines crossing each polygon (so the polygon layer will have only two column: "ID" and "number of lines").

nmtoken
  • 13,355
  • 5
  • 38
  • 87
lausent
  • 219
  • 2
  • 7

1 Answers1

1

If you store the result of the intersection into a sql database (SQLite is sufficient), you can use "group by" and "count" to query how many there are.

select polygon_id, count(*) as number_of_crossing_lines
from line_crosses_poly
group by polygon_id
til_b
  • 5,074
  • 1
  • 19
  • 36