Rendering Smooth Contour With MapServer

As part of the new features of the next release of MapServer (6.4), two of them are particularly interesting if you used to work with contours data:

Here is a small example that uses both features as demonstration purpose. I assume you already know how to create a mapfile with MapServer.

Create a Vector Contour Layer

With a contour dataset (raster), you can define a MapServer contour layer as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
LAYER
  NAME "MyContourLayer"
  STATUS DEFAULT
  DATA "wind.tif"
  TYPE LINE
  CONNECTIONTYPE CONTOUR
  PROJECTION AUTO END
  PROCESSING "BANDS=1"
  PROCESSING "CONTOUR_ITEM=elevation"
  PROCESSING "CONTOUR_INTERVAL=0,0:1"
  CLASS
    EXPRESSION ([elevation] >= 0)
    STYLE
      COLOR 0 0 255
    END # STYLE
  END # CLASS
END # LAYER

you will get a contour layer rendered directly in MapServer:

You will notice that the lines are non-smooth curves and it will be worst if you zoom in. Using shape smoothing is very useful for thoses cases.

Enable Smoothing

You can enable the smoothing with the GEOMTRANSFORM directive in the layer (or style) definition:

1
2
3
...
  GEOMTRANSFORM (smoothsia([shape], 5))
...

The rendering is lot nicer with smoothing. These new features are available in the development version of MapServer. You can refer to their RFCs for more information.

Comments