Tutorial: Advanced Georeferencing in QGIS using a Reference Layer

In the previous tutorial “Georeferencing Topo Sheets, Topo Maps, Satellite Image or Scanned Maps in QGIS”, you learnt the basic process of georeferencing in QGIS. That method involved reading the coordinates from your scanned map and inputting it manually. Many times though you may not have the coordinates printed on your map, or you are trying to georeference a photograph. In that case, you can use another georeferenced data source as your input. In this tutorial, I will show you how you can use existing open data sources in your georeferencing process.The topics covered by this tutorial are

Downloading super high-resolution public domain imagery

Using OpenLayers plugin in QGIS

Converting coordinates between different projection using cs2cs command-line tool

Using an existing georeferenced layer to input GCP points in the Georeferencer tool

Setting a custom no-data value for a layer.

Let’s get started. In this tutorial, we will be using some gorgeous kite and balloon imagery collected by The Public Laboratory. They make the georeferenced versions of the images also available, but we will download a non-georeferenced JPG image and go through the process of georeferencing it in QGIS. If you like the imagery they provide, you can explore it in Google Earth as well.

Go to the download page for Washington Square Park, New York from Public Laboratory. Right-click on the JPG button and click ‘Save link as’. Save it to your hard drive.

For this tutorial, we will be using the OpenStreetMap layer as our reference layer. The reference layer could be anything. It could be a georeferenced map that you have for the area or a vector layer which may have roads or landmarks that are in your image. In QGIS, the ‘OpenLayers plugin’ provides easy access to the rich global dataset from OpenStreetMap (OSM). Since OpenStreetMap has global coverage, this method will work well for most georeferencing tasks. Once you have fetched and loaded the plugin, go to Plugins → OpenLayers plugin → Add OpenStreetMap layer.

Now you have the OpenStreetMap layer loaded in QGIS. Note the Coordinate Reference System (CRS) for this layer. It is set as EPSG 3857 Pseudo Mercator. This is important to note, since the coordinates we ‘infer’ from this layer will be in this CRS.

Now the task is to locate the general vicinity of the area that we are trying to georeference. You can just use Pan and Zoom tools to locate that area on the OpenStreetMap layer. But I will take this chance to demonstrate another tool that may help you in future. We know that the image we downloaded is for Washington Square Park in New York. If you search for that place, you will be able to locate the wikipedia page for it. The coordinates for the park are listed there.

You will notice that the coordinates are in Degrees/Minute/Seconds and are Latitude and Longitude. But since our layer is in Mercator projection, we will need Mercator coordinates to locate the park. Here’s where a command-line tool called ‘cs2cs’ comes handy. If you have installed QGIS from OSGeo4W installer, you will already have it installed on your system. On Linux and Mac too, it comes pre-installed with QGIS. Launch a terminal window and type ‘cs2cs’ to check if it is available. Windows users can find a terminal at Start → OSGeo4W → MSYS.

Once you have verified that the cs2cs tool exists on your system, it is time to convert out Latitude and Longitude to Mercator coordinates. The way this tool works is that you need to specify a ‘source’ and ‘destination’ CRS. The CRS definition could be a PROJ4 string or an EPSG code. Since we already know the EPSG code for out input and output CRS, we will use this. The simplest way to use the tool is to supply the input coordinates on the command line itself. Note that the tool accepts coordinates in the order “X Y”, so we need to enter “Longitude Latitude”.

Once you press enter, you will see the tool process the coordinates and print out output X Y coordinates in EPSG 3857 CRS. Copy these coordinates and switch to QGIS. At the bottom of the QGIS window, you will see a textbox labeled Coordinates. Enter the coordinates there in X,Y form. Press Enter. You will see the map shift a bit, but not zoom. To zoom to the area, select 1:2500 scale from the Scale drop-down next to the Coordinate box. Voila! you now see Washington Square Park area on your canvas.

Now it is time to start georeferencing. Launch the Georeferencer from Raster → Georeferencer → Georeferencer.

Click on Open raster button. Navigate to the 2011-04-27-newyork-newyork-washingtonsquarepark.jpg image saved on your disk. Click OK.

In the CRS selected, choose the CRS of the reference layer EPSG 3857.

Now click on the ‘Add Point’ button on the toolbar and select an easily identifiable location on the image. Corners, intersections, poles etc. make good control points. Once you click on the image at a control point location, you will see a pop-up asking you to enter map coordinates. Click the button ‘From map canvas’.

Find the same location in your reference layer, i.e. the OpenStreetMap layer and click there.

The coordinates are auto-populated from your click on the map canvas. Click Ok.

Repeat this process till you have found at least 4 ground control points (GCPs). Then click on ‘Transformation settings’ button.

Choose the settings as shown below. Make sure you check the ‘Load in QGIS when done’ button. Click OK.

Now you are ready to begin applying the transform. Click the ‘Start georeferencing’ button.

Once the process finishes, you will see your newly georeferenced image loaded in QGIS. If all went well, you will see it nicely overlay the OpenStreetMap layer.

To make our output look nicer, let’s remove the white no-data values. Right click on the image layer and Choose Properties. Switch to the Transparency tab and input 255 as the no-data value, since in our case the unncessary portion of the image is white. Also move the global transparency slider to 25%. Click OK.

There you have it. You have successfully georeferenced a plain JPG image to a GeoTiff image.