MapServer banner Home | Docs | Issue Tracker | FAQ | Download
en de es fr zh_cn it

AntiAliasing with MapServer

Author:Pericles Nacionales
Contact:naci0002 at umn.edu
Revision:$Revision$
Date:$Date$
Last Updated:2009/01/17

Note

For quality antialiased output from mapserver, it is highly recommended to use the AGG rendering. This document applies only if you whish 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

Note

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:

Note

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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
MAP
  NAME 'ms101'
  EXTENT -2198022.00 -2444920.25 2707932.00 1234545.25  # CONUS LAEA (US)
  SIZE 640 480
  SHAPEPATH 'data'
  SYMBOLSET 'symbols/symbols.txt'

  IMAGETYPE PNG24

  PROJECTION
    "init=epsg:2163"
  END

  # The layer below will be rendered as 1-pixel wide, antialiased line
  # If you'd like to change the line thickness add the WIDTH keyword
  # in the STYLE object with a value of 3 or greater.
  LAYER # begin antialiased country boundary (line) layer
    NAME 'country_line'
    DATA 'shapefile/WorldCountryBorders'
    TYPE LINE
    STATUS ON
    TRANSPARENCY ALPHA

    PROJECTION
      "init=epsg:4326"
    END

    CLASS
      NAME 'Country Boundary'
      STYLE
        COLOR 96 96 96
        ANTIALIAS TRUE
      END
    END
  END # end country boundary layer

  # The layer below shows one way to draw a polygon with antialiased outline
  LAYER # begin antialiased country boundary (polygon) layer
    NAME 'country_line'
    DATA 'shapefile/Countries_area'
    TYPE POLYGON
    STATUS ON
    TRANSPARENCY ALPHA

    PROJECTION
      "init=epsg:4326"
    END

    CLASS
      NAME 'Country Boundary'
      STYLE
        COLOR 212 212 212
        OUTLINECOLOR 96 96 96
        WIDTH 3
        ANTIALIAS TRUE
      END
    END
  END # end country boundary polygon layer

  # The layer below shows one way to draw a polygon with antialiased outline
  LAYER # begin antialiased state boundary (line) layer
    NAME 'state_line'
    DATA 'shapefile/us_states'
    TYPE LINE
    STATUS ON
    TRANSPARENCY ALPHA

    PROJECTION
      "init=epsg:4326"
    END

    CLASS
      NAME 'State Boundary'
      STYLE
        COLOR 144 144 144
        SYMBOL 'cartoline'
        ANTIALIAS TRUE
      END
    END
  END # end state line layer
END # end of map file

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

Note

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

Note

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.