.. index::
   pair: Optimization; Raster

.. _raster_optimization:

*****************************************************************************
 Raster
*****************************************************************************

:Author:        HostGIS 
:Last Updated: 2008/08/08

.. contents:: Table of Contents
    :depth: 2
    :backlinks: top



Overviews
---------
TIFF supports the creation of "overviews" within the file, which is basically a
downsampled version of the raster data suitable for use at lower resolutions.
Use the "gdaladdo" program to add overviews to a TIFF, and MapServer (via GDAL)
will automagically choose which downsampled layer to use. Note that overviews
significantly increase the disk space required by a TIFF, and in some cases the
extra disk reading may offset the performance gained by MapServer not having to
resample the image. You'll just have to try it for yourself and see how it
works.

.. index::
   triple: Optimization; Raster; Tiling

Tileindexes and Internal Tiling
-------------------------------
Tiling is mostly effective for cases where one commonly requests only a very
small area of the image. 

A tileindex is how one creates an on-the-fly mosaic from many rasters. This is
described in the :ref:`tileindex`. That document describes common cases where
a tileindex makes sense. In particular, if you have a very large raster and
most requests are for a very small spatial area within it, you may want t
consider slicing it and tileindexing it.

As an alternative to slicing and mosaicing, TIFFs do support a concept of
internal tiling. Like a tileindex, this is mostly effective when the requests
are for a small portion of the raster. Internal tiling is done by adding "-co
TILED=YES" to gdal_translate, e.g.:

:: 

    gdal_translate -co TILED=YES original.tif tiled.tif
    
.. index::
   pair: Optimization; Image formats

Image formats
-------------

The TIFF image format is the fastest to "decipher", but once you get beyond a
certain point, the disk reading (since TIFF is very large) may become slow
enough to make it worthwhile to consider other image formats.

For TIFFs larger than 1 GB, ECW images tend to render faster than TIFFs, since
decompressing the data (CPU and RAM) is faster than reading the uncompressed
data (disk). The downside is that ECW is not open-source, and the licensing is
often prohibitive.

JPEG2000 is a very slow image format, as is JPEG.

Remote WMS
----------

Remote WMS servers are often slow, especially the public ones such as
TerraServer or NASA's Landsat server. There's nothing you can do about that,
except to reconsider when the remote WMS layer should be used.

For example, there may be a different WMS server (or a different set of
imagery, or even vector outline maps) suitable for drawing the countries or
states to orient the user. You could then have the WMS layer come on at a
certain scale, or have the layer always available but turned off so the user
can choose when to turn it on.

.. seealso::
    :ref:`raster`

.. #### rST Link Section ####

