Georeference Webmaps

Say you want to use a digital map youve found somewhere on the internet as a basemap for a GIS project? Well you can screen print the map in one or more peices, georeference it using known points, using QGIS georeference plugin [1]. The downside to this approach is:

  • screenprinting is tedious, esp if restitching pieces together using photoshop.
  • the georefernece process introduces errors and possible distortion, but we actually know the srs, and we also know that the map needs no rotation, North is north [2].

 

Theres another way. gmapmaker can download and stitch map tiles from several popular mapping providers. It produces a png for a specifed lat long range and produces a world file of sorts to match [3].

 

The one problem is that the world file is in a proprietary format that is incompatible with std world files. The solution is this.

 

Get these lines from near the end of the oziexplorer .map file.

 

MMPXY,1,0,0

MMPXY,2,11520,0

MMPXY,3,11520,7680

MMPXY,4,0,7680

MMPLL,1,   171.145020,   -43.994790

MMPLL,2,   171.268616,   -43.994790

MMPLL,3,   171.268616,   -44.054038

MMPLL,4,   171.145020,   -44.054038

 

The first four are the pixel extents of the four corners of the image, the most interesting of which is   MMPXY,3 which tells us its pixel width and height respectively. The second four are the lonlat coords of the same 4 corners, the most interesting of which are top left MMPLL,1 and bottom right MMPLL,3. Now to convert these we need to understand the exact meaning of these compared to the std world file spec.

 

The lonlat in ozi .map files are the coords of outer edges of the pixel, eg the lonlat of the top left corner of the top left pixel and the bottom right corner of the bottom right pixel. Whereas the world file uses a format where the matching latlon relates to the center of the top left pixel. Understanding this then you can easily hand build the world file by adding half a pixel (in map units) onto the coords of the top left pixel, like so:

 

firstline:   x mu/px = (171.268616 - 171.14502)/11520

2ndline: 0

thirdline: 0

forthline: y mu/px =(-44.054038 - -43.99479)/7680

5thline: x mid of top left pixel= 171.14502 + x mu/px /2

6thline: y mid of top left pixel= -43.99479 + y mu/px /2

 

So my world file now file looks like this:

0.000010728819

O

O

-0.000007714583

171.1450254

-43.99479386

 

If the map image is called map.png, save the world file as   map.pngw.

 

Now the map is still missing two things. Firstly an srs or coordinate system (which would ordinarily be either provided as a .proj file or in the geotiff metadata). But we do know what it is. Your average popular web mapping system uses a hybrid of wgs84 (epsg4326) and spherical mercator (EPSG3785 (formerly epsg90913). The map is expressed or measured geographically in wgs84 coords but rendered on screen using the pseduo meter/pixel based spherical mercator, that expands the y axis in relation to wgs84. If you are confused see here. This requires mindfulness to load the image into your project map correctly.   If you just add the geotif as is to a qgis layer it will look flattened in the vertical direction compared to the original and reflects the slightly dodgy cartography that is spherical mercator.

 

So the image wont overlay correctly, as is, on our map, which is using a a meter based projected or cartesian coordinate system as opposed to a global scale geographic coordinate system. So we need to reproject or warp   the image as well as assign a source projection. Turns out we can kill both these birds with one stone [5].

 

In QGIS, assuming we want to reproject the image to   NZTM, wed need to:

  • use QGIS | raster | warp.
  • choose your map.png file
  • choose input srs   as 4326, becasue the world file is expressed in wgs84 coords, so we ignore the sperical mercator in this instance.
  • choose output srs, in my case 2193 (NZTM).
  • choose geotif as output format
  • none of the other settings are critcal, you can experiment with them

 

This gives us a fully georeferenced geotif warped to the project projection, done the right way, not the guestimation that the georeferencer uses. The georeferencer plugin is best suited for cases where either you dont know the source projection or you dont have any world file coords.

 

 

[1] QGIS will warp and rotate your image unless you explicitly select linear, thats a trap for new players. Moreover this isnt a mathmatcially defined warp between two known projections it just trys to make your grid points match by brute force.

[2] you do this by choosing grid control points that you know the location of. Beware you cant paste coords into the georeferencer, so the either use the get from map tool, assuming you have a vector map thats accurate and you can identify the same points on the web map.

[3] beware that using this tool may violate licensing terms for some mappering sources.

[4] There various ways to get coordinates out of google maps, see here for ideas.

[5] Beware some of the many tempting tools in QGIS like assign projection and such, theyll disappoint.

Admin login