Tools for map image tile creation (tileCutter & aligner)

by Peter Pesti

development ended: February 12, 2006
document written: June 16, 2006


I created some tools to generate the image tiles for Google Maps Nighttime!. Since these were made for one-time personal use only, they are very unsophisticated, and this description is quite technical. I provide the tools here, but I can't offer any support for them... (Note: You might want to try the newer, and user-friendly MSR MapCruncher too.)

The tools are: The main tool is tileCutter, a Python script controlling ImageMagick under Linux. The challenge was the creation of a tool that I could use to process the 16384 x 8192 pixel NASA image into 256 x 256 pixel tiles. The input image had to be stretched for alignment to Google's maps, then resized for each zoom level, where the maximum zoom level required enlarging the image (by a factor of ~1.3 in one dimension). I needed a machine with a lot of memory for this, which was only available to me via a simple SSH login, on a remote Linux machine. Thus the tile creation itself has no GUI, so the new image layer and Google Maps have to be pre-aligned.

You will need two "feature points" on your image to align to Google Maps. These can be any two points that you can visually identify (eg. corners), and should be far apart both horizontally and vertically. These two points will match up exactly in the final result: the image will be stretched horizontally and vertically to make this happen. The first feature point will be "top-left", and the second will be "bottom-right". Write down the pixel coordinates of these two points (using some image editor/viewer program), so you have: [map_x1] [map_y1] [map_x2] [map_y2]. Next, you will need to find the same two points on Google Maps, using the aligner tool. You can zoom in/out as much as you like, and click to place a marker for the "top-left", then the for the "bottom-right" point. Click on a marker to restart if you made a mistake. You will get five numbers at the bottom of the screen; note these too: [zoom] [tile_x1] [tile_y1] [tile_x2] [tile_y2]. Now you have all the alignment data. (Note: When using an image that spans the entire globe, you will want to explicitly use [map_x1]=0, [map_x2]=width of image in pixels-1, [tile_x1]=0, [tile_x2]=pow(2,[zoom]) * 256 - 1, while using the Y coordinates of two feature points)

To run my tileCutter3.py tile cutter script, I used Python 2.3.4 and ImageMagick 6.0.7 running on a remote Red Hat Linux 4 machine. When using different Python or different ImageMagick versions, the script might not work properly, or at all in its current form (this is my personal experience). You might be able to use the script under Windows inside Cygwin (Python and ImageMagick must be installed inside Cygwin). You might also be able to use the script in a simple command prompt under Windows, but I think there are some OS-dependent lines that you would have to rewrite (Python and ImageMagick must be installed in Windows). I have played around with these in the beginning, but decided to tune to the configuration of the Linux machine with the huge memory.

I have included an example with the tileCutter. You can start the example with gt.sh, which simply runs tileCutter3.py with the correct arguments to take the Georgia Tech campus map image found in the src directory, and generate the tiles for it. The resulting tiles should look something like this.

The tileCutter's arguments are the following:

python tileCutter3.py [name] [extension] [source map] [map_x1] [map_y1] [map_x2] [map_y2] [zoom] [tile_x1] [tile_y1] [tile_x2] [tile_y2] [background color] [logo image]

in the example:

python tileCutter3.py gt png src/campus-map.png 286 659 1292 1609 19 35639742 53713957 35644711 53718674 "#111111" ImageMagick runs in "nice" mode. Map tiles will go into separate directories for each zoom level, so you can access them as ./[zoom]/[x]-[y].[extension]. All "reasonable" zoom levels will be automatically processed (ie. not too zoomed out, and not too zoomed in). You can figure out the details from the tileCutter3.py file...

Hope this helps!


(Note: tileCutter3.py is under a GNU GPL license.)