Merging shapefiles
Merging shapefiles with matching projections and attribute structures is a very common operation. In QGIS, the best way to merge vector datasets is to use another GIS system included with QGIS, called SAGA. The OSGeo4W QGIS version for Windows includes SAGA. The KyngChaos distribution of QGIS for OSX includes SAGA. Most other versions and platforms will need SAGA manually installed. In PyQGIS, you access SAGA functions through the Processing Toolbox.
Getting ready
In this recipe, we'll merge some building footprint shapefiles from the adjoining areas into a single shapefile. You can download the sample dataset from the following URL:
https://github.com/GeospatialPython/Learn/raw/master/tiled_footprints.zip
Extract the zipped shapefiles to a directory named /qgis_data/tiled_footprints
.
How to do it...
We will locate all of the .shp
files in the data directory and hand them to the saga:mergeshapeslayers
to merge them:
Start QGIS.
From the Plugins menu, select Python Console.
We...