[GIS] Exporting 2 shp layers to geojson using QGIS

geojsonqgisshapefile

I will explain with an example:

I have 2 shp files for Tanzania.

Tanzania inland waters http://www.diva-gis.org/data/wat/TZA_wat.zip

Tanzania administrative boundaries http://gadm.org/data/shp/TZA_adm.zip

I open both shp files (TZA_wat.shp and TZA_adm0.shp) in Quantum GIS Desktop.
I want to merge the layers : TZA_wat and TZA_adm0 and export/save both layers to one geojson file.

While I can do this for individual layers but not able to do this for both at once. I have written code to process geojson files but I get stuck at this step.

Is there a way to first merge both these .shp files to a single .shp file and then export/save as geojson?


I used the Union option in QGIS and merged the two shp files (here) into one. I uploaded the file here in a zip if anyone wants to take a look. The zip has shp files and geojson file in it.

input shp files : link
output shp file: link

Best Answer

The problem with your data is that you have one line type layer, and the rest are polygon layers. You can merge data of one type, but not mixed (at least not with shapefiles).

So you have to do it by editing the geojson file, or leave it separated type-wise. QGIS is not able to work with mixed geometries, so you have to split a mixed-geometry input file anyway (like gpx or kml drivers do).


EDIT

Improved answer with new data:

Now you have only polgon data, which makes a union possible without mixed geometry. But your admin shapefile has no prj file. That might cause the crash, see http://hub.qgis.org/issues/5962. Union does it better, but makes 2239 objects out of 83 admin area objects and 892 water areas.

What you can do is clear the union file, and copy and paste the elements of the two layers again into the output layer. The union file still has all attribute fields from both datasets, so copying works. In result you only have 975 elements.

Or copy and rename the .prj file from the water areas, which has the same projection. Then merging shapefiles works, with the expected 975 elements.