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 https://geospatialpython.googlecode.com/files/MSCities_MSTM.zip.
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:
Start QGIS.
From the Plugins menu, select Python Console.
First, you need to import the processing module:
import processing
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...