GeoServer creates tiles of rendered WMS maps using GeoWebCache where as the GeoTools tutorial you found is splitting up an existing GeoTiff. These are different processes with as you note different outputs.
However, there is no difficulty in using GeoTools to split a GeoTiff into png or jpg images using the tutorial code. You simply need to change the output format when writing the tiles back to disk.
At the end of the tile
method are the output lines:
File tileFile = new File(tileDirectory, i + "_" + j + "." + fileExtension);
format.getWriter(tileFile).write(finalCoverage, null);
format
is the same object as was used to read in the coverage (a GeoTiff) but you can get other formats, for example a WorldImageWriter
will output georeferenced png or jpg tiles:
fileExtension = "png";
File tileFile = new File(tileDirectory, i + "_" + j + "." + fileExtension);
final WorldImageWriter wiWriter = new WorldImageWriter(tileFile);
// writing parameters for png
final Format oFormat = wiWriter.getFormat();
((AbstractGridFormat) oFormat).getWriter(tileFile).write(finalCoverage, null);
Or you can simply use an ImageWriter
Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix("jpg");
ImageWriter writer = null;
while (writers.hasNext()) {
writer = writers.next();
System.out.println(writer);
// break;
}
writer.setOutput(new ImageOutputStreamAdapter(new FileOutputStream(tileFile)));
writer.write(grid.getRenderedImage());
In both these cases you are writing out the raw data values with no styling applied, this may or may not be what you want. If you need to apply styling then you should look at the image tutorial for an example of how to style a raster and draw it to screen, you would need to provide an Image
to draw on instead of a screen and pass that Graphics2D
object to the renderer.