Unix command-line tile cutter for Google Maps
When I released my new Toronto transit map I promised to release some of the tools I used to create it. Possibly the most useful tool I created is my command-line tile cutter. True, there are other image tilers, such as a Photoshop script and a web-based tool which uses Google Maps. I don’t have Photoshop and find it slow, and the web-based tool is difficult to use even with small files, so I created my own tile cutter.
My image tiler uses Free Software, is released under the GPL, and has the following features:
- Tiles most image formats, including GIF, JPEG, PNG and TIFF.
- Works on most flavours of Unix, including Mac OS X.
- Supports version 1 and version 2 zoom levels.
- Automatically calculates offsets for all zoom levels.
- Supports padding from the upper-left as output by the web-based tiling helper.
- Automatically pads image to size appropriate to Google Maps (ie. multiple of 256).
- Optionally discards empty transparent tiles to save space.
- Optional prefix for each tile.
- Outputs tiles in PNG format.
- Compresses tiles with either advpng or pngcrush.
The tiler requires ImageMagick and advpng or pngcrush for PNG compression. (I recommend advpng as it is faster and compresses smaller in most situations.) Tiled image size is restricted only by disk space and ImageMagick limitations.
To use the tile cutter, one need only specify the image being tiled, the Google tile coordinates of the top-left tile, the zoom level for which those coordinates are valid and the zoom level the tile represents. For example, suppose we have three images (img15.png, img16.png and img17.png) for zoom levels 15 through 17 (in version 2 zoom levels), respectively. The top-left corner of the image at level 15 is 1812,1924. You would then run the following commands to generate the tiles:
% googletilecutter -o 15 -t 1812,1924 -z 15 img15.png
% googletilecutter -o 15 -t 1812,1924 -z 16 img16.png
% googletilecutter -o 15 -t 1812,1924 -z 17 img17.png
Note that the only options which need to be changed from image to image are the zoom level of the image and the image itself. Compression and discarding of empty tiles is performed automatically. For more command-line options execute the script with the -h option.
Download the Unix command-line tile cutter for Google Maps. If you have any problems or experience any unexpected behaviour, please leave a comment below.
- none
This entry was posted on Wednesday, January 24th, 2007 at 12:08 am and is filed under googletilecutter, programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Eli Says:
May 9th, 2007 at 11:16 pm
Hi Ian,
I’m interested in using your sh script that you wrote, but an error keeps coming up when trying to initiate the program. Here’s the output of the command when trying to use it.
eli% tilecutter -o 15 -t 772,571 -z 15 ds9.tif
csh: .: Command not found.
/usr/bin/tilecutter: line 111: [: too many arguments
csh: .: Command not found.
Using pngcrush for compression.
Padding image …
identify: ds9.tif: unknown field with tag 34665 (0×8769) encountered..
convert: ds9.tif: unknown field with tag 34665 (0×8769) encountered..
Generating tiles …
Renumbering and compressing tiles …
identify: unable to open file `/tmp/map-XXXXXX.OViCcJKb-tile-0′: No such file or directory.
identify: unable to open file `/tmp/map-XXXXXX.OViCcJKb-tile-1′: No such file or directory.
identify: unable to open file `/tmp/map-XXXXXX.OViCcJKb-tile-2′: No such file or directory.
identify: unable to open file `/tmp/map-XXXXXX.OViCcJKb-tile-3′: No such file or directory.
identify: unable to open file `/tmp/map-XXXXXX.OViCcJKb-tile-4′: No such file or directory.
identify: unable to open file `/tmp/map-XXXXXX.OViCcJKb-tile-5′: No such file or directory.
identify: unable to open file `/tmp/map-XXXXXX.OViCcJKb-tile-6′: No such file or directory.
identify: unable to open file `/tmp/map-XXXXXX.OViCcJKb-tile-7′: No such file or directory.
identify: unable to open file `/tmp/map-XXXXXX.OViCcJKb-tile-8′: No such file or directory.
identify: unable to open file `/tmp/map-XXXXXX.OViCcJKb-tile-9′: No such file or directory.
identify: unable to open file `/tmp/map-XXXXXX.OViCcJKb-tile-10′: No such file or directory.
identify: unable to open file `/tmp/map-XXXXXX.OViCcJKb-tile-11′: No such file or directory.
Any clues as to where I should start looking into?
Thanks for your consideration and writing such a program.
Cheers,
Eli
Ian Stevens Says:
May 10th, 2007 at 7:54 pm
Hm, there are a number of things wrong here. This shouldn’t be running under csh. Find out where your bash shell is and change the first line of the script to reflect that. It might be /usr/bin/bash, not /bin/bash.
It also looks like identify can’t parse your .tif file and is failing to pad it. Not sure why.
Relations › links for 2007-09-13 Says:
September 12th, 2007 at 8:30 pm
[…] Unix command-line tile cutter for Google Maps - crazed monkey My image tiler uses Free Software, is released under the GPL, and has the following features: […]
ExtMapTypeControl 1.2: Types Made on ordering Maintaining Of Support Of Chart | geo2web.com Says:
September 19th, 2007 at 3:46 am
[…] those of you who don’t know, you can create your own custom map types, cut your own tiles, or even remove default map types. The GMapTypeControl respects whatever map types are defined, and […]
Peter Says:
October 17th, 2007 at 7:11 am
What do I need to do to get this up and running. Do you have a easy cant go wrong guide to how to cut up tiles. So far all the examples online are sparse to say the least and there is no easy all you need to do to create your own tiles is…
1. get an image of the world like this one… i.e.
2. using the following …..
3. running the script under linux you will need to make sure you install X and Y via apt-get, yum or whatever package manager you use…
At the moment when I run your script i get the following:
Advpng or pngcrush not found. Using no PNG compression.
Padding image …
./googletilecutter.sh: line 140: identify: command not found
./googletilecutter.sh: line 152: convert: command not found
Generating tiles …
./googletilecutter.sh: line 161: convert: command not found
Renumbering and compressing tiles …
ls: /tmp/map-HUzlU1-tile*: No such file or directory
Any info would be appreciated!
Thanks
Ian Stevens Says:
October 17th, 2007 at 2:12 pm
Hi Peter. My tile cutter requires you to install ImageMagick, which you do not have installed. If you’re under a Debian variant, running
apt-get imagemagickshould solve the problem.Admittedly, a more suitable error message should be output, and I’ve created a ticket reflecting this. Unfortunately, the script won’t auto-install missing packages.
I hope this helps. If you’re still having problems, let me know.
ExtMapTypeControl 1.2 with Custom Map Types | geo2web.com Says:
November 5th, 2007 at 9:17 am
[…] those of you who don’t know, you can create your own custom map types, cut your own tiles, or even remove default map types. The GMapTypeControl respects whatever map types are defined, and […]
Bo Bjerregaard Says:
May 2nd, 2008 at 8:01 am
Hi Ian,
I’ve been using googletilecutter, and so far I’m pretty happy with the results, great work!
But at the moment I’m running into some issues cutting tiles so I can zoom in on them.
I have a source-map, which has coords 34623, 20350 @ zoom-level 16, that I’ve used googletilecutter to cut up into 9 tiles. I want to be able to zoom further in on the map, how would I be able to do this? I’ve tried cutting up the resulting tiles into more tiles to get another zoomlevel, but it just doesn’t work…
I hope you can help me out :)
~Bo
Martoosh Says:
June 6th, 2008 at 3:56 pm
Hi Ian,
I’m looking for a tool that will allow me to cut out a section from a map online, from google maps for instance.
Is this the function of the Unix command-line tile cutter? Forgive my ignorance, I am a social worker (not a computer scientist) and am not literate with tools - however I’m trying to create a document and such a tool would be useful.
Thank you, best,
Marta
Ian Stevens Says:
June 7th, 2008 at 1:06 pm
Sorry Martoosh, this utility just cuts an existing image into tiles suitable for Google Maps. It does not do the reverse. There are apps that do this. Search for “google maps tile stitcher” or something similar.
P.R. Says:
September 13th, 2008 at 12:52 am
Ive created a large, full-globe projection using a program called GrADS, and the image lat/lon values range from -180 to +180 longitude, +90 to -90 latitude.
However, Ive noticed that google’s map progjection ranges from about -85 to +85 latitude (it doesnt go all the way to 90 degrees), and also that the change in latitude across the center tiles is not uniform (i.e., at zoom level 2, tile 2 goes from 0 to about 66 degrees, instead of going to 45 degrees, because 180degrees/4 tiles should equal a tile height of 45 degrees, guessing this is because of the mercator distortion?).
Anyway, Im wondering if your tiler takes care of this stuff, or would my image need to already be compatible with google’s projection? (so, would my image already have to start & end at 85 degrees latitude instead of 90 degrees, and would the center latitudes need to already be “distorted”, in mercator???)…please help…
Ian Stevens Says:
September 14th, 2008 at 11:28 am
Sorry, PR. The tile cutter does not manipulate projections. The image has to already map to the same projection.
DamageInc Says:
September 22nd, 2008 at 7:10 am
There is a small bug in this when you give it an image with power-of-two dimensions where it will create one more tile than required (since it always rounds up).
I changed:
width=$((`echo $dim | sed -e “s/x.*//”`+$padX))
tileWidth=$(($width / 256 + 1))
height=$((`echo $dim | sed -e “s/.*x//”`+$padY))
tileHeight=$(($height / 256 + 1))
to:
width=$((`echo $dim | sed -e “s/x.*//”`+$padX))
tileWidth=$((($width - 1) / 256 + 1))
height=$((`echo $dim | sed -e “s/.*x//”`+$padY))
tileHeight=$((($height - 1) / 256 + 1))
and it seems to work fine.
Patrick Says:
October 2nd, 2008 at 3:38 pm
Excellent little tool.
I found that I had to rename the file with no extension to get a .jpg to be tiled on a mac OSX-10.5