AntiAliasing with MapServer

Author:

Pericles Nacionales

Contact:

naci0002 at umn.edu

Last Updated:

2009/01/17

Uyarı

This document is outdated. Since version 6.0, MapServer will produce aliased output for the “gd/” drivers, and antialiased output for the “agg/” and “cairo/” ones

Not

For quality antialiased output from mapserver, it is highly recommended to use the AGG rendering. This document applies only if you wish to stick to the GD rendering, or if you are using a version predating the 5.0 release of mapserver.

What needs to be done

1. Change (or add) IMAGETYPE keyword in MAP object to PNG24 (24-bit PNG output) or JPEG

MAP
  ...
  IMAGETYPE PNG24
  ...
END
  1. Add TRANSPARENCY to the LAYER object and set value to ALPHA

MAP
  ...
  IMAGETYPE PNG24
  ...

  LAYER
    ...
    TRANSPARENCY ALPHA
    ...
  END
END
  1. Add ANTIALIAS keyword to the STYLE object within the CLASS object within the LAYER and set value to TRUE

MAP
  ...
  IMAGETYPE PNG24
  ...

  LAYER
    ...
    TRANSPARENCY ALPHA
    ...
    CLASS
      ...
      STYLE
        ...
        ANTIALIAS TRUE
        ...
      END
      \.\.\.
    END # end class
  END # end layer
END # end map

Not

Don’t use the SYMBOL or the SIZE keywords within the CLASS object, instead use WIDTH to specify width of line or polygon outline. Don’t use WIDTH unless you have to. If you must define a SYMBOL, use symbol of type ELLIPSE–it supports antialiasing.

Here’s an example of a real-world mapfile:

Not

From MapServer 6, symbol type CARTOLINE is no longer supported. You have to use AGG rendering and STYLE PATTERN to achieve dashed lines. Therefore, the following example does not work anymore.

 1MAP
 2  NAME 'ms101'
 3  EXTENT -2198022.00 -2444920.25 2707932.00 1234545.25  # CONUS LAEA (US)
 4  SIZE 640 480
 5  SHAPEPATH 'data'
 6  SYMBOLSET 'symbols/symbols.txt'
 7
 8  IMAGETYPE PNG24
 9
10  PROJECTION
11    "init=epsg:2163"
12  END
13
14  # The layer below will be rendered as 1-pixel wide, antialiased line
15  # If you'd like to change the line thickness add the WIDTH keyword
16  # in the STYLE object with a value of 3 or greater.
17  LAYER # begin antialiased country boundary (line) layer
18    NAME 'country_line'
19    DATA 'shapefile/WorldCountryBorders.shp'
20    TYPE LINE
21    STATUS ON
22    TRANSPARENCY ALPHA
23
24    PROJECTION
25      "init=epsg:4326"
26    END
27
28    CLASS
29      NAME 'Country Boundary'
30      STYLE
31        COLOR 96 96 96
32        ANTIALIAS TRUE
33      END
34    END
35  END # end country boundary layer
36
37  # The layer below shows one way to draw a polygon with antialiased outline
38  LAYER # begin antialiased country boundary (polygon) layer
39    NAME 'country_line'
40    DATA 'shapefile/Countries_area.shp'
41    TYPE POLYGON
42    STATUS ON
43    TRANSPARENCY ALPHA
44
45    PROJECTION
46      "init=epsg:4326"
47    END
48
49    CLASS
50      NAME 'Country Boundary'
51      STYLE
52        COLOR 212 212 212
53        OUTLINECOLOR 96 96 96
54        WIDTH 3
55        ANTIALIAS TRUE
56      END
57    END
58  END # end country boundary polygon layer
59
60  # The layer below shows one way to draw a polygon with antialiased outline
61  LAYER # begin antialiased state boundary (line) layer
62    NAME 'state_line'
63    DATA 'shapefile/us_states.shp'
64    TYPE LINE
65    STATUS ON
66    TRANSPARENCY ALPHA
67
68    PROJECTION
69      "init=epsg:4326"
70    END
71
72    CLASS
73      NAME 'State Boundary'
74      STYLE
75        COLOR 144 144 144
76        SYMBOL 'cartoline'
77        ANTIALIAS TRUE
78      END
79    END
80  END # end state line layer
81END # end of map file

Here’s how the ‘cartoline’ symbol is defined:

Not

From MapServer 6, symbol type CARTOLINE is not available. You have to use AGG rendering and STYLE PATTERN to achieve dashed lines. Therefore, the following symbol can not be used anymore.

SYMBOL
  NAME 'cartoline'
  TYPE CARTOLINE
  LINECAP "round"
  LINEJOIN "round"
  LINEJOINMAXSIZE 3
END

Not

The examples provided here are for illustrative purposes only–keep your map file definitions simple. Antialiasing adds computing overhead on the server and could slow/degrade its performance. Don’t use it unless you must and certainly don’t use symbols with it unless you really have to.