5

I have a polygon layer 'lot' containing an attribute "lot_number". Then, I want to create a Virtual Layer that merges some of the lots while keeping others separated, as the diagram shows below.

Specifically, in the virtual layer, I want to merge the lots with "lot_number" 1, 2 and 4 into one polygon, and ones with "lot_number" 5 and 6 into another polygon. How could I do that?

enter image description here

3

I figured this out. First you need to create a new field merged_ID in the lot layer, giving a unique ID to each group of polygons to be merged. The attribute table would look like this:

enter image description here

Then type the following query in the virtual layer creation window:

select st_union(geometry), l.*
from "lot" as l
group by l."merged_ID"
| improve this answer | |
  • 1
    When working with a single layer there is no need in an alias i.e. from "lot" as l, simply from "lot" – Taras Sep 21 at 5:59

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.