OpenStreetMap tiles in EPSG:25832 projection using GeoServer

Warning: This is a description of how to create a OpenStreetMap WMS with GeoServer. It works fine up to the point where the layers published as an unstyled WMS. This is where I've not been able to produce a good result, because of lack of a good Styled Layer Descriptor (SLD). If you have hints about a good SLD, feel welcome to submit a comment!

The idea

The idea is/was to first create a good general purpose OpenStreetMap WMS, and then use GeoWebCache to generate tiles from this WMS source in a custom projection, epsg:25832 in our case.

The OpenStreetMap project uses Mapnik, and have published a Python script that generates tiles, but tiles are generated in another (geographical) projection than the one we want (epsg:25832). I'm not so familiar with Mapnik, so I tried to use GeoServer instead, with limited success. Like I said, it works fine, except for styling, which is of course alpha and omega for a useful map.

My development environment

I'm on Mac OS X, and in this post I'll use Geoserver 2.1.0 and Postgres 9.0 to render OpenStreetMap data for Denmark in the UTM projection EPSG:25832. You can propably use these instructions for a slighty different scenario.

On the OpenStreetMap homepage there are instructions on how to generate your own OSM tiles, but the instructions do not fit with my needs exactly. Namely I ultimately want maptiles in EPSG:25832 as created by GeoWebCache, and move these tiles to a web server and display them using the GWC layer in Openlayers.

Step one: Get the data

Download the OSM data from one of the mirrors (choose an "osm" distribution, not e.g. the shapefiles)

curl -O http://download.geofabrik.de/osm/europe/denmark.osm.bz2
bunzip2 denmark.osm.bz2

You can also use the OSM API to get an .osm file for a custom region by bounding box (lat/long):

curl -O http://api.openstreetmap.org/api/0.6/map?bbox=11.54,48.14,11.543,48.145

It should be noted that you can get daily/hourly/minutely diffs from OpenStreetMap for updating your data set once you have downloaded it.

Step two: Prepare the database

Create a user and database (I used osm_dk for both the database and the user):

createuser -U postgres osm_dk
createdb -U postgres -E UTF8 -O osm_dk osm_dk

Prepare the database for spatial OSM data (check you installation of postgis for location of postgis.sql file):

psql -U postgres -d osm_dk /Library/PostgreSQL/9.0/share/postgresql/contrib/postgis.sql
curl -O http://skipperkongen.dk/files/900913.sql
psql -U postgres -d osm_dk -f 900913.sql

Step three: Import data using osm2pgsql

If you're on a Mac, you can use HomeBrew to install osm2pgsql. My version of osm2pgsql is 0.70.5.

Before you continue, you'll need the "style" file that comes with osm2pgsql. Mine was in:

/usr/local/Cellar/osm2pgsql/HEAD/share/osm2pgsql/default.style

Run osm2pgsql (I use -K to "keep coastline". See other options with osm2pgsql --help):

osm2pgsql -U osm_dk -W -d osm_dk -K -S default.style denmark.osm

There is an -E EPSG-num option for reprojecting the data, but it didn't work for me. I'll have to do the reprojection to EPSG:25832 on the fly.

Step four: Styling!

This is actually the hard part, and where my effort comes to a grinding halt. You'll need a good SLD for Geoserver to render the map data, but these are hard to come by. There is a project on Github called openstreetmap-sld, but it is not that well-maintained. There is another project called mapnik2geotools which looks promising, but I've not gotten it to work (I have not tried that hard).

The direct route is to create (and share on github!) your own SLD. If I can not get mapnik2geotools to work, this is what I'll have to do...

4 thoughts on “OpenStreetMap tiles in EPSG:25832 projection using GeoServer”

  1. Pingback: OpenStreetMap tiles with custom projection and grid using Mapnik | skipperkongen.dk

  2. hi
    excusme for my poor english
    i found you in stackexchange.com.in context of SLD creation i make some SLDs with “Geopublisher” project.do you work with it?it can generate good styles but i have not time for this issue.do you have any SLD for osm or shape lines and polygons?if yes or no please send your answer to my mail.
    Thank you very much :)

    1. Hi Hamed. I will answer you in email, but just for the sake of the public debate, I’ve not found a good SLD, and I presently think the best way to render OSM tiles is to use Mapnik. This is what the OSM team does, and the style is being maintained.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.