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.
-
1Step 1: Tell us which software you're working with.Erik– Erik2021年10月19日 12:00:02 +00:00Commented Oct 19, 2021 at 12:00
-
QGIS for desktop. My bad, I thought I was on a different stackexchange. Fixed it.James G.– James G.2021年10月19日 12:08:05 +00:00Commented Oct 19, 2021 at 12:08
-
Is there an attribute telling the row/column of each feature?JGH– JGH2021年10月19日 12:11:48 +00:00Commented Oct 19, 2021 at 12:11
-
Unfortunately, no.James G.– James G.2021年10月19日 12:19:21 +00:00Commented Oct 19, 2021 at 12:19
-
1By a 3x3 grid you mean 9 feature to be grouped in 3 rectangle column ? If yes doing it manually is probably the quickest wayJ.R– J.R2021年10月19日 12:44:17 +00:00Commented 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