A large-format Google map

Translated from Polish. Originally published on morony.pl on 7 Sep 2016.

I really like maps. One day earlier this year I came up with the idea of decorating a wall with a map of Poland. There was one small catch: I didn't want just any map, I wanted a Google map. A quick look around the internet turned up no concrete solutions – great, I'll be the first!

Google Maps shows a different amount of detail depending on the zoom level. When the whole of Poland fits on the screen, there's no detail at all. My wall map was going to be big (I was planning something around a meter by a meter), so I needed the detail. I decided to write an application in C# whose job was to display successive pieces of the map and take a screenshot of each. Development of the application stopped the moment it worked, so not even the buttons were labeled:

For medium detail, ~120 screenshots were enough to cover Poland, and for high detail I took over 1200 of them.

Taking the screenshots was the easy part. Stitching them together was harder. Remember that the Earth is a sphere, so simply gluing the images together would leave gaps, because the relationship between degrees of longitude and kilometers depends on latitude. I easily found online the relationship between map pixels and physical distances as a function of latitude:

Meters per pixel = 156543.03392 * Math.cos(latLng.lat() * Math.PI / 180) / Math.pow(2, zoom)

In the next step, I cut out of each screenshot the part of the map without any interface elements – to keep things simple, always the same rectangle in the middle of the screen. I did this automatically, of course, using the convert command. While cropping, I also converted the cut-out piece to TIFF format. Having calculated the geographic coordinates of the corners of each map piece from the formula above, I converted the TIFF image to GeoTIFF using the gdal_translate command. A GeoTIFF is nothing more than a regular TIFF with additional information about its orientation in space. This process was driven by a MATLAB script:

lat_min = 48.7;
lat_max = 55;
lon_min = 13.8;
lon_max = 24.6;

lat_step = .6;
lon_step = 1.2;

xof = 100;
yof = 100;
x = 1920 - 2*xof;
y = 982 - 2*yof;

for lat = lat_min:lat_step:lat_max
    for lon = lon_min:lon_step:lon_max
        im_width = 1720;
        im_height = 782;
        zoom = 10;

        meters_vertical = (156543.03392 * cos(deg2rad(lat))  / (2^zoom));

        [lat_tm, lon_tm] = reckon(lat, lon, km2deg(meters_vertical*(im_height/2)/1000), 0);
        [lat_bm, lon_bm] = reckon(lat, lon, km2deg(meters_vertical*(im_height/2)/1000), 180);

        meters_horizontal_top = 156543.03392 * cos(deg2rad(lat_tm)) / (2^zoom);
        meters_horizontal_bottom = 156543.03392 * cos(deg2rad(lat_bm)) / (2^zoom);

        [lat_tr, lon_tr] = reckon(lat_tm, lon_tm, km2deg(meters_horizontal_top*(im_width/2 - .5)/1000), 90);
        [lat_tl, lon_tl] = reckon(lat_tm, lon_tm, km2deg(meters_horizontal_top*(im_width/2 - .5)/1000), 270);

        [lat_br, lon_br] = reckon(lat_bm, lon_bm, km2deg(meters_horizontal_bottom*(im_width/2 - .5)/1000), 90);
        [lat_bl, lon_bl] = reckon(lat_bm, lon_bm, km2deg(meters_horizontal_bottom*(im_width/2 - .5)/1000), 270);

        system(sprintf('convert source/mapa_%8.5f_%8.5f.png -crop %dx%d+%d+%d -resize %dx%d -transparent white crop/mapa_%8.5f_%8.5f.tiff', lat, lon, x, y, xof, yof, 2*x, 2*y, lat, lon));
        system(sprintf('gdal_translate -of GTiff -a_srs WGS84 -a_ullr  %8.5f %8.5f %8.5f %8.5f crop/mapa_%8.5f_%8.5f.tiff crop/geomapa_%8.5f_%8.5f.tiff', lon_tl, lat_tl, lon_br, lat_br, lat, lon, lat, lon));
    end
end

Then, using the gdal_merge.py script, I merged all the GeoTIFFs into one huge GeoTIFF. The work could have ended here, but I wanted my map to have a nice projection, a frame and so on. The best map-drawing software I know is the GMT package (http://gmt.soest.hawaii.edu/). With a simple script I prepared a PDF (well, PS is almost a PDF) with the map, ready for printing:

gmt gmtset PS_MEDIA=Custom_60ix80i
gmt gmtset MAP_FRAME_WIDTH=.25i
gmt gmtset FONT_ANNOT_PRIMARY=32p,Helvetica,black
gmt gmtset COLOR_NAN=white
gmt psbasemap -R13.8/24.5/48.7/55 -Jl19.20/19.30/52/60/1:600000 -B1g.5:."": -K -P > mapa_all.ps
gmt grdimage ALL.tiff -D -R13.8/24.5/48.7/55 -Jl19.20/19.30/52/60/1:600000 -Gf -Q -P -O -K >> mapa_all.ps
gmt pscoast -R -Df -J -N1/3p,- -A0/0/1  -O -P >> mapa_all.ps

This is what the final result looked like once printed:

I'm not sharing the map file, because it's very large and I'm not sure Google wouldn't have my head for it.