Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.

Code Block
languagebash
      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.

Code Block
languagebash
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.

Code Block
languagebash
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
Code Block
languagebash
		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:

     

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


Code Block
languagebash
		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 - Advanced Styling

 

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

Code Block
titleCluster layer - hw_road_accidents_display
linenumberstrue
collapsetrue
	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

Code Block
titlehw_road_accidents
linenumberstrue
	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

 

 

 

NHS Choices

Image Removed
DescriptionSnippetThumb

Dentists

Image Removed

Code Block
	LAYER
        NAME nhsdentists
        STATUS OFF
        TYPE POINT
        INCLUDE "datashare.inc"
        DATA "wkb_geometry from 
			(select * from nhschoices.dentists) as foo 
			using unique ogc_fid using srid=27700"
        TOLERANCEUNITS PIXELS
        CLASS
			NAME "supplied by nhs choices"
            STYLE
                 SYMBOL "dentists"
            END
        END
	END
Image Removed

Doctors

Image Removed

Code Block
	LAYER
        NAME nhsdoctors
        STATUS OFF
        TYPE POINT
        INCLUDE "datashare.inc"
        DATA "wkb_geometry from 
			(select * from nhschoices.doctors) as foo 
			using unique ogc_fid using srid=27700"
        TOLERANCEUNITS PIXELS
        CLASS
			NAME "supplied by nhs choices"
            STYLE
                 SYMBOL "doctors"
            END
        END
	END
Image Removed

Hospitals

Image Removed

Code Block
	LAYER
        NAME nhshospitals
        STATUS OFF
        TYPE POINT
        INCLUDE "datashare.inc"
        DATA "wkb_geometry from 
			(select * from nhschoices.hospitals) as foo 
			using unique ogc_fid using srid=27700"
        TOLERANCEUNITS PIXELS
        CLASS
			NAME "supplied by nhs choices"
            STYLE
                 SYMBOL "hospitals"
            END
        END
	END	
Image Removed

Opticians

Image Removed

Code Block
	LAYER
        NAME nhsopticians
        STATUS OFF
        TYPE POINT
        INCLUDE "datashare.inc"
        DATA "wkb_geometry from 
			(select * from nhschoices.opticians) as foo 
			using unique ogc_fid using srid=27700"
        TOLERANCEUNITS PIXELS
        CLASS
			NAME "supplied by nhs choices"
            STYLE
                 SYMBOL "opticians"
            END
        END
	END	
Image Removed

Pharmacies

Image Removed

Code Block
	LAYER
        NAME nhspharmacies
        STATUS OFF
        TYPE POINT
        INCLUDE "datashare.inc"
        DATA "wkb_geometry from 
			(select * from nhschoices.pharmacies) as foo 
			using unique ogc_fid using srid=27700"
        TOLERANCEUNITS PIXELS
        CLASS
			NAME "supplied by nhs choices"
            STYLE
                 SYMBOL "pharmacies"
            END
        END
	END	

Legend Graphics

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

...