Sometimes, you need to split a shapefile in order to break a larger dataset into more manageable sizes or to isolate a specific area of interest. There is a script in the Processing Toolbox that splits a shapefile by attribute. It is very useful, even though it is provided as an example of how to write processing scripts.
We will split a census tract shapefile by county. You can download the sample zipped shapefile from https://geospatialpython.googlecode.com/files/GIS_CensusTract.zip.
/qgis_data/census
.https://geospatialpython.googlecode.com/svn/Split_vector_layer_by_attribute.py
/qgis_data/
directory.The stage is set now. Perform the steps in the next section to split the shapefile.
This recipe is as simple as running the algorithm and specifying the filename and data attribute. Perform the following steps:
processing
module:import processing
pth = "/qgis_data/census/"
processing.runalg("script:splitvectorlayerbyattribute",pth + "GIS_CensusTract_poly.shp","COUNTY_8",pth + "split")