Wednesday, 6 March 2019

qgis - Merge 2 SpatiaLite layers into one



I have a SpatiaLite database with some multipolygon layers loaded.


What I would like to do is to merge (not dissolve) 2 layers into 1. Both layers have the same SRID and same field name (they are a result of the same algorithm).


I'm looking for a SpatiaLite funcion that does the same thing of QGIS -> Union.


Is there a simple comand to do that?




My solution, using @Alexandre's suggestions:


CREATE TABLE merged AS
SELECT * FROM layer1
UNION ALL
SELECT * FROM layer2;


SELECT RecoverGeometryColumn('merged', 'Geometry', 32632, 'MULTIPOLYGON', 'XY');

Answer



If you use DB Manager, you can use plain SQL to union two tables. Something like this:


SELECT field1, field2 FROM my_table_1
UNION ALL
SELECT field1, field2 FROM my_table_2

Notice that the fields must match in both tables in terms of data type, but they do not need to have the same name.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...