Book Image

QGIS Python Programming Cookbook

Book Image

QGIS Python Programming Cookbook

Overview of this book

Table of Contents (16 chapters)
QGIS Python Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Splitting a shapefile


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.

Getting ready

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.

  1. Extract the zipped shapefile to a directory named /qgis_data/census.

  2. You also need the following script for the Processing Toolbox:

    https://geospatialpython.googlecode.com/svn/Split_vector_layer_by_attribute.py
    
  3. Next, use the following steps to add the script to the Processing Toolbox:

  4. Download the script to your /qgis_data/ directory.

  5. In the QGIS Processing Toolbox, open the Scripts tree menu and then go to the Tools submenu.

  6. Then, double-click on the Add script from file command...