Configure MapServer Cartography

Here we have tried to provide real life examples of symbology in iShare using MapServer along with a Symbols Gallery. See Symbols & Styling for other examples. 

You should create your own symbols file in the /mapserver/shared/symbols folder and copy any symbols that you wish from the supplied symbolsms6.1.sym file which you will find in the same folder. Then you will be able to edit this file without a subsequent upgrade to iShare overwriting your changes and as it will only contain the symbols you wish to use will make it easier to manage. Your new symbols file must start with a SYMBOLSET entry and have a matching END and then each individual SYMBOL entry with matching END e.g.

Symbols file
SYMBOLSET
 
	SYMBOL
		NAME 'hospitals'
		TYPE PIXMAP
		IMAGE "isharemaps/hospital-1.png"
	END
 
	SYMBOL
	  NAME 'circle'
	  TYPE ELLIPSE
	  FILLED TRUE
	  POINTS
	    1 1
	  END
	END
 
END

 

You will also need to edit the .MAP file and change the SYMBOLSET entry near the top to point to your new file e.g.

SYMBOLSET "d:/mapserver/shared/symbols/symbols_myfile.sym"

 

 

Polygon Fill Types

Using the HATCH symbol

The HATCH style allows for a line to be be used at any angle with any width, all defined in the .map file.

DescriptionCLASS snippet (from .map file)Thumbnail

Standard horizontal (no ANGLE)

 

		CLASS
			NAME ""
			STYLE
				COLOR 196 0 0
				SYMBOL "HATCH"
				SIZE 7
				WIDTH 1
			END
			STYLE 
				OUTLINECOLOR 196 0 0
				OUTLINEWIDTH 3
			END
		END
ANGLE 135
		CLASS
			NAME ""
			STYLE
				COLOR 196 0 0
				SYMBOL "HATCH"
				ANGLE 135
				SIZE 7
				WIDTH 1
			END
			STYLE 
				OUTLINECOLOR 196 0 0
				OUTLINEWIDTH 3
			END
		END
ANGLE 45
		CLASS
			NAME ""
			STYLE
				COLOR 0 0 196
				SYMBOL "HATCH"
				ANGLE 45
				SIZE 7
				WIDTH 1
			END
			STYLE 
				OUTLINECOLOR 0 0 196
				OUTLINEWIDTH 3
			END		
		END
ANGLE 90
		CLASS
			NAME ""
			STYLE
				COLOR 0 0 196
				SYMBOL "HATCH"
				ANGLE 90
				SIZE 7
				WIDTH 1
			END
			STYLE 
				OUTLINECOLOR 0 0 196
				OUTLINEWIDTH 3
			END		
		END

SIZE 10

  • how far inbetween

WIDTH 4

  • how wide the HATCH is
		CLASS
			NAME ""
			STYLE
				COLOR 0 0 196
				SYMBOL "HATCH"
				ANGLE 90
				SIZE 7
				WIDTH 1
			END
			STYLE 
				OUTLINECOLOR 0 0 196
				OUTLINEWIDTH 3
			END		
		END

Using Symbols for Filling Polygons

DescriptionLabel SnippetThumbnail

POINT fill with CIRCLE

The use of GAP and SIZE to change the spread and the size of the circles

 

NOTE a separate STYLE is needed for the OUTLINE

		CLASS
			NAME "Postcode Areas"
			MAXSCALEDENOM 20000
			STYLE
				SYMBOL "circle"
				SIZE 6
				GAP 6
				COLOR 196 0 0
				OPACITY 60
			END
			STYLE
				OUTLINECOLOR 196 0 0
				WIDTH 2
				OPACITY 60
			END
		END
	END	

Line Styles

DescriptionLabel SnippetThumbnail

Single Line

STYLE # thick outline 
   COLOR 25 29 173
   SIZE 2
END

Double Line

STYLE # thick outline 
   COLOR 0 0 0
   SIZE 6
END
STYLE # colour middle 
   COLOR 178 172 235
   SIZE 3
END

Point Styles

DescriptionLabel SnippetThumbnail

Simple PIXMAP (external graphic) symbol

Here the SYMBOL is definined in the relevant symbols .sym file or in the MAP header - See Symbols & Styling for other examples. 

		CLASS
			NAME ""
			STYLE
				SYMBOL "hospitals"
			END
		END

Scaled Symbology

Separate classes for scaled symbology and ensure that Legend Graphic isn't confusing. In this example there are three classes for emphasis.

In this example the size of the circle depends upon the zoom level.

		CLASS
			MAXSCALEDENOM 5000
			NAME ""
			STYLE
				SYMBOL "circle"
				COLOR 255 255 128
				OUTLINECOLOR 0 0 0
				SIZE 7
			END
		END
		CLASS
			STYLE
				SYMBOL "circle"
				COLOR 255 255 128
				OUTLINECOLOR 0 0 0
				SIZE 4
				MINSCALEDENOM 5000
				MAXSCALEDENOM 25000
			END
			STYLE
				SYMBOL "circle"
				COLOR 255 255 128
				SIZE 2
				MINSCALEDENOM 25000
			END			
		END

 

Graduated Point Thematic

Graduated symbol size is handled by using a numerical attribute for the symbol size. In this example there are two classes for emphasis.

The CLASSITEM entry defines the field that is to be used in the EXPRESSION etc. size_percent in this example.

  1. In the first CLASS we are saying that if the value of size_percent is less than 8, i.e. Minor Crime, then the colour will be blue. Also the size of the circle will be dependent upon the value of size_percent.
     
  2. In the second CLASS, which will catch anything that doesn't match the first CLASS EXPRESSION, i.e. Major Crime, then the colour will be red. Here also the size of the circle will be dependent upon the value of size_percent.



 

CLASSITEM "size_percent"
CLASS
	NAME "Minor Crime"
	EXPRESSION ([size_percent] < 8)
	STYLE
		SYMBOL "circle"
		SIZE [size_percent]
		COLOR 0 0 255
	END
END
CLASS
	NAME "Major Crime"
	STYLE
		SYMBOL "circle"
		SIZE [size_percent]
		COLOR 255 0 0
	END
END

Boundary Styles

DescriptionLabel SnippetThumbnail

Coloured Boundary – Transparent Fill

STYLE
   COLOR -1 -1 -1
   OUTLINECOLOR 222 0 0
   WIDTH 2
END

Coloured Boundary – Coloured Fill

STYLE
   COLOR 156 215 57
   OUTLINECOLOR 0 0 0
   WIDTH 2
END

Labelling

DescriptionLabel SnippetThumbnail

Label - with POSITION UC

Place the Label as Upper Centre

		CLASS
			NAME ""
			STYLE
				SYMBOL "circle"
				COLOR 0 196 0
				OUTLINECOLOR 255 255 255
				SIZE 16
			END
			LABEL
				FONT "verdana"
				TYPE truetype
				SIZE 8
				POSITION UC
				COLOR 0 0 0
				OUTLINECOLOR 255 255 255
				OUTLINEWIDTH 3
				MAXLENGTH 12
				WRAP " "
				ALIGN CENTER
				BUFFER 10
			END		
		END

Concatenate fields (TEXT) and then WRAP on their comma

		CLASS
			NAME ""
			TEXT "[stop_name],[place],[postcode]"
			STYLE
				SYMBOL "triangle"
				COLOR 0 196 0
				OUTLINECOLOR 255 255 255
				SIZE 16
			END
			LABEL
				FONT "verdana"
				TYPE truetype
				SIZE 8
				POSITION UC
				COLOR 0 0 0
				OUTLINECOLOR 255 255 255
				OUTLINEWIDTH 3
				MAXLENGTH 12
				WRAP ","
				ALIGN CENTER
				BUFFER 10
			END		
		END

Concatenate fields inside an SQL if using PostgreSQL

(as opposed to the TEXT "[field1] field2 etc"

 

This gives utmost flexibility to how the text can be treated

DATA "wkb_geometry from
 (select *, coalesce(pn::text,rn::text) as hwy_name 
from upload_multi.hw_saltng_ntwrk) 
as foo using 
unique ogc_fid 
using srid=27700"
LABELITEM "hwy_name"
 

ANGLE FOLLOW and MINFEATURESIZE AUTO

With the second screen shot you can see how the labelling can now fit within the FEATURE and therefore MINFEATURESIZE AUTO allows for this

 

MINFEATURESIZE also allows for the restriction according to the Minimum Bounding Rectangle of a feature (in pixels)

		CLASS
			NAME ""
			STYLE
				PATTERN 10 5 5 10 END
				WIDTH 2
				COLOR 0 0 255
				OUTLINECOLOR 255 255 255
				
			END
			LABEL
				FONT "verdana"
				TYPE truetype
				SIZE 7
				POSITION LC
				COLOR 0 0 255
				OUTLINECOLOR 255 255 255
				OUTLINEWIDTH 4
				ANGLE FOLLOW
				MINFEATURESIZE AUTO
			END	

How can I label certain features and not others?

 

CLASS
   NAME "Capitals"
   TEXT ([NAME])
   EXPRESSION "1"
   STYLE
      SYMBOL "square"
      COLOR 0 0 0
      SIZE 6
   END
   LABEL
      FONT "arialbd"
      TYPE TRUETYPE
      COLOR 0 0 255
      OUTLINECOLOR 255 255 255
      SIZE 10
      POSITION cc
   END         
END
CLASS
   NAME "Others"         
   EXPRESSION ([Rank] > 1)
   STYLE
      SYMBOL "circle"
      COLOR 255 0 0
      SIZE 3
   END
END

As above with extra Label with different colour.

 

CLASS
   NAME "Capitals"
   TEXT ([NAME])
   EXPRESSION "1"
   STYLE
      SYMBOL "square"
      COLOR 0 0 0
      SIZE 6
   END
   LABEL
      FONT "arialbd"
      TYPE TRUETYPE
      COLOR 0 0 255
      OUTLINECOLOR 255 255 255
      SIZE 10
      POSITION cc
   END         
END
CLASS
   NAME "Others"         
   EXPRESSION ([Rank] > 1)
   STYLE
      SYMBOL "circle"
      COLOR 255 0 0
      SIZE 3
   END
   TEXT ([NAME])
   LABEL
      FONT "arialbd"
      TYPE TRUETYPE
      COLOR 255 0 0
      OUTLINECOLOR 255 255 255
      SIZE 8
      POSITION cr
   END         
END

 

Filtering

DescriptionLayer snippetThumbs

How do I filter a layer to only certain features?

 

Change the counties layer to include - see the Layer snippet --> 

 

Please note this is different to only drawing certain features as it is like having a subquery.

      FILTER "Cumbria"
      FILTERITEM "name"

 

How do I filter a layer to only draw certain features based on a field value?

Change the mainplaces Layer - see the Layer snippet --> 

 

Have &Layer=mainplaces in the URL.

CLASSITEM "Rank"
      CLASS
         NAME "Capitals"
         EXPRESSION "1"
         STYLE
           SYMBOL "square"
           COLOR 0 0 0
           SIZE 6
         END
      END

How do I filter a layer to draw certain features in different styles based on a field value?

Change the mainplaces Layer - see the Layer snippet --> 

 

Have &Layer=mainplaces in the URL.

CLASSITEM "Rank"
CLASS
   NAME "Capitals"
   EXPRESSION "1"
   STYLE
      SYMBOL "square"
      COLOR 0 0 0
      SIZE 6
   END
END
CLASS
   NAME "Others"         
   EXPRESSION ([Rank] > 1)
   STYLE
      SYMBOL "circle"
      COLOR 255 0 0
      SIZE 3
   END
END
 

Advanced Scaled Symbology

DescriptionLayer snippetThumbs
Variable points styles depending on the scale of the map
		CLASS
			NAME ""
			MAXSCALEDENOM 50000
			STYLE
				SYMBOL "square"
				COLOR 255 128 0
				OUTLINECOLOR 255 255 255
				SIZE 16
			END
			STYLE
				SYMBOL "C"
				COLOR 255 255 255
				SIZE 10
			END
			LABEL
				FONT "verdana"
				TYPE truetype
				SIZE 8
				POSITION UC
				COLOR 255 128 0
				OUTLINECOLOR 255 255 255
				OUTLINEWIDTH 3
				BUFFER 10
				MAXSCALEDENOM 10000
			END		
		END

 

 

 

A little more complexity, if boundaries are too complex then transform the geometries (GEOMTRANSFORM) to their centroids at a certain scale


Other options include (from MapServer site)

GEOMTRANSFORM [bbox|end|labelpnt|labelpoly|start|vertices|<expression>]

Used to indicate that the current feature will be transformed before the actual style is applied. Introduced in version 5.4.

  • bbox: produces the bounding box of the current feature geometry.

  • centroid: produces the centroid of the current feature geometry.

  • end: produces the last point of the current feature geometry.

  • labelpnt: used for LABEL styles. Draws a marker on the geographic position the label is attached to.

  • labelpoly: used for LABEL styles. Produces a polygon that covers the label plus a 1 pixel padding.

  • start: produces the first point of the current feature geometry.

  • vertices: produces all the intermediate vertices (points) of the current feature geometry (the start and end are excluded).

  • <expression>: Applies the given expression to the geometry. Supported expressions:

    • (buffer([shape],dist)): Buffer the geometry ([shape]) using dist pixels as buffer distance.
    • (simplify([shape],tolerance)): simplifies a geometry ([shape]) .
    • (simplifypt([shape],tolerance)): simplifies a geometry ([shape])
    • (generalize([shape],tolerance)): simplifies a geometry
    • (smoothsia([shape], smoothing_size, smoothing_iteration, preprocessing)): will smooth a geometry ([shape]) using the SIA algorithm

    Example (polygon data set) - draw a two pixel wide line 5 pixels inside the boundary of the polygon:

     

    STYLE
      OUTLINECOLOR 255 0 0
      WIDTH 2
      GEOMTRANSFORM (buffer([shape],-5))
    END


		CLASS
			NAME "Postcode Areas"
			MAXSCALEDENOM 20000
			STYLE
				SYMBOL "circle"
				SIZE 6
				GAP 6
				COLOR 196 0 0
				OPACITY 60
			END
			STYLE
				OUTLINECOLOR 196 0 0
				WIDTH 2
				OPACITY 60
			END
			LABEL
				FONT "verdana"
				TYPE truetype
				SIZE 8
				POSITION UC
				COLOR 196 0 0
				OUTLINECOLOR 255 255 255
				OUTLINEWIDTH 3
				MAXLENGTH 12
				WRAP ","
				ALIGN CENTER
				BUFFER 10
				MAXSCALEDENOM 10000
			END		
		END
		CLASS
			NAME "Postcode Points"
			STYLE
				MINSCALEDENOM 20000
				SYMBOL "circle"
				GEOMTRANSFORM CENTROID
				COLOR 196 0 0
				OUTLINECOLOR 255 255 255
				SIZE 6
			END
		END	
	END	

 

 

 

Clusters

 

DescriptionSnippetThumb

CLUSTERS

This layer is combined with the hw_road_accidents layer it is purely for display purposes highlighting some of the advanced functionality of MapServer

 

Note the class Accident Clusters in the layer hw_road_accidents - the second class isn't used for map display (due to MAXSCALEDENOM) but is here for the GetLegendGraphic request

Cluster layer - hw_road_accidents_display
	LAYER 
		NAME "hw_road_accidents_display"
		REQUIRES "[hw_road_accidents]"
		STATUS DEFAULT
		TYPE POINT
		INCLUDE "datashare.inc"
		DATA "wkb_geometry from 
			(select * from upload_multi.ecc_road_acc) as foo
			 using unique ogc_fid using srid=27700"
		LABELITEM "Cluster:FeatureCount"
		CLASSITEM "Cluster:FeatureCount"
		CLUSTER
			MAXDISTANCE 50
			REGION "rectangle"
		END
		MINSCALEDENOM 25000
		CLASS
			NAME "Road Accidents"
			EXPRESSION ("[Cluster:FeatureCount]" == "1")
			STYLE
				SYMBOL "circle"
				SIZE 8
				COLOR 255 255 255
				OUTLINECOLOR 40 40 40
				WIDTH 2
			END
		END
		CLASS
			EXPRESSION ([Cluster:FeatureCount]>100 )
			NAME "Road Accidents"
			STYLE
				SYMBOL "circle"
				SIZE 50
				OUTLINECOLOR 0 0 0
				WIDTH 6
				OPACITY 10
			END	
			STYLE
				SYMBOL "circle"
				SIZE 40
				OUTLINECOLOR 0 0 0
				WIDTH 6
				OPACITY 30
			END			
			STYLE
				SYMBOL "circle"
				SIZE 32
				COLOR 255 255 255
				OUTLINECOLOR 40 40 40
				WIDTH 3
			END
			LABEL
				FONT "arialbd"
				TYPE truetype
				SIZE 10
				COLOR 0 0 0
				OUTLINECOLOR 255 255 255
			END
		END
		CLASS
			EXPRESSION ([Cluster:FeatureCount]>50 
				AND [Cluster:FeatureCount]<100 )
			NAME "Street crime"
			STYLE
				SYMBOL "circle"
				SIZE 40
				#COLOR 255 255 255
				OUTLINECOLOR 0 0 0
				WIDTH 6
				OPACITY 10
			END	
			STYLE
				SYMBOL "circle"
				SIZE 32
				#COLOR 255 255 255
				OUTLINECOLOR 0 0 0
				WIDTH 6
				OPACITY 30
			END			
			STYLE
				SYMBOL "circle"
				SIZE 24
				COLOR 255 255 255
				OUTLINECOLOR 40 40 40
				WIDTH 3
			END
			LABEL
				FONT "arialbd"
				TYPE truetype
				SIZE 8
				COLOR 0 0 0
				#OUTLINECOLOR 255 255 255
			END
		END
		CLASS
			EXPRESSION ([Cluster:FeatureCount]>20 
				AND [Cluster:FeatureCount]<50 )
			NAME "Street crime"
			STYLE
				SYMBOL "circle"
				SIZE 30
				COLOR 255 255 255
				OUTLINECOLOR 0 0 0
				WIDTH 6
				OPACITY 10
			END	
			STYLE
				SYMBOL "circle"
				SIZE 24
				COLOR 255 255 255
				OUTLINECOLOR 0 0 0
				WIDTH 6
				OPACITY 30
			END			
			STYLE
				SYMBOL "circle"
				SIZE 16
				COLOR 255 255 255
				OUTLINECOLOR 40 40 40
				WIDTH 3
			END
			LABEL
				FONT "arialbd"
				TYPE truetype
				SIZE 8
				COLOR 0 0 0
				OUTLINECOLOR 255 255 255
			END
		END
		CLASS
			EXPRESSION ([Cluster:FeatureCount]<20)
			NAME "Street crime"
			STYLE
				SYMBOL "circle"
				SIZE 26
				COLOR 255 255 255
				OUTLINECOLOR 0 0 0
				WIDTH 6
				OPACITY 10
			END	
			STYLE
				SYMBOL "circle"
				SIZE 20
				COLOR 255 255 255
				OUTLINECOLOR 0 0 0
				WIDTH 6
				OPACITY 30
			END			
			STYLE
				SYMBOL "circle"
				SIZE 16
				COLOR 255 255 255
				OUTLINECOLOR 40 40 40
				WIDTH 3
			END
			LABEL
				FONT "arialbd"
				TYPE truetype
				SIZE 8
				COLOR 0 0 0
				OUTLINECOLOR 255 255 255
			END
		END
	END

hw_road_accidents
	LAYER 
		NAME "hw_road_accidents"
		STATUS OFF
		TYPE POINT
		INCLUDE "datashare.inc"
		DATA "wkb_geometry from 
			(select * from upload_multi.ecc_road_acc) as foo
			 using unique ogc_fid using srid=27700"
		TOLERANCE 100
		UNITS PIXELS
		CLASS
			NAME "Actual accidents"
			STYLE
				MAXSCALEDENOM 25000
				SYMBOL "circle"
				SIZE 5
				COLOR 255 0 0 
			END			
		END
		CLASS
			NAME "Accident clusters"
			MAXSCALEDENOM 1
			STYLE
				SYMBOL "circle"
				SIZE 26
				COLOR 255 255 255
				OUTLINECOLOR 0 0 0
				WIDTH 6
				OPACITY 10
			END	
			STYLE
				SYMBOL "circle"
				SIZE 20
				COLOR 255 255 255
				OUTLINECOLOR 0 0 0
				WIDTH 6
				OPACITY 30
			END			
			STYLE
				SYMBOL "circle"
				SIZE 16
				COLOR 255 255 255
				OUTLINECOLOR 40 40 40
				WIDTH 3
			END
		END		
	END

 

 

Legend Graphics

  • Rely on NAME entry on CLASS
  • If no NAME entry then ignored - extremely powerful

MasterMap Examples

DescriptionLabel SnippetThumbnail

GoLoader

Showing an area of Coniferous trees

CLASSITEM "OSMMSTYLE_NAME"
CLASS
   EXPRESSION "scatteredConiferousTreePattern"
   STYLE
     COLOR 224 224 224
     OUTLINECOLOR 204 204 204
     SYMBOL "0380Scattered"
   END
END
 

TranspOSe/SuperpOSe

Showing an area of Non Coniferous trees

CLASSITEM "Legend"
CLASS
   EXPRESSION "0384 Nonconiferous trees"
   STYLE
     COLOR 0 0 0
     OUTLINECOLOR 204 204 204
     SYMBOL "0384"
   END
END