Tutorial: Working with Projections in QGIS

Map projections often cause a lot of frustration when working with GIS data. But proper understanding of the concepts and access to the right tools will make it much easier to deal with projections. In this tutorial, we will explore how projections work in QGIS and learn about tools available for vector and rasters - particularly reprojecting vector and raster data, enabling on-the-fly reprojection and assigning projection to data without projection.
We will use Natural Earth vector data for this tutorial, particularly 10m_admin0_map_units layer. We will also use some raster data for the UK. I downloaded MiniScale raster layer from UK’s OS Open Data initiative.

Let’s get familiar with basics of how projection is handled in QGIS. Projection is referred as Coordinate Reference System (CRS) or Spatial Reference System (SRS) within QGIS. Coordinate systems are categorized in 2 types: Geographic Coordinate Systems and Projected Coordinate Systems. Geographic Coordinate Systems use Latitude and Longitude as coordinates and use different ellipsoids. Projected Coordinate Systems project the ellipsoid to a surface and use various linear schemes to assign coordinates. 

  • Load the 10m_admin0_map_units.shp layer in QGIS via Layer → Add Vector Layer. At the bottom of QGIS window, you will notice the label “Coordinate”. As you move your cursor over the map, it will show you the X,Y coordinates at that location. At the bottom-right corner you will see EPSG:4326 . This is the code for the current ‘Project CRS’.
  • To determine a layer’s projection, right click on it and select Properties.
  • In the Properties dialog, click on the Metadata tab. You will see the projection definition of the layer under ‘Layer Spatial Reference System’.
  • Let’s say we want to reproject the layer to a different projection. Right click on the layer and select ‘Save as...’
  • In the Save vector dialog, first click on ‘Browse’ next to Save As label and name your output file admin_0_reprojected.shp. Next, click on the Browse button next to CRS label.
  • Since this is a global layer, let us choose the ‘World Mercator’ projection. Click OK.
  • Click OK on the ‘Save vector layer as...’ dialog as well.
  • The layer is now saved at the path you had selcted. Load the layer to QGIS canvas by going to Layer → Add Vector Layer.
  • Once the layer is loaded, you will see it on the table of contents. But you don’t see it on the canvas. This is because you are in the latitude/longitude coordinate space from the previous layer. The new layer has a different coordinate space, so it will be located somewhere off the current view. To see it, right click and click on ‘Zoom to layer extent’.
  • Now you will see the newly reprojected layer. But you do not see the previous layer. This is a common problem when working with data of different projection. Ideally you would like to see the layers overlaid on top of each other in the same coordinate-space regardless of their projection. There is an option called ‘on-the-fly reprojection’ to enable just that.
  • Click on Settings → Project Properties.
  • Check the box next to ‘Enable ‘on the fly’ CRS transformation’. Next select the ‘common’ projection that all the current and subsequent layers would be automatically reprojected to. We would keep that as WGS84. Click OK.
  • In the QGIS table of contents. Right click on any layer and select ‘Zoom to layer extent’.
  • Now you will see both of the layers overlaid on top of each other and in the space lat/long coordinate space.
  • Now let’s switch gears and add a raster layer to our project. You have to download the Miniscale layer, extract the zip file to a directory and locate RGB_TIF_COMPRESSED folder containing tif files. You will notice that the .tif image files are plain TIF files, not GeoTIFF files. That means they do not have any projection information associated with that. To use any image in a GIS, you need 2 types of information - image extents and projection. Typically, the extents are stored in a file known as ‘World file’ and they have extensions like tfw or jgw. The projection information is stored as a ‘PRJ file’ and they have extension of .prj. Most GIS software, including QGIS would be able to use information stored in the world files and projection files as long as they are stored in the same directory as the original image and has the same name. So if your file is called foo.tif, your world file and projection file should be called foo.tfw and foo.prj. In the Miniscale layer, we have been supplied with the World files in a separate layer.
  • Copy the tfw files from the ESRI_TFW_Files folder and copy it alongside the tif files.
  • Now we are ready to open the file in QGIS.
  • Click on Layer → Add Raster Layer.
  • Select MiniScale_(no_grid).tif file. and click Open
  • You will get a pop-up box to define the layer’s projection. You can look at the data documentation (PDF) and determine that this image is georeferenced in the British National Grid projection. Locate it from the list and click OK.
  • Once the layer is loaded, right click on select ‘Zoom to layer extent’.
  • You will now see the newly added raster layer perfectly overlaid with our vector data. Remember that all these three layers are in a different projection and hence a different coordinate space, but because we have enabled ‘on the fly’ transformation, they are converted to a common coordinate space in real time.
  • If you want to permanently assign the projection to the raster layer, use Raster → Assign projection tool. It will create a GeoTiff file from the original TIF file that will be self-contained with the extent and projection information.
Hope you have learnt the basics of CRS and how QGIS handles it. Do let me know how you deal with projections in your project.