Skip to main content
Improved code
Source Link
Detlev
  • 4.7k
  • 19
  • 26
areas = []
for line_feature in line_layer.getFeatures():
    for area_featurecands in= area_layer.getFeatures(QgsFeatureRequest().setFilterRect(line_feature.geometry().boundingBox()))
    for area_feature in cands:
        if line_feature.geometry().intersects(area_feature.geometry()):
            areas.append(area_feature.id())

area_layer.select(areas)

If polyline geometry is complex filtering the area feature by the bounding box of the polyline may increase the perfomance. See link provided by @juls.

areas = []
for line_feature in line_layer.getFeatures():
    for area_feature in area_layer.getFeatures():
        if line_feature.geometry().intersects(area_feature.geometry()):
            areas.append(area_feature.id())

area_layer.select(areas)

If polyline geometry is complex filtering the area feature by the bounding box of the polyline may increase the perfomance. See link provided by @juls.

areas = []
for line_feature in line_layer.getFeatures():
    cands = area_layer.getFeatures(QgsFeatureRequest().setFilterRect(line_feature.geometry().boundingBox()))
    for area_feature in cands:
        if line_feature.geometry().intersects(area_feature.geometry()):
            areas.append(area_feature.id())

area_layer.select(areas)
Source Link
Detlev
  • 4.7k
  • 19
  • 26

areas = []
for line_feature in line_layer.getFeatures():
    for area_feature in area_layer.getFeatures():
        if line_feature.geometry().intersects(area_feature.geometry()):
            areas.append(area_feature.id())

area_layer.select(areas)

If polyline geometry is complex filtering the area feature by the bounding box of the polyline may increase the perfomance. See link provided by @juls.