European Forum for Geo-Statistics 2009
Haag, 5 - 7 October 2009
Session 5: Small areas and web mapping technologies
WMS and statistics on grids
Introduction of WMS in Statistics Norway
Prepared by Marianne Vik Dysterud- - Statistics Norway
Background
Statistics Norway (SSB) is obliged through a partnership in Norway digital (a nation-wide program for co-operation on establishment, maintenance and distribution of digital geographic data) to provide geo referenced statistics on different regional levels. Data should be made available both for download and as WMS services.
What is a WMS
From OGC:The OpenGIS® Web Map Service Interface Standard (WMS) provides a simple HTTP interface for requesting geo-registered map images from one or more distributed geospatial databases. A WMS request defines the geographic layer(s) and area of interest to be processed. The response to the request is one or more geo-registered map images (returned as JPEG, PNG, etc) that can be displayed in a browser application. The interface also supports the ability to specify whether the returned images should be transparent so that layers from multiple servers can be combined or not.
The first WMS in Statistics Norway
The prioritized statistic theme for dissemination via WMS in SSB was Population statistics on 1x1 kilometre square grid.
The WMS for Population statistics supports 4 requests – GetCapabilities, GetMap, GetLegendGraphic and GetFeatureInfo.
GetCapabilities returns an XML-file where the first part could looksomething like:
GetMap returns a map picture. Example of Population statistics on 1x1 square grid for Norway:
GetLegendGraphic returns a picture of the legend specified in the request. Example:
GetFeatureInfo returns information of the geographic object specified in the request. Example:
The above examples are all runfrom the Address line in the Explorer. But the strength of a WMS is that it could be called from any other web Application by a URL. The URL includes different parameters that can be set dynamically by the web Application.
Example of the WMS included in uDIG (an Open Source GIS program). The Population statistics is combined with County bordersfor Norway:
Getting started
SSB had to upgrade skills in building WMS. Some partners in Norway digital recommended software and a Norwegian consultancy (Avinet) was hired in the start-up period. The preferred software is MapServer developed by University of Minnesota. MapServer is an Open Source product and included in different software packages like MS4W (MapServer for Windows). The basic MS4W package installs a preconfigured Web Server environment that includes the following components:
- Apache HTTP Server version 2.2.11
- PHP version 5.3.0
- MapServer CGI 5.4.2
- MapScript 5.4.2 (CSharp, Java, PHP, Python)
- Includes support for Oracle 11g, and SDE data (if you have associated client/dlls)
- MrSID support built-in
- GDAL/OGR 1.6.1 and Utilities
- MapServer Utilities
- PROJ Utilities
- Shapelib Utilities
- Shp2tile Utility
- Shpdiff Utility
- AVCE00 Utilities
- OGR/PHP Extension 1.0.0
- OWTChart 1.2.0
MS4W is Open Source platform and can be downloaded from
For the time being SSB has no available geo-database hence shape files are used as data source. Due to this a challenge was to establish a suitable data and catalogue structure which simplifies updating the WMS when new datasets are produced.
The consultancy firm made a kind of small “framework”. This framework exists of a MapScript (PHP), environment adaptations, HTML templates, symbol files and required MapServer code – the Mapfile. The Mapfile is the heart of MapServer. It defines the relationships between objects, and points MapServer to where data are located and defines how things are to be drawn. To make a most efficient Mapfile as regards updates the INCLUDE statement is recommended to an extensive use. In this way code can be updated one place, but used a lot of places.
In SSB some naming “standards” are chosen for file extensions for different files to be INCLUDEd in the Mapfile. This is done for easy readability and understanding. Examples are .lay for layer, .class for class and .map_start for the first lines in a Mapfile.
Example of INCLUDE used in a Mapfile:
ssb_rutenett.map :
MAP
DEBUG 3
#INCLUDE "ssb_win.map_start" # when running on på Windows
INCLUDE "ssb_linux.map_start" # when running on Linux
….
….
INCLUDE "SSB_signatur.lay"
INCLUDE "SSB_bef_2008.lay"
INCLUDE "SSB_bef_2007.lay"
And one example for a “layer” file:
SSB_bef_2008.lay:
LAYER
GROUP befolkningsdata
NAME "Bef_2008"
PROJECTION
"init=epsg:32633"
END
….
…
DATA "Befolkningsdata/År2008/Rutenett1000Meter/totalt"
…
….
INCLUDE "SSB_bef_rute.class"
Notice that INCLUDE can be used in several levels which really simplifies maintenance of a WMS.
Web Application on for statistics on 1x1 square grids - tentative plans
Due to great demand for statistics on grids Statistics Norway hasmade some tentative plans for a user friendly web application. The idea is to let the end user select statistical grid data from the Norwegian statistical database (Statbank) in combination with different thematic maps. The thematic maps could be fetched as shapefiles, geo-database or as WMS-services from internal and external data providers. The maps can be ticked on and off by the end user.
A simple sketch for the planned application:
The application is within the biggest green square and communication to the “surroundings” is illustrated by the yellow arrows.
Some general tips
Text editors
TextPad is a good editor for Mapfiles included layers and class information.
WordPad is the preferred for editing Symbol files.
Tuning a WMS
Build indexes in the shapefile (c:\>shptree <shape name>.shp)
Reduce the EPSG file containing references to almost all coordinate systems in the world (delete all lines in /ms4w/proj/nad/epsg that are of no interest). For Norway the reduction of the file was from 523KB to 3KB. This has a great effect while this file is called for every WMS request.
Colour selection
Web Safe Colours is recommended. That assures colours to be shown equally independent of browsers used.
Getting Help
The MapServer documentation is recommended while developing WMS services. But also is a place worth a visit.
Further a lot of information and Questions&Answers on the Internet – Google!.
Linux vs Windows
Experience shows that MapServer works a bit different in Windows environment (which was used in the development phase) and on Linux (which is our production environment).
An important observation was that the library php_mapscript.so must be loaded in the beginning of the Mapscript file when running on Linux. But not on Windows – that gives error.
Example in the beginning of the PHP-file (text in cursive): dl('php_mapscript.so');
1