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.