tags:

views:

303

answers:

5

hi i want to write a mapviewer, i must to work small tile of big map image file and there is need to tiling the big image, the problem now is to tiling big image to small tiles (250 * 250 pixel or like this size) so on, i used ImageMagic program to do it but there was problem now is any other programing method or application that do tiling? can i do it with JAI in java? how?

A: 

imagemagick does tiling using -tile. It's more of a repitition of an image, but might be useful esp. since youre already using it. However If you mean generated seamless tiling I'm not sure if imagemagick can do that or not.

Jamie
+2  A: 

For the large images sizes like you have, you will be best served with lossless editing of the JPEG files. Not only is this faster, since the image doesn't need to be rendered, but it also preserves quality, since the image is not recompressed.

Lossless editing works on blocks, typically 16px square. While restrictive for some applications, this seems a good fit for mapping. You could implement tiling at different zoom levels by first losslessly cropping the image to sized pieces. (This is quick an efficient since the image is not rendered.) This gives you tiles for full-zoom. To create lower-levels of zoom, combine 2x2 tiles and scale these down to the size of 1 tile. The next level uses 4x4 tiles, and 8x8 and so on, each time scaling down to one tile. At some point when the number of tiles beecomes too large, you can choose to use zoomed tiles as the base resource. For example, at zoom level 8, that would require 256x256 tiles. This might be too much to handle, so you could use 16x16 tiles from zoom level 4.

Wikipedia has more on lossless editing, and links to some implementing libraries.

mdma
A: 

GDAL comes with a script called gdal2tiles.py that does exactly what you want, including formatting the tiles for use with Google Maps, OpenLayers, etc.

There seems to be an newer version of GDAL2Tiles as well.

Daniel Pryden
A: 

How about a megatexture with an r-tree for efficient access? Apparently it can use images 128000x128000 pixels.

feelie
+3  A: 

Have you tried doing it in java yourself? I tried this with (WARNING, big image, can crash your browser, use "save as...") this image. Needed to run with extra memory though (-Xmx400M).

public class ImageTile {
    public static void main(String[] args) throws IOException {
        Dimension tileDim = new Dimension(250, 250);
        BufferedImage image = ImageIO.read(new File(args[0]));

        Dimension imageDim = new Dimension(image.getWidth(), image.getHeight());

        for(int y = 0; y < imageDim.height; y += tileDim.height) {
            for(int x = 0; x < imageDim.width; x += tileDim.width) {

                int w = Math.min(x + tileDim.width,  imageDim.width)  - x;
                int h = Math.min(y + tileDim.height, imageDim.height) - y;

                BufferedImage tile = image.getSubimage(x, y, w, h);
                ImageIO.write(tile, "JPG", new File("tile-"+x+"-"+y+".jpg")); 
            }
        }
    }
}
dacwe