01.16.10

1862

Posted in programming at 9:43 pm by paul

I made previous reference to a scan available online of a map of San Francisco and my intention to put that map on a Google Map. Well, I’ve spent way more time on it than I anticipated but it finally, actually works as I originally envisioned.

Challenges:

  1. Google Maps are aligned with “true north”; the old map is aligned with some other north, possibly magnetic north at the time the map was made
  2. the horizontal and vertical scales are not the same
  3. the old map apparently fell apart and was taped back together; this was not done perfectly and there are a few small gaps and missing bits
  4. the scale tends to vary over relatively small distances; agreement between the tiles I generated and Google’s tiles can wander even within one tile

I ultimately decided not to fix items 3 and 4. Fixing the gaps tended to do more harm than good and scale variances require far more graphics-fu than I am ever likely to have.

If you want to cut to the chase & see the map, it is here.

Here is what I did:

  • Create a map from Google tiles of the area of the map. This made it possible to determine both the rotation and scaling necessary.
#!/bin/bash
let EX=5236
let WY=12660
while [ ${EX} -lt 5243 ] ; do {
 while [ ${WY} -lt 12670 ] ; do {
 curl -o z15_x${EX}_${WY}.png "http://mt1.google.com/vt/lyrs=m@116&hl=en&src=api&x=${EX}&s=&y=${WY}&z=15&s=Galileo"
 let WY=(${WY}+1);
 } ; done
 let EX=(${EX}+1);
 let WY=12660;
} ; done

To combine all these tiles into a larger map:

#!/bin/bash
let EX=5236
let WY=12660
while [ ${WY} -lt 12670 ] ; do {
 FILES=`ls *${WY}*`
 echo "appending $FILES"
 convert ${FILES} +append ${WY}.png
 let WY=(${WY}+1);
} ; done
YFILES=`ls 12*.png`
convert $YFILES -append whole_map.png

(The convert binary is part of ImageMagick.)

Comparing this image with the downloaded file, I estimated that the rotation should be about 9 degrees counter-clockwise (ie, -9°). I rotated the image with:

convert -rotate -9 whole_map.png whole_map_rotated.png

This created a white background, I wanted the background to be clear. It seems to me you need to know the size of the image to on this image, so to rotate the image I did this:

convert -size 4606x5108 xc:none -background \
 transparent \( whole_map_rotated.png -rotate -9 \) -flatten test.png

This gave me the rotated, clear-background image I needed. Once I started gereating the tiles based on that image, I discovered that if the tile crop area included a negative x or y offset, the image would be scaled awkwardly either in ImageMagick or in the browser. So I added a border area of 500 px on all sides to give a little margin for error. Unfortunately, after a lot of flopping around with ImageMagick, I resorted to Photoshop and the “canvas size” dialog.

Finally I wrote a script to generate the tiles.

Leave a Comment