OpenStreetMap over WMS

This paper discuss the issues which we faced, while preparing WMS server with OpenStreetMap data of whole Europe. This article is divided into three sections. First is about mandatory applications which are required for working WMS service with OpenStreetMap data. Second is focused on tuning up PostgreSQL. Third is focused on rendering time improvement of layers.

MapServer of version 5.4 and higher.This is required due to change of labels rendering machine.
Application osm2pgsql.This is a little bit still development application.
Postgresql of version 8.0 and higher with PostGIS.I recommend 8.3 with PostGIS 1.3.5 and higher.There was some bug in 1.3.3 which was returning bad bounding box.
Optional mapserver-utils -this project contains mapfiles for advanced drawing of layers from OpenStreetMap.You needn't to use this mapfiles but it's recommended.This can be obtained from http://code.google.com/p/mapserver-utils.
Because MapServer 5.4 and PostGIS 1.3.5 is very recent user will probably don't find it in repository of almost every distribution of Linux if you are not using some kind of rollingupdates distribution (like Gentoo).Here is small howto create your own deb packages in debian.First of all you will need pbuilder application.This application will make "fake" image of system.After small tweaking of config file you can start making debian packages.

Last step is to create package by pdebuild --use-pdebuild-internal
If it is everything ok you will have package ready to install.

PostgreSQL part
PostgreSQL is configured for secure and reliable handling of data by default, but if you want to handle big amounts of data it's better to do some tweaks.You should think about your hardware in the beginning for better performance of your database management system.Memory is faster than HDD but it is not possible to buy lot of memories because there is limited number of memory slots.SSD disks are slower but their size is still not so big (max 128GB) and they are more expensive.Most used scenario is disks connected into RAID.RAID1 at least but I prefer RAID5.RAID5 is slower when writing data to disks but faster when reading data from disks.
Software tweaking of PostgreSQL can be done in config file which you can find in CLUSTER-DIR/postgresql.conf.shared buffers -this parameter defines amount of memory in which PostgreSQL will hold requests.This should be set to thousands (one buffer is 8kB).Some sources writes one quarter of memory another writes set this to 256MB (32768).maintenance work mem -specifies amount of memory which is used for maintenance operations like vacuum, create index ... This should be set to bigger amount than default.Very usable if you are using autovacuum operation.

Getting data to
And last step before inserting data into database is to create 'google projection' in /usr/share/proj/epsg. Add this line <900913> +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0+lon_0=0.0+x_0=0.0+y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs For faster queries it's recommended to put projections which are used in the beginning of the epsg file.It's possible to start importing data into database now.This is done with osm2pgsql application which have some parameters.-d will specify database, -p -prefix of created tables, -C define amount of space for caching.If you run out of memory try turning on -s osm2pgsl -d osm -p osm -C 2048 <file_with_osm_data> At [1] is written some after-importing operations which makes better output from database.

Speeding up rendering time
Mapfiles from mapserver-utils are nice but they are not usable for big amount of data like whole Europe.If you don't have some very powerful grid and want to see map before your coffee get cold, you must do some optimizations for small scales (from ∞ to 1 : 500000).For example osm line table has 9.5M records and in scale 1:5 000 000 are shown these layers:

PostgreSQL
Data from osm format are put into PostgreSQL by osm2pgsql software.Before user can use this software he must have spatial enabled database and must have existing Mercator projection (or "Google projection") in /usr/share/proj/epsg and spatial ref sys table.This projection was added to recent version of EPSG.After this log into PostgreSQL using osm database and add 'google projection' into spatial ref sys table: