Introduction

This document describes how to use UMN MapServer with Ordnance Survey data.

MapServer will probably have some performance issues if you're using it in an AJAX environment, but it's worth trying first.

These instructions describe the process on Microsoft Windows, however it should be easy to apply them on a unix platform.

Initial download and install

Download MapServer
    http://mapserver.org/download

Unzip to
    C:\MS4W\

You can change the drive *letter* only

To avoid conflicts with things like Microsoft IIS, I would suggest changing the port it listens on from 80 to 81 eg....
    "C:\ms4w\Apache\conf\httpd.conf"
Change listen port from 80 to 81.

Go to C:\ms4w\apache\bin and run httpd.exe

The tutorial is good...
    http://biometry.gis.umn.edu/tutorial/
I'd only worry about the first section for WFS/WMS funcitonality.

After you've installed that, this URL should work...
    http://localhost:81/tutorial/example1-1.html
This should display a map using this URL...
    http://localhost:81/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example1-1.map&layer=states&layer=states_line&mode=map

A working example of the tutorial project should be hosted here so you can see what you should be getting...
    http://biometry.gis.umn.edu/tutorial/example1-1.html

Using the MapServer tools

Getting the mapserver installed tools to work sensibly for data that's not on the same disk.

Copy...
    C:\ms4w\setenv.bat
To...
    C:\ms4w\setenv2.bat

Edit setenv2.bat and replace all paths that start with "\" with "c:\"
eg.
    set PATH=\ms4w\Apache\cgi-bin;\ms4w\tools\gdal-ogr; ...
becomes...
    set PATH=C:\ms4w\Apache\cgi-bin;C:\ms4w\tools\gdal-ogr; ...

TODO: Find out what %[Something] will get replaced with "C:\MS4W\" (on Win2K+)

Run setenv2 and you should be able to run:

Importing Raster Data (OS StreetView, 250K, 50K, 10K etc)

Note: You can have one root data directory per MapServer map called the "SHAPEPATH". We're going to use "C:\GIS1\Maps\" and try to work with relative paths from there.

Sensible folders for maps might be...
    C:\GIS1\Maps\250K\
    C:\GIS1\Maps\50K\
    C:\GIS1\Maps\StreetView\

Download the appropriate georeference files from the Ordnance Survey...- use TFW format...
    http://www.ordnancesurvey.co.uk/oswebsite/products/georeferencing/aboutpopup.html
Unzip the files into the same directory as the images.

We can use gdalinfo to get information about an image which should include placement from the TFW eg...
    gdalinfo TQ.tif | more

C:\GIS1\Temp>dir
 Volume in drive C has no label.
 Volume Serial Number is AC53-4476

 Directory of C:\GIS1\Temp

11/03/2007  08:08    <DIR>          .
11/03/2007  08:08    <DIR>          ..
11/03/2007  08:11               189 tq.map
21/04/2001  14:59         3,615,355 TQ.png
25/02/2004  18:12               127 TQ.TFW
               3 File(s)      3,615,671 bytes
               2 Dir(s)  125,042,814,976 bytes free

C:\GIS1\Temp>gdalinfo TQ.png | more
Driver: PNG/Portable Network Graphics
Size is 4000, 4000
Coordinate System is `'
Origin = (500000.000000000000000,200000.000000000000000)
Pixel Size = (25.000000000000000,-25.000000000000000)
Corner Coordinates:
Upper Left  (  500000.000,  200000.000)
Lower Left  (  500000.000,  100000.000)
Upper Right (  600000.000,  200000.000)
Lower Right (  600000.000,  100000.000)
Center      (  550000.000,  150000.000)
Band 1 Block=4000x1 Type=Byte, ColorInterp=Palette
  Color Table (RGB with 256 entries)
    0: 255,255,255,255
    1: 59,43,47,255
    2: 62,42,67,255
    3: 61,41,90,255
-- More --

You can see we have "Corner Coordinates" from the TFW that are in OS grid references. We also have no cordinate system declared - that's probably OK for now - OS grid references get complicated. If you don't have a good TFW file, you'll probably have an upper left coordinate of 0 0 and it'll be placed in pixel coordinates, which you'll need to fix before you proceed.

The Map file required to render that image in MapServer would be as follows:

#Map file in C:\GIS1\Temp\tq.map
MAP
  EXTENT        500000 100000 600000 200000
  SIZE           400 300
  LAYER
    TYPE         RASTER
    DATA         "C:\GIS1\Temp\TQ.png"
    STATUS       DEFAULT
  END
END

We can request this with the following URL:
    http://localhost:81/cgi-bin/mapserv.exe?mode=map&map=/GIS1/temp/tq.map

Converting your images to a sensible format

The Ordnance Survey send out images in a number of formats which may or may not be optimal for processing.  You will probably want to convert them anyway, just to make sure everything is consistant.

Copy your source maps and TFW files into a temporary directory and then run gdal_translate to translate them into an appropriate location:

C:\GIS1\Temp\250K>gdal_translate -co COMPRESS=LZW -co tiled=yes -co TFW=yes TQ.PNG C:\GIS1\Data\250K\TQ.TIF
Input file size is 4000, 4000
0...10...20...30...40...50...60...70...80...90...100 - done.

C:\GIS1\Temp\250K>

The above command will translate the files back into C:\GIS1\Data\250K\.  The files will be internally tiled TIF images that may not render properly in very many imaging programs. Irfanview (http://www.irfanview.com/) will be able to display and convert a large range of image formats. files

MapServer will probably have some performance issues if you're using it in an AJAX environment, but it's worth trying first.

TODO: See if there are any more optimal compression options - not many people use 8 bits per pixel images.

To import a load of maps, you can use a 'for' loop like this...

C:\GIS1\Temp\250K>for %f in (*.png) do gdal_translate -co COMPRESS=LZW -co tiled=yes -co TFW=yes %~nf.PNG C:\GIS1\Data\250K\%~nf.TIF

C:\GIS1\Temp\250K>gdal_translate -co COMPRESS=LZW -co tiled=yes -co TFW=yes TM.PNG C:\GIS1\Data\250K\TM.TIF
Input file size is 4000, 4000
0...10...20...30...40...50...60...70...80...90...100 - done.

C:\GIS1\Temp\250K>gdal_translate -co COMPRESS=LZW -co tiled=yes -co TFW=yes TQ.PNG C:\GIS1\Data\250K\TQ.TIF
Input file size is 4000, 4000
0...10...20...30...40...50...60...70...80...90...100 - done.

C:\GIS1\Temp\250K>gdal_translate -co COMPRESS=LZW -co tiled=yes -co TFW=yes TR.PNG C:\GIS1\Data\250K\TR.TIF
Input file size is 4000, 4000
0...10...20...30...40...50...60...70...80...90...100 - done.

C:\GIS1\Temp\250K>gdal_translate -co COMPRESS=LZW -co tiled=yes -co TFW=yes TV.PNG C:\GIS1\Data\250K\TV.TIF
Input file size is 4000, 4000
0...10...20...30...40...50...60...70...80...90...100 - done.

C:\GIS1\Temp\250K>

We now have our optimally stored TIFF files in C:\GIS1\Data\250K\

Building an index of your raster files

We need to build an index of them so they can be quickly located and indexed. We do this with the 'gdaltindex' command which generates a shape file index. The shape file contains rectangles that define where the images are and have an attribute that indicates where the tile is.

Because of the way the mapserver resolves relative paths, you always want to run 'gdaltindex' in the directory that your the root of your data directory (or wherever your 'SHAPEPATH' points).

C:\GIS1\Data>gdaltindex 250KIndex 250k\*.TIF
Creating new index file...

C:\GIS1\Data>dir
 Volume in drive C has no label.
 Volume Serial Number is AC53-4476

 Directory of C:\GIS1\Data

11/03/2007  08:30    <DIR>          .
11/03/2007  08:30    <DIR>          ..
11/03/2007  08:23    <DIR>          250K
11/03/2007  08:30             1,089 250KIndex.dbf
11/03/2007  08:30               644 250KIndex.shp
11/03/2007  08:30               132 250KIndex.shx
               3 File(s)          1,865 bytes
               3 Dir(s)  125,029,220,352 bytes free

C:\GIS1\Data>

The paths in the index are as you put them on the 'gdaltindex' commandline eg. "250K\TQ.TIF" in this case. MapServer will append that path onto the SHAPEPATH.

We can now build a MapServer map from those tiles as follows:

#Map file in C:\GIS1\Temp\250k.map
MAP
  EXTENT        500000 100000 700000 200000
  SIZE           400 300
  SHAPEPATH      "C:\GIS1\Data\"
  LAYER
    TYPE         RASTER
    STATUS       DEFAULT
    TILEINDEX    "250KIndex.shp"
  END
END

You should be able to request that from the following URL:
    http://localhost:81/cgi-bin/mapserv.exe?mode=map&map=/GIS1/temp/250k.map

Importing vector data

GDAL will import NTF and GML data, however support is somewhat limited and there is no easy way to infer Ordnance Survey's default styling.

To import MasterMap topographical data we'd recommend you use Edonica's MasterMap importer. This is open source but only free for development, testing, demonstrations and non commercial use.

Example map configuration.

An example MapServer configuration for rendering the Ordnance Survey data is below:

    MS4W_OS1.zip

Note that symbols and styles are not supported. Refer to the readme.txt file included for more instructions.

Below is an example image generated with this configuration and some Ordnance Survey sample data.

Example of imported MasterMap data viewed with UMN MapServer
Example map configuration - V2

Donald Kerr has provided us with a new MapServer template which is available for download here:

    OSMaps_v1.00b.zip

This has OS symbols provided via a TrueType font and a number of other improvements as you can see from the image below.

Example of imported MasterMap data viewed with UMN MapServer courtesy of Donald Kerr

More examples: 01_250K.gif   02_250K.gif   03_250K.gif   04_50K.gif   05_50K.gif   06_50K.gif   07_10K.gif   08_10K.gif   09_10K.gif   10a_MasterMap.gif   10b_MasterMap.gif   10c_MasterMap.gif   11_MasterMap.gif   12_MasterMap.gif

Where Next.

OpenLayers have a great AJAX based mapping client that will talk to MapServer, along with lots of documentation. You may be able to get round some performace problems with TileCache and FastCGI

We've done some research into Geoserver, a Java based rendering engine which may provide better performance, however installation / configuration is quite painful.  It might be the case that the detail level in Ordnance Survey maps is more than most US based GIS systems can cope with.