crazed monkey

Ian Stevens’ weblog

RSS

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.

Tags:
  • 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.

10 Responses to “Unix command-line tile cutter for Google Maps”

  1. 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

  2. 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.

  3. 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: […]

  4. 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 […]

  5. 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

  6. 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 imagemagick should 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.

  7. 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 […]

  8. 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

  9. 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

  10. 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.

Leave a Reply