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
About the Author
About the Reviewers

Reprojecting a vector layer

We will use the Processing Toolbox in QGIS to reproject a layer to a different coordinate system.

Getting ready

For this recipe, we'll need the Mississippi cities' shapefile in the Mississippi Trans Mercator projection (EPSG 3814), which can be downloaded as a ZIP file from

Extract the zipped shapefile to a directory named /qgis_data/ms.

How to do it...

To reproject the layer, we'll simply call the qgis:reprojectlayer processing algorithm, specifying the input shapefile, the new projection, and the output file name. To do this, perform the following steps:

  1. Start QGIS.

  2. From the Plugins menu, select Python Console.

  3. First, you need to import the processing module:

    import processing
  4. Next, run the reprojection alogoritm, as follows:

    processing.runalg("qgis:reprojectlayer", "/qgis_data/ms/MSCities_MSTM.shp", "epsg:4326", "/qgis_data/ms/MSCities_MSTM_4326.shp")

How it works...

The source data starts out in EPSG 3814...