10.3. Setting Output Image Formats

 < Day Day Up > 

MapServer can produce map images, legends, and scale bars in different image formats. Throughout this chapter, the PNG format is shown in the examples because it is the default image format. MapServer packages can have different default image formats. PNG format is commonly supported by many MapServer packages, but in some cases MapServer may not be able to produce PNG files or doesn't produce them by default.

MapServer can be compiled using many different options. The term "MapServer package" refers to the set of programs, e.g., shp2img, that you are using. The capabilities of these programs depend on how they are compiled. Some packages will have more features enabled than others.


The output image format can be explicitly set in the map file. This requires adding a single line specifying the output format you are requesting. Example 10-11 shows the additional line added to the earlier example map file.

Example 10-11. Specifying the output image format as JPEG
 MAP   SIZE 600 300   EXTENT -180 -90 180 90   IMAGECOLOR 180 180 250   IMAGETYPE JPEG   UNITS DD ...

This setting can be overridden when using the shp2img command with the -i option. It can't be overridden when using commands such as scalebar or legend, as mentioned earlier in "Creating Your First Map Image."

The IMAGETYPE specified must be one supported by the MapServer package you are running. To check what output formats your installation supports, run the mapserv file (or mapserv.exe on Windows) with the -v option. This option tells you what input and output formats are supported by the utilities in your MapServer package. The following example shows the output from the MapServer used in this chapter, with the output image formats highlighted:

          > mapserv -v     MapServer version 4.4.1 OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP SUPPORTS=PROJ     SUPPORTS=FREETYPE SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER     SUPPORTS=WFS_CLIENT INPUT=EPPL7 INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE

This listing shows that this installation of MapServer can only output PNG, JPEG, or WBMP format files. That means the IMAGETYPE could be set to either of those three. Therefore it can't output GIF, TIFF, PDF, or any other formats.

WBMP images produced by MapServer appear to be unreadable. This may only be a problem for non-Windows environments.


For many vector-mapping applications, the PNG output format is sufficient. In many cases it will be the default output format. If you have a raster layer with more than 256 colors, it will probably not look right using the default PNG image type. Usually, all that is needed is to increase the depth of colors that MapServer creates in the output image. This can be set by requesting a 24-bit version of the PNG output format such as:

     IMAGETYPE PNG24

Be warned: increasing the color depth also increases the file size of your images. This can be a major performance issue when sending graphics across the web.

More specific output image format settings can be made using an OUTPUTFORMAT object in your map file. This is an advanced topic and isn't described here. Please refer to the MapServer documentation at http://mapserver.gis.umn.edu/doc/mapfile-reference.html#outputformat.

     < Day Day Up > 


    Web Mapping
    Web Mapping Illustrated: Using Open Source GIS Toolkits
    ISBN: 0596008651
    EAN: 2147483647
    Year: 2005
    Pages: 138

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net