Here's what I'm looking to do :

Suppose you have a 3x3 grid, with each box in the grid being a vector. I want to make a new layer on top of that in which each column of 3 boxes is its own vector in the new layer. I'm interested in doing this for all of the vector data in the previous layer (i.e. grouping it into larger chunks).

How do I do that?

Using QGIS for desktop.

  • 1
    Step 1: Tell us which software you're working with.
    – Erik
    Oct 19, 2021 at 12:00
  • QGIS for desktop. My bad, I thought I was on a different stackexchange. Fixed it.
    – James G.
    Oct 19, 2021 at 12:08
  • Is there an attribute telling the row/column of each feature?
    – JGH
    Oct 19, 2021 at 12:11
  • Unfortunately, no.
    – James G.
    Oct 19, 2021 at 12:19
  • 1
    By a 3x3 grid you mean 9 feature to be grouped in 3 rectangle column ? If yes doing it manually is probably the quickest way
    – J.R
    Oct 19, 2021 at 12:44

1 Answer 1


You can achieve this using a virtual layer.

Go the the menu layer / add layer / add-edit virtual layer and enter the following query.

WITH src AS (
  SELECT min(st_minx(geometry)) AS startX 
  FROM Grid)
SELECT st_union(geometry), 
       round(((st_minx(geometry)-startX)/3)-0.5) AS col
FROM Grid,src
GROUP BY round(((st_minx(geometry)-startX)/3)-0.5)

It starts by computing the grid origin. Then it selects every geometry from the Grid (that's the name of the layer, feel free to change it), takes each geometry origin, remove the grid origin from it and at last it group them in groups of "3" units wide.

PS: round(x-0.5) is the same as the (unavailable) floor(x) function

enter image description here

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.