-1

I have two layers in QGIS:

  1. "line" layer which consists of lines and multi-lines
  2. "Point" with points with attribute 'Code'

How to write a efficient script in PyQGIS to find out all the lines at whose

  • start point, there is a point with Code value "1" and
  • end point, there is a point with Code value "1"

enter image description here

Vince
  • 20,017
  • 15
  • 45
  • 64

1 Answers1

1

You could add a Virtual Layer Layer|Add Layer|Add/Edit Virtual Layer... with the Query:

SELECT L.*
FROM "LineLayer" AS L, "PointLayer" AS P1, "PointLayer" AS P2
WHERE ST_Intersects(ST_PointN(L.geometry, -1), P1.geometry)
AND ST_Intersects(ST_PointN(L.geometry, 1), P2.geometry)
AND P1."Code" = 1
AND P2."Code" = 1

You would need to substitute "LineLayer" and "PointLayer" with the correct layer names.

This will select all the lines where the start point ST_PointN(L.geometry, 1) and end point ST_PointN(L.geometry, -1) each intersect points in the "PointLayer" where the "Code=1".

Taras
  • 32,823
  • 4
  • 66
  • 137
M Bain
  • 2,042
  • 8
  • 12