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:

  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, but we want to project it to WGS 84 Geographic, which is commonly used to deal with global datasets and is usually the default coordinate reference system for GPS devices. The target EPSG code is 4326. Dealing with map projections can be quite complex. This QGIS tutorial has some more examples and explains more about map projections at http://manual.linfiniti.com/en/vector_analysis/reproject_transform.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset