My dataset comprises many polygons representing workspaces over a large area:

-1 vector layer comprising my polygons (each polygon ID appears 1 time)

For my online atlas however I need to obtain a pivot table layer as follows :

-1 pivot table listing all the polygon couples less than 300 meters apart (each polygon ID appears over more than 1 line depending the nb neighbor polygons). I have no clue how to obtain this in QGIS.


If you are familiar with SQL, you can make a virtual layer based on following reason: If you buffer each polygon with 300 meters, you can do an intersect to couple all neigbouring polygons within a given distance.

in code this gives:

    from polygonlayer a, polygonlayer b
    where st_intersects(a.geometry, st_buffer(b.geometry, 300)) and a.id != b.id

Put this code in a virtual layer (layer > add layer > add virtual layer) and check 'autodetect'.

enter image description here

This gives following result:

enter image description here

You can use that table as coverage layer in the print composer.

  • Thanks ! Small question, Is there any way to save the data in this layer non-virtually ? I need to add a few things manually and use it to create relationships in lizmap.
    – Lay
    Apr 26 '18 at 13:10
  • Yes, you can save this result (right-click and choose save as...) in whatever format you want.
    – PieterB
    Apr 27 '18 at 19:47

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.