0

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.

Babel
79.7k15 gold badges96 silver badges244 bronze badges
asked Oct 19, 2021 at 11:56
6
  • 1
    Step 1: Tell us which software you're working with. Commented Oct 19, 2021 at 12:00
  • QGIS for desktop. My bad, I thought I was on a different stackexchange. Fixed it. Commented Oct 19, 2021 at 12:08
  • Is there an attribute telling the row/column of each feature? Commented Oct 19, 2021 at 12:11
  • Unfortunately, no. Commented 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 Commented Oct 19, 2021 at 12:44

1 Answer 1

3

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

answered Oct 19, 2021 at 12:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.