Change an attribute in QGIS if a line intersects a polygon

Let's assume that you want to know if a line intersects a polygon in QGIS and change an attribute accordingly. For example, let's suppose that you have the following map:

Lines and polygons

Vector > Geoprocessing Tools > Intersect and select both layers

QGIS intersection

At this point you'll have another layer with the intersected lines:

QGS intersected lines

As you want to modify the 'Lines' layer:

Vector > Research tools > Select by location

Select features from 'Lines' where the features intersect with 'Intersection'. At this point, all the lines from the 'Lines' layer that intersect with the polygons are selected.

Open the attributes table from 'Lines' and filter by 'Selected elements' at the bottom. Now you can change the attributes from the 'Lines' layer that intersect with the polygons.

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.