Q:

Count how many times an attribute in a polyline intersects a polygon in QGIS

I am trying to count how many times a polyline with a specific attribute intersects a polygon in QGIS. For example, I have a polyline with a feature class called "size", this contains a text value i.e. small, medium & large. I have also made a grid of 100m x 100m squares.
I would like to be able to count how many "large" polylines intersect each grid square polygon, and then repeat this for "medium" etc.

A:

In database/DB manager/Virtual Layers/Qgis layers you can try the following query :
select count(*), line_id, grid_id from line_layer, grid_layer
where st_intersects(line.geometry, grid_geometry)
and line.width='large'
group by grid_id

You'll have to adapt the attributes according to your data structure.

