4

I have a line file and a polygon file in QGIS.

Primarily I am looking for any polygon that has a line intersecting it - easy, sorted.

From these intersects, I then want to pull out just the polygons that have a line going all the way through them and ignore those where the line ends within the polygon. See the below diagram for an explanation: I only want polygons 2 and 3.

Example

Does that make sense? I haven't managed to find any predefined tools thus far.

1 Answer 1

6

There is a possibility using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...

Let's assume we have two layers, namely 'lines_test' and 'polygons'

Input

With using this query it is possible to differentiate between line ending within polygon and line passing all the way through polygon.

SELECT *
FROM polygons
WHERE polygons.id NOT IN (
    SELECT polygons.id
    FROM polygons, lines_test
    WHERE ST_Within(ST_StartPoint(lines_test.geometry), polygons.geometry)
          OR ST_Within(ST_EndPoint(lines_test.geometry), polygons.geometry)
)

Output


References:

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.