Category Archives: FOSSGIS

A simple way to localize (latinize) an Openstreetmap style

Based on a request on the german mailinglist back in july, I thought about how the perfect localization of the german mapnik style would look like and finaly implemented something which comes close. Unfortunately up till now I did not document it.

However Reading about a map in manx today, I came to the conclusion, that I really need to do this.

First of all I came up with the following assumptions (valid for all languages using latin script IMO):

  • always prefer mapped names over automated transliteration
  • prefer name:<yourlang> over any other name tags (name:de in my case)
  • prefer int_name over non-latin script
  • prefer name:en over non-latin script if int_name has not been specified
  • transliterate non-latin script as a last resort

So how has this been implemented?

I decided to do it inside the SQL-query. This way it is independent of the rendering Software. It will certainly work at least with mapnik, mapserver and geoserver. Even the proprietary ESRI rendering stuff should actually work :)

Basically any rendering system using a PostgreSQL backend can be easily adapted. Of course your database must provide all the required name columns.

So how would one enable rendering a latin name insead of just the generic name tag?

Assume your style uses something like this for rendering a street-name:

FROM planet_osm_line;

Now just replace this by the following:

SELECT get_localized_name(name,"name:de",int_name,"name:en") as name
FROM planet_osm_line;

Quite easy isn’t it?

Well, here comes the (slightly) more complicated stuff…

Of course PostgreSQL does not provide a get_localized_name function out of the box, we have to install it first. So here is how to do this in two steps:

The get_localized_name function has been implemented in PL/pgSQL and is available at

So first add this function to your database using the following command:
psql -f get_localized_name.sql <your_database>

Second add the transliterate function available at

To compile and install it on GNU/Linux (sorry, I don’t care about Windows) do the following:

  • svn co
  • Install the Server dev package (On Debian/Ubuntu this would be called postgresql-server-dev-x.y, postgresql-server-dev-9.2 in my case)
  • Install the libicu-dev package
  • compile and install calling make; make install
  • On Debian/Ubuntu you would be better off using dpkg-buildpackage and install the resulting package instead of using the make install procedure.

Now enable the function from the shared object using the following SQL command (from a postgresql admin account):

CREATE FUNCTION transliterate(text)RETURNS text
AS '$libdir/utf8translit', 'transliterate' LANGUAGE C STRICT;

Here is how to check if this works:
mydb=> select transliterate('Москва́');
(1 row)

Well that’s it, I hope that this will be useful for some people.

Unfortunately this stuff has currently (at least) two problems:

  • Transliteration of Thai Language uses ISO 11940 instead of the RTGS system
  • Transliteration of japanese Kanji characters end up with a chinese transliteration (e.g. dōng jīng instead of Tōkyō for 東京)

If anybody has some suggestions on how to solve these please post them here!


Warum die “offenen Geodaten” von Baden-Württemberg eine Mogelpackung sind

“Baden-Württemberg gibt Geodaten frei”, so titelte beispielsweise Pro-Linux vor zwei Tagen. Schaut man sich das etwas genauer an, dann bleibt von dieser Aussage leider nur wenig übrig :(

Gut, die Maps4BW Rasterkarten stehen jetzt unter CC BY 3.0 zur Verfügung (leider derzeit nur in einem proprietären Format von ESRI[1]) und man darf daraus jetzt mit offizieller Erlaubnis durch abmalen von Rastergrafiken freie Vektordaten in (verglichen mit den Rohdaten) geringerer Qualität für OSM erzeugen!

Die eigentlichen Geodaten, aus denen diese Rastergrafiken erzeugt worden sind bleiben hingegen proprietär!

Wörtlich steht folgendes in den Nutzungsbedingungen des WMS:

Maps4BW liegen nicht offene Geobasisdaten zugrunde, deren Nutzung einer gesonderten Vereinbarung bedarf.

Die Rohdaten also, deren Erstellung zu einem Großteil vom Steuerzahler finanziert worden ist, stehen diesem also weiterhin nur unter einer teuren kommerziellen Lizenz zur Verfügung.

Sorry liebe Leute, aber das ist doch genau das worum es bei Opendata geht: Um die Freigabe von Rohdaten und eben nicht um irgendwelche hübsch aufbereiteten Rasterkarten! Bei Maps4BW handelt es sich zwar um eine recht brauchbare Webkarte, aber Anwendungen für die man Rohdaten benötigt (z.B. Routing oder Geocoding) kann man damit natürlich nicht machen.

Es wäre technisch erheblich einfacher gewesen Rohdaten zum download anzubieten statt daraus erzeugte Rasterkarten.

Es bleibt also festzustellen, dass die Freigabe von Geo-Rohdaten wohl auch unter einer Grün-Roten Regierung weiterhin nicht erwünscht ist.

Fazit: Opendata geht anders :(

[1] Der Firma ESRI, ist hier kein Vorwurf zu machen, deren Software kann die Daten problemlos auch in offenen Formaten liefern. Im Gegenteil ESRI verhält sich als Firma sogar ausgesprochen Opendata freundlich.

My subjective perception of the impact of the OSM licence change

As most of my readers will probably know Openstreetmap is in progress to change it’s licence to a less restrictive one (at least from a data users perspective). Fortunately this will likely remain the only Openstreetmap licence change in my livetime well at least the only invasive one.

Today the so called redaction bot finished its work leaving the database in a state where most of the data origins from people which approved the new licence.

The Place where I live (Karlsruhe/Germany) has been one of the places to be fully mapped at a fairly early state of the project.
And ss with the rest of Germany most of the stuff originates from crowdsourcing work.

This turned out to be a huge advantage compared to places likeSydneywhere quite a lot of data has been imported from sources which did partly not agree with the licence change and which looks quite messy now.

While Karlsruhe also looks quite bad on theredaction bot view of OSM Inspector it does not look that bad if you check the details.

The red stuff mainly originates from one mapper doing quite a lot of public transport stuff, which lost some details now here and there, but most parts of the map are still quite intact.

But after all this is mostly what I would have expected, so here comes what I did not expect at all:

Back in 2009 I mapped two long-distance cycle tracks and last sommer we mapped another one while I was cycling with Christoph.

So this evening I decided to repair these relations and based on the fact that every single one of them is roughly 150km long I expected that this would be a lot of work.

This proved to be completely wrong. I did have to fix next to nothing on any of the three relations. Only one licence change related fix in all of them!

So instead of fixing bugs caused by OSM licence change I spend my evening writing silly blog postings like this one :)

Handy bash function for Unix GIS people :)

The usually so called shapefiles are typically not files but a couple of them with different extensions. Thus it is not very convenient to rename them.

Fortunately a Unix Shell is a very powerful tool so here comes shpmv which is a simple bash shell function. Just put it in your .bashrc. It works fine regardless if an extension (e.g. .shp) is given or not.

function shpmv() {
  if [ $# -ne 2 ]; then
    echo "shpmv: rename shapefiles"
    echo "usage: shpmv  "
  if ! [ -f $src.shp ]; then
    echo "$src.shp: file not found"   
  for f in $src.*; do
    mv $f $tgt.$ext

A Mapserver backend for Tirex

When rendering maps people coming from a traditional GIS background tend to use Mapserver rather than Mapnik. I don’t know the reason for this, but it is probably just because Mapserver is quite mature and has been around for a long time while Mapnik is still relatively new.

I also did quite a few things using Mapserver in the past but mostly in the WMS and raster data area.

One thing Mapserver can do is rendering based on data values rather than just by predefined rules, which could be quite useful for river widths and the like. This was not possible in Mapnik at least not in Mapnik versions < 2.0.

Mapserver is scriptable in a couple of languages (not just Python) and this is why it has been relatively easy coding a new backend for Tirex although Perl is not quite my favourite scripting language. Of course this new backend is heavily based on the existing WMS backend.

So why did I do this? Well, last week I just stumbled upon the nice Topomap project which Max Berger is doing and unfortunately he map is limited to a very small area.

Hopefully I will be able to provide a map of this style for a couple of other areas real soon now. I’m especially interested in islands with good hiking options, the so called Wanderinseln in German.

I just commited the changes to the Openstreetmap SVN-repository in the hope that it might be useful for others as well.

BTW, Max is using TileCache which I could probably use as well. Probably someone can enlighten me about the pros and cons of Tirex vs. TileCache.

Der deutsche OSM Kartenstil, Aufzucht und Pflege

Seit einigen Monaten gibt es auf der deutschen OSM Homepage einen eigenen Kartenstil, der im Rahmen einer Bachelorarbeit an der HFT Stuttgart aus dem internationalen Stil entstanden ist. Dieser Stil versucht sich an die hierzulande in Karten üblichen Gepflogenheiten zu halten und trotzdem nicht allzuweit von der internationalen Variante abzuweichen.

Im Gegensatz zu einer Bachelorarbeit und einem Studium ist ein Kartenstil für ein solch dynamisches Projekt wie Openstreetmap aber niemals fertig.

Aus diesem Grund haben wir jetzt eine Arbeitsliste gegründet. Die Abonnenten dieser Liste möchten sich der Weiterentwicklung und Pflege dieses Kartenstils annehmen.

Insbesondere warten schon diverse Änderungen am internationalen Stil auf ihre Portierung.

Über weitere Mitstreiter, die mit der Mapnik Toolchain und Subversion umgehen können würden wir uns freuen.

Es geht bei der Liste ausdrücklich nicht um Diskussionen was man darstellen sollte und was nicht. Dafür gibt es talk-de und das Forum.

Was die Technik betrifft ist der Server leider sehr langsam und stellt derzeit auch nur Europa zur Verfügung. Das ändert sich hoffentlich bald wenn wir unseren eigenen Server bekommen.

Wenn jemand den Betreiber eines Rechenzentrums kennt der dem Openstreetmap Projekt etwas gutes tun möchte möge sich umgehend bei mir melden. Wir bräuchten etwa 3HE Platz in einem Serverschrank.

A WMS-server in about 100 lines of code…

or how to use and others in josm

A few weeks ago a few austrian mappers contacted me because we are now allowed to us the WMS server at for mapping.

Unfortunately the data is currently only available in an austrian koordinate system (EPSG:31287). With EPSG:4326 beeing unavailable this is in fact a violation of the WMS spec :(

This could however be easily fixed using UMN-Mapserver as WMS-proxy, but unfortunately we are not allowed to do this at wms.openstreetmap.debecause we are not permitted to set up a cascading WMS based on their rules.

Anyway, with my setup already using the python wsgi-interface (apache mod_wsgi) I thought that a standalone UMN-Mapserver based WMS-server should be very easy to hack, given the fact, that all the difficult stuff is already available in python and mapscript. Well, my presumption proved to be true :)

So here is my standalone WMS-server written in roughly 100 lines of python code.

As far as is concerned, there are already other solutions at the OSM-Wiki page, but this was fun to hack and might be useful for other purposes as well. An advantage of my solution is that it is possible to use the Austrian GIS-grid file for reprojection to achieve the highest possible accuracy. For this purpose the proj4-definition for EPSG:31287 (defined in /usr/share/proj/epsg on Linux) must look like this:

<31287> +proj=lcc +lat_1=49 +lat_2=46 +lat_0=47.5 +lon_0=13.33333333333333 +x_0=400000 +y_0=400000 +ellps=bessel +units=m +nadgrids=/path/to/GIS_GRID_austria.gsb +no_defs

I would be interested in feedback on how to get this to work on Windows as well. Talking about Linux this has only been a matter of typing apt-get install python-mapscript and adjusting the proj4 definition file to use the GIS-grid.

The state of free bicycle trip planning tools

While the quality of openstreetmap has changed from unusable to what is now arguably the best map for bicycle trip planning in recent years (at least in germany) unfortunately free bicycle trip planning software has not.

The following table is probably not complete so please post your suggestions if you know about other tools.

I just tested FOSS and web based tools because commercial applications like TTQV tend to be running on windows only anyway.

So here is the current state of the tools I checked. What I would really like to see in the future is a like semi-automatic-routing feature but based on osm instead of google.

stand alone applications:


OSM tiles

Google maps/aerial images


Garmin maps

rectified images

Automatic routing

Manual route planning

semi-automatic routing


yes not allowed via hack no no no yes no


yes no no no yes no yes no

web based tools:


OSM tiles

Google maps/aerial images


Garmin maps

rectified images

Automatic routing

Manual route planning

semi-automatic routing

my hacked version yes no no no no yes no

yes no no no no no yes no

yes yes no no no Google API yes Google API

yes no no no no OSM no no

My current workflow ist still using about 2 or 3 of these tools because fortunately all of them are able to read/write GPX file format.

Currently I just set up a hack which will translate tile requests into WMS to allow using them in viking. This is basically the same setup (with a slightly modified mapfile) already in use at and available from Openstreetmap SVN.

An example tile URL for this kind of setup would be Please note that this data has not been approved for Openstreetmap use so please do not use these tiles for mapping.

PostGIS and hstore for OSM Data

Unlike traditional GIS data, which usually uses just a couple of attributes per spacial object, openstreetmaps comes with a free tagging scheme. In traditional database design it is impossible to store this type of data in a single table thus adding the need for joins in any single SQL request.

Starting from Version 9.0 PostgreSQL will however include an extension called hstore which is available as a backport for current Versions of PostgreSQL (8.3 and 8.4) and even as a debian package.

Using this extension an additional key/value table is no longer needed.

Already back in March I commited a patch for osm2pgsl which would allow for storage of tag objects inside such a hstore column.

An hstore is basically what is known as hash (perl) or dictionary (python) in scripting languages. A datatype for storage of key value pairs – well suited for storage of OSM data tags.

Talking about python I took me quite some time to figure out how to convert a hstore result from an SQL query so here is how it works:

q="select (each(tags)).key,(each(tags)).value from ... where ..."
rows = cur.fetchall()

Back to the actual hstore issue…

In the meantime people are actually starting to use this stuff and MaZder even wrote a HOWTO document (currently in german language only) on howto set up such a database.

So here are the projects currently using hstore that I am aware of:


The 201 Gigapixel Image :)

German Company Aerowest is providing Openstreetmap with high resolution Images.

Once again I have been doing most of the technical work which needed to be done behind the scenes. While has been up and running for a few weeks now I still had to do some stuff to get the things going.

First of all I converted the mapscript from the older mod_python to the state of the art mod_wsgi. Furthermore the script has been extended to allow for individual copyright-watermarks based on mapfile entries. Tiles generated for Potlatch are now cached using the Apache Module mod_disk_cache.

The aerial image itself came as a raster image of 201 Gigapixels in the very good (in terms of image compression) but proprietary ECW-format. For legal reasons we are now using another format for actually serving the image (eating a huge 675 Gigabytes of disk-space) because the proprietary license of libecwj2 does not state very clearly if we are allowed to use it in our setup or not.