1

How do I perform gap analysis with line and polygon layer in QGIS?

I have 2 vector layers. The first vector layer has line features and second layer has polygon features as in the following images.

Figure 1: Vector Layer with Line features

Figure 2: Vector Layer with Polygon features

Overlapping Lines and Polygon features

I am trying to perform a gap analysis that is cutting the lines at segments the polygons do not overlay the lines in QGIS.

Shapefiles of line and polygon layers are accessible from the following link: https://drive.google.com/drive/folders/11GhQODoPby9SCnp9WcydOBJHVS3O1Lsv?usp=sharing

1
2

As your polygon layer has invalid geometries, you have to run first this method of Processing tool (Fix geometries). Both layers (I named Polygons as Polygons_fixed) loaded in QGIS look as follow.

enter image description here

Afterward, you need to run Difference Processing tool with following parameters:

enter image description here

After click in Run, resulting layer looks as follow. I used an opacity of 20 % in Polygons_fixed for corroborating that produced line layer effectively corresponds to lines which do not overlap.

enter image description here

1

A simpel example cutting the lines not intersecting a polygon using QGIS Virtual Layers.

select p.id, st_intersection(l.geometry, p.geometry) as geometry 
from test_line l
inner join test_poly p on st_intersects(l.geometry, p.geometry) 

Input a linestring and three polygons.

enter image description here

New virtual layer with linestring intersecting polygons.

enter image description here

2
  • 1
    I think OP wants the contrary: the part of the lines that do not overlap the polygons. – Babel Jan 22 at 9:21
  • Yes. I am looking into the method to find lines which do not overlap. – HansrajR Jan 22 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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