I have two polygon layers which I want to union. One layer (1) is just one big feature, the other (2) contains 250’000+ features. Layer 1 was created this way: Several polygons --> fix geometry --> dissolve. Layer 2 contains the original features but geometry fixed. Both layers are the same CRS, are stored in a separate GPKG and were originally delivered as a ArcGIS GDB (which first I exported to a GPKG).

Now, if I use the QGIS union tool, it takes more than 15 hours to complete (I don’t know how much, but after 15 hours I escaped).

I also tried to split the process by splitting the big polygon to 60 polygons. Then with PyQGIS I created a loop where both layers get filtered (setSubsetString: they have a common field-value for overlapping polygons) and then executed the union. This is still very slow – it takes around 2 to 3 hours for one union to complete.

So I tried to union the layers with GRASS v.overlay “Operator = or”. This works a lot faster. The problem is that it doesn’t create the same output: If layer 1 overlaps layer 2 the way that layer 2 is on the left AND the right side of the overlapping layer 1, it creates 3 polygons: layer 2 on the left, the overlapping part and layer 2 on the right. I would need it to create just one polygon for the non-overlapping part.

Is there a way to tell the v.overlay-tool to create just one polygon per layer, if it gets cut by the other layer?

I also tried to then dissolve the v.overlay result. The problem with this solution is, that I would need it to do the dissolve over approx. 10 fields/columns. But in the v.dissolve as well as the other dissolve tools I found in QGIS, I couldn’t figure out how to use 10 fields to dissolve a layer.

Any suggestions?

Edit: Here you can download some sample data. Layer 1, layer 2 and the solution, how the generated file should look like (solution_after_union).

It is essential that the file in the end still contains all the columns as in the solution file (except “GENRE” and it could also be only one of the two fields “fid_2” and “NOM”). The most important thing is that the process creates multipart-features.

I try to explain it as follows: The polygons of layer 2 (parcels) should be max. two polygons after the union-process. Which means that if the forest cuts a parcel (see “NUMERO” 626, 628, 629), the result should be one single-part-polygon which contains the part where the forest overlays the parcel and one multipart-polygon which contains both non-forest parts of the parcel. Same thing the other way around: if the forest is on both sides of the parcel (see “NUMERO” 625), the result should be one multipart-polygon, which contains both forest-parts overlaying the parcel, and another singlepart-polygon, which contains the non-forest part of the parcel. Obviously if there are several parts of forest overlaying one parcel the way the non-forest part of the parcel gets split up in several parts as well, the result should be two multipart-polygons.

The purpose of all this:

Farmers in Switzerland have to declare how they plough every single parcel. What they grow: e.g. if they produce wheat, soy, hay, let the animals grass, etc. But also “non-food” things like forest, trees or similar stuff.

The data I use for my union-task is from the Swiss cadastral survey. It says whether the land is grassland/crops or non-productive (which I declared as forest to make it simple).

Now I want to visualize what the farmers declare. If they declare “non-food” I want to join the data of what they grow to the “forest”-part of the parcel. If they declare whatever sort of food-production, I want to join the data of what they grow to the “non-forest”-part of the parcel. They usually declare both on the same parcel. And I need the data to be joined only on the “correct” part of the parcel. This way, I can for example control if they declare the correct area per land use type – and help them declare correctly if not.

The data of what they grow, I get as a excel-table. I create a join-field using the parcel number, forest/non-forest, etc.

  • 3
    Union is slow. Multipart to singlepart on your dissolved layer and create spatial indexes on all layers. What is the task you are trying to solve with this?
    – Bera
    Commented Dec 22, 2021 at 11:56
  • 2
    Sorry, the question/your is a bit difficult to understand without any screenshot showing what you have and what you want to achieve. It would be also helpful if you could provide sample data.
    – Babel
    Commented Dec 27, 2021 at 11:33
  • 2
    I second Babel on the need for more information. In its absence I'll suggest a couple of other approaches you might look at when overlays are slow. First, create spatial indexes if you haven't and have both layers in the same coordinate system. Prior to an overlay you might run a v.generalize on your layers. If your attribute tables are large, after making sure you have a unique field to link attributes on you could create a polygon layer with no attributes but the link field and use that in the overlay. If that works then you could join the attributes back to the result.
    – John
    Commented Dec 27, 2021 at 18:00
  • 1
    If you could describe your purpose of this it would be easier to understand. Even with the sample data I dont understand why you are doing this
    – Bera
    Commented Dec 27, 2021 at 19:18
  • 2
    Check my assumption: "If you tidy up layer" layer1_forest" by removing unacceptable mini-polygon artifacts inside the layer in edit mode or programmatically, you will get the expected speed of the Union geo-tool..." Commented Dec 28, 2021 at 15:50

2 Answers 2


You can run Clip and Difference tools from Menu Vector / Geoprocessing tools. The advantage of this tools is that a polygon of the input layer that gets split into several parts will still be one multipart feature as you can see on the screenshot (red arrows, selected one feature "forest inside a parcel" (right) and one "non-forested part of parcel" (bottom).

Run both tools with Input layer = Layer2_parcel and Overlay layer = Layer1_forest. Copy / paste one layer to the other if you need all polygons on the same layer.

These tools should run faster (don't forget spatial indices!) because Union checks for self-overlapping within the same layer and the overlay layer. Clip and Difference only check for overlapping/disjoint parts between the input and overlay layers.

enter image description here

  • I did a speed test on a bigger part of the dataset than provided in the sample data: Union as the data is: 9:04 Union when i previously deleted the holes in the forest layer <3m: 7:35 Clip, Difference and Merge (using the deleted holes-layer as well): 6:20. I hoped, there would be a bigger difference. Still: if I run the Clip, Difference and Merge on the whole dataset, it doesn't complete overnight. Is my dataset just too big for my computer (a normally quite fast notebook)? Would you recommend splitting the data, process it and merge it again? Would this help to speed it up as well?
    – Motti
    Commented Dec 30, 2021 at 7:08

You could give geofileops a try. This is a python library that tries to speed up processing of larger files and it supports performing a union.

The result for your sample file is the same.

Note: geofileops also has a function identity. ArcGIS has this as well, QGIS does not. This does like 2/3 of the union: for your example the forest parts that don't overlap with farmers parcels are not included/calculated. If I understand your use case correctly you don't need those polygons, so you could save some time by using identity instead of union.

Code sample for union:

import logging
from pathlib import Path
import geofileops as gfo

input_path = Path("C:/Temp/sample_geodata.gpkg")
output_path = input_path.parent / "sample_geodata_union.gpkg"


Disclaimer: I'm the developer of geofileops

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.