2

I'm using QGIS 3.2.3 in Windows and I created a tessellation with polygons (Voronoi tiling / Thiessen polygons) with the built-in tool "Voronoi Diagrams", (Call this layer LAYER1). Afterwards, I used LAYER1 to subdivide another layer stored as a Geopackage with many polygons (call this layer LAYER2) using the built-in tool "Clip" and the option "Iterate over this layer" to create a separate layer for every feature in LAYER2 with the subdivision of LAYER1 and set as output for each one a new Geopackage (call this layers OUTPUTS).

Now I want to merge all this OUTPUTS in a new layer, so I get a tesellation of polygons in LAYER2, for that I tried to use the tool "Merge Vector layers" that I suppose replace and extends the old tool "Merge Shapefiles", but as I'm using now geopackage this process fails (If I set the output format as Shapefile it runs successfully, because that format doesn't use a unique ID).

I suppose that, this problem is caused because all features in all OUTPUTS must to have different FID to be merged, but that's no my case because the FID in the outputs are based on FIDs of LAYER1 so the same polygon can divide many others in LAYER2.

Is there a solution to this problem using QGIS built-in tools? The easy way could be just use as output format Shapefile. But I like to maintain the consistency of my project and avoid to rename some fields in my layers, or edit manually the fids in the outputs.

0

As long as the QGIS fix is not ready you can use ogr2ogr for merging the layers. Use it with parameter -unsetFid https://www.gdal.org/ogr2ogr.html. Run this command for all your input layers for appending data from the layers to a single table named "merged"

ogr2ogr -f gpkg -update -append -unsetFid output.gpkg input_layer1 -nln merged

Afterward of @ndawson's comment and @user30184's answer. I wrote a batch file for Windows that iterates in all OUTPUTS with the pattern iterate_*.gpkg and merges all in one file this way:

echo off set dst_datasource_name=voronoi_merge.gpkg del %dst_datasource_name% for %%f in (iterate_*.gpkg) do ( echo Merging %%~nf ogr2ogr -f gpkg -update -append -unsetFid %dst_datasource_name% %%~nf.gpkg -nln voronoi_merge )

This file must be run from the folder with all the OUTPUTS

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.