collapse

* Forum Staff

PeterC admin PeterC
Administrator
admin webmasterOPS
Administrator

Author Topic: Turning an image into a map - georeferencing  (Read 526 times)

PeterC

  • Administrator
  • Member
  • *****
  • Posts: 382
  • Passionate about my one-place study
    • View Profile
    • Holywell-cum-Needingworth History
Turning an image into a map - georeferencing
« on: 10 May 2016, 09:45:57 »
Georeferencing is the process of aligning geographic data to a known coordinate system so it can be viewed, queried, and analyzed with other geographic data. It may involve shifting, rotating, scaling, skewing, and in some cases warping, the data (Wikipedia).  We do it to images of maps of our OPS so we can overlay them automatically over other maps.

We will need
  • A good quality scanned image, usually a .tiff or .jpg (see this article about how to obtain a suitable image)
  • Image manipulating software, such as IrfanView (free)
  • GIS software, such as QuantumGIS (QGIS) (free) (or we can use MapTiler for this stage)
  • The QGIS OpenLayers and Georeferencer Plugins (installed via the Plugins Menu – Manage and Install Plugins, or they might have been installed already as part of the standard install)
  • Create a working folder for this map in the OPS' Data folder - thus for Peter's HcN OPS this is ...M4OPS\OPS\...\Data\Map name
  • If we are not using a local map as the basis, a note of the EPSG:3857 coordinates of approximately where our image fits in.  The easiest way to do this is by using M4OPS and the EPSG:3857 (x/y) option - click on a point then copy and save the string. As an example the coordinates for the HcN OPS are -3713, 6860017 (they do not need to be very accurate).
Note that we may use other options but:
  • We do all OPS work (including georeferencing) based on the EPSG:3857 (Spherical Mercator: metres) projection – which is also used by Google, and known as EPSG:900913
  • we use the spline transformation (a true rubber sheeting method, which positions the source control points exactly to the target control points, optimising local accuracy rather than global accuracy)
To get our image ready for georeferencing
  • Copy our original scanned map to our working folder
  • Rename it to an appropriate simple name, preferably without spaces in case these are a problem later
  • If necessary, use (eg) IrfanView to convert it to a .tif(f) (as this is lossless) - using LZW compression
  • Use (eg) IrfanView to:
    • if it helps, rotate the map so its verticals and horizontals are as good as possible
    • remove superfluous things from around the edges of the map (eg margins, mapping outside our area of interest)
    • change the colours using Image > Color corrections
      • click in the preview on a white area to set the white value
      • if there are multiple images try to get them the same colour balance, or at least the same white
      • a useful technique for matching brightness involves the histogram function (shift H), selecting a white area and clicking on Update - we can then see the pixel values of the white
    • consider filtering it to clean it up, Image > Effects > the Filter Sandbox Plugin and apply the four different automatic filters, as even with the default settings they give good results
  • Make sure that the map’s image file is not too large [900 megapixels (30K * 30K) is the maximum for the Plus version of MapTiler] – we may want to compress it (Image > Resize/Resample)– but also make sure it is sufficiently sharp (or you can do this later in QGIS)
Now we can use QGIS to convert the image into a georeferenced map (tif)
  • Open a new project in QGIS
  • Go to Project Menu – Project Properties – Click CRS – Check the box “Enable ‘on the fly’ CRS transformation – type 3857 into the Filter box – Click WGS 84 / Pseudo Mercator – and hit OK (these may already be set)
  • Open a base map, either:
    • (Preferably) Open a large-scale accurately georeferenced raster map (eg an OS 25 inch) - use Layer/ Add Layer/ Add Raster and select the mbtiles version of the map, or
    • Go to the Web Menu–OpenLayers–Bing Maps -  select “Bing Aerial Layer with labels” (or another if we prefer), to give us a base map
  • Get this map to approximately where our image fits in:
    • either by using the boxes at the bottom of the window to change the scale in QGis to eg 1:25,000 (use drop down), then putting in the EPSG:3857 coordinates we saved earlier (you can copy an dpaste, but make sure the mouse stays off the mapping area)
    • or we can move the base map with the Hand tool, use the Magnifying Glass and/or the mouse wheel to Zoom
  • On the top toolbar select the Hand tool (this makes things easier later)
  • Go to Raster – Georeferencer – select Georeferencer and the Georeferencer will open in another window
  • (Note that if we minimise (or lose) the Georeferencer window, a way to get it back is to minimise the main QGIS window then maximise it again)
  • Click “open raster” on the far left of the menu and open our scanned map in the Georeferencer window (don’t worry that it has hidden our Bing Aerial view)
  • When asked, again select EPSG:3857 as the coordinate system
  • If we have lat/lon coordinates (to at least 6 decimal points, but 7 are better) on the scanned map then we can just click on the yellow “add point” menu item and then click on as many instersection points as we wish, and when the dialogue pops up asking us to enter the coordinates enter the corresponding lat/lon figures
  • If we do not have lat/lon coordinates then we need to match points on our image to a known map, and this is a bit tricky – we will need to find landmarks on our Scanned map that precisely coincide with locations on the Bing Aerial view in QGIS
    • Manipulate the QGIS and the Georeferencer Windows so they are side by side, so we can see both at the same time. Alter the position and zoom level in both so the same landmarks appear in both. Good landmarks include bends in rivers, river confluence, road intersections, the corners of large buildings, rock outcrops, field boundaries and corners and small islands. Don’t click the tops of tall buildings, antennae or trees – locations are measured at ground / street level
    • Be aware that with the Bing Aerial view there is a limit as to how far we can zoom in – if we go too far (beyond 1:5000) it will become blank
    • Use the Hand tool and zoom to find a landmark in our Scanned map in the Georeferencer window. Click on the yellow “add point” menu item then click a landmark in the Georeference window  – a dialogue pops up asking us to enter the coordinates – since we don’t know this value – we then choose click “from map canvas” – the Georeference Widow disappears – Now click the exact same landmark in the QGIS window using the cross hair (it is important to be as accurate as possible) – the map coordinates are added to the Scanned map the Georeferencer window – click OK
    • For maps where road widths are not surveyed, maybe the middle of the road is a better landmark than the edge (although even there the road could have been manipulated to get some text into it), but hedges, field corners, and corners of buildings are better
  • Super Important – after adding all our Control Points (say about 8 to 12 points) – File - Save GCP points – then if anything goes wrong we won’t have to start from the beginning
  • Click on the yellow cog for Transformation Settings: Select Transformation Type thin plate spline; Sampling – Choose Lanczos (smoother better results); compression LZW; Use zero for transparency,  – Choose the path of the output Raster (where to save the georeferenced map - by default has _modified after the name), and the option to get it shown on QGIS;  click OK
  • When we are satisfied we have enough points in the same place on the Scanned map and the base map in QGIS –Click on the green triangle to start the process, and the georeferenced map will be saved as a GeoTiff
  • The newly georeferenced map will also show in QGIS over the top of the base map.  To see how good our match was either right click on this layer (or double click), select Properties and change its transparency to about 40%, or toggle its visibility on and off, or have a look around the edges to see how roads etc match up
  • If needed we can now go back and make adjustments – for example some small roads may have been roughly drawn and we can use the first attempt to make additional control points. To do this keep the base view in QGIS, with our partially transparent first attempt over the top of it.  Reopen our scanned map and control points in the Georeferencer.
  • Repeat the process, deleting or moving control points (the menu options are next to the yellow “add point” menu item), or adding more. Click on the yellow cog  and choose the path of output Raster, then click on the green triangle to create a second version of the georeferenced map
  • Check the size of the modified image in IrfanView (Image/ Information)
  • If the size is more than 900 Megapixels, to make the image a smaller filesize use QGIS Raster – Conversion - Translate, Nodata=0, Conversion options: profile JPEG compression 75%, (could add PHOTOMETRIC=YCBCR?) - from GeoTiff compression
  • To reopen and edit an image, reload the original tiff/jpg and the control points (ie not the modified tiff)
  • The end result will be a (georeferenced) .tif file in the working folder. This can now be converted into tiles for serving by eg Tileserver
In our working folder, we should end up with:
  • Our original tiff/jpg, and a tiff version with edges removed
  • A .points file (with the saved control points - mapX,mapY,pixelX,pixelY,enable - for the georeferencing)
  • One or more versions of the georeferenced file (tif)
If we want to merge two or more georeferenced images (not often needed as M4OPS can group them, we need to:
  • Click on Raster/Miscellaneous/Merge
  • In the Merge dialog, select all the Input files, select the folder for the Output file and its name, check the No data box and its value to 0, check the box next to Load into canvas when finished
  • Click OK - it will take a while to complete
With thanks to the instructions at:Other Notes
  • The Wikimaps Warper is a free tool for warping and georeferencing the maps before they are stored in WikiMaps.
  • MapWarper is another "free to use, open source map warper / map georectifier, and image georeferencer tool (developed, hosted and maintained by Tim Waters). Find maps and other imagery, upload, and rectify against a real map."
« Last Edit: 3 August 2017, 07:41:57 by PeterC »

 

mapping4ops.org is a Society for One-Place Studies project supported by Grassroots Giving from Skipton Building Society
Glossary | BBCodes | Feedback