11 Dec 2009 dangermaus   » (Journeyer)

I managed to install Openstreetmap on Gentoo (status: December 2009) and I could generate some interesting tiles of Poschiavo, which is a little valley in the mountains where I live. My server is an AMD k6-600 MHZ with 600 MB of RAM, so not a real power horse but quite an old scrap iron thing. Of course, I did not import the whole planet, but only a dump of Switzerland.

Your own Openstreet map tile server on Gentoo

I wrote down some steps that differ from the excellent tutorials here and here, because my installation is performed on Gentoo instead of Ubuntu: of course, this is working now as for December 2009, but an emerge --sync in the future might solve some of these problematic steps (maybe someone more knowledgeable than me will read this tutorial and fix some ebuilds :-).

Step: Subversion and Java

These one were easy and you probably figured out faster than me: emerge -av subversion
emerge -av sun-jdk

Step: Installing Postgresql with Postigs spatial extensions

osm2pgsql does not work with Postgresql 8.1 which is marked stable in Gentoo. The reason is that Postgresql 8.1.11 does not know about the command 'DROP TABLE IF EXISTS' which is used in oms2pgsql. Defining a stored procedure that does the same and modifying the source code of osm2pgsql did not work for me.

Therefore I chose another way, which goes as follows: you should add at the end of /root/.bashrc the following alias:

alias aemerge='ACCEPT_KEYWORDS="~x86" emerge '
source /root/.bashrc will load this setting for the first time. The setting is kept after, as .bashrc is read at every login. From now on, you can use "aemerge" to emerge unstable packages instead of "emerge".

Then, you can install an unstable Postgresql with
aemerge -av postgresql

This will install a Postgresql 8.2.14 which is fine for our purposes.

Install also Postgis:
aemerge -av postgis
Postgis-1.4.0 is then installed.

Configure the database postgis extensions not by using emerge --config as suggested at the end of emerge, but use the instructions provided in this tutorial. Remember to follow the instructions as normal user and not as superuser (a part of the inital step of setting up the database).

As noted in the previous comment, lwpostgresql.sql does not exist in postgis anymore, it was renamed in postgis.sql, you should therefore use
psql -d gis -f /usr/share/postgresql/contrib/postgis.sql

Step: Installing mapnik
For mapnik I had problems, it did not compile from source as described in the tutorial, it was failing when compiling the postgis plugin for linking reasons against the library libpq.la, though the library was present on the proposed path.

I did the following trick:

USE="postgresql" aemerge -av mapnik

emerged and installed a mapnik with all dependencies, which however was not able to recognize the postgis extensions on the 'gis' database.

In fact, when running ./z0_generate_tiles.py, mapnik was failing with:

Could not create datasource. No plugin found for type 'postgis' (encountered during parsing of layer 'leisure') when connecting to the imported database.

Then I did the following: I unmerged the unstable libpq library (libpq is a library used by postgresql used as connection layer.
emerge --unmerge libpq
I unmerged mapnik without its dependencies with
emerge --unmerge mapnik
I installed the stable libpq library with:
emerge -av libpq
Then I installed mapnik from source with the following steps
mkdir src
cd src
svn co http://svn.mapnik.org/trunk/ mapnik
cd mapnik
scons/scons.py -c install
scons/scons.py PGSQL_LIBS=/usr/lib/postgresql/ PGSQL_INCLUDES=/usr/include/postgresql/
sudo scons/scons.py install PGSQL_LIBS=/usr/lib/postgresql/ PGSQL_INCLUDES=/usr/include/postgresql/
ldconfig

Therefore: postgresql is compiled against an unstable version of libpq, while mapnik needs a stable one to compile. Of course, postgresql will survive the restart with
/etc/init.d/postgresql restart
:-)

Have fun with your maps! Import the planet on your favourite Gentoo box!

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!