söndag 5 oktober 2008

GPSDrive med Mapnik och kartor från openstreetmap.org under Gentoo

Tar och sätter ut min howto hit också, får nöja er med engelska. GPSDrive är ett fritt kartprogram ( http://www.gpsdrive.de ) och OpenStreetMaps ( http://www.openstreetmap.org ) är kartor enligt wiki-principen. Notera att jag inte behandlar hur man sätter igång sin GPS.
---

First some notes about dependency versions
I have installed this using glibc-2.7-r2 and gcc-4.2.4 - I do not know if it will work with glibc 2.8x and/or gcc 4.3.x.
I used boost-build-1.34.1 and boost-1.34.1-r2. Higher versions (1.35.0-r1) caused GPSDrive or Mapnik to fail to render maps (shows "No map available for current position").
Do not use LibTool 2.x, Mapnik will not build. I used libtool 1.5.26.

Setup PostgreSQL and Postgis
Install PostgreSQL by
#> emerge postgresql-server
and then postgis by
#> USE="proj geos" emerge postgis
I am not sure if it has to be built with proj and geos support, but Mapnik uses it so I added them.

Run
#> emerge postgresql-server --config
to initialize the databases and
#> /etc/init.d/postgresql-8.3 start
to start the server.

Now switch to postgres user by
$> su
#> su - postgres
As the postgres user run the following to create the database (NOTE: Replace username with the user that will be using mapnik):
$> createuser username
$> createdb -E UTF8 -O username gis
$> createlang plpgsql gis
Setup PostGIS
Initial database setup:
$> psql -d gis -f /usr/share/postgresql/contrib/lwpostgis.sql
$> echo "ALTER TABLE geometry_columns OWNER TO username; ALTER TABLE spatial_ref_sys OWNER TO username;" | psql -d gis
Finally add the user who will be using GPSDrive to postgres group in /etc/group and login again.

Install Mapnik
Ebuilds for Mapnik can be found at http://bugs.gentoo.org/show_bug.cgi?id=140599

Add the ebuild to portage tree:
#> mkdir /usr/portage/sci-geosciences/mapnik
#> mv mapnik-0.5.1.ebuild /usr/portage/sci-geosciences/mapnik/
#> ebuild /usr/portage/sci-geosciences/mapnik/mapnik-0.5.1.ebuild manifest
#> USE="postgres proj debug doc gdal python bidi" emerge mapnik
Setting up necessary data for Mapnik
Here are more instructions: http://wiki.openstreetmap.org/index.php/Mapnik

I have condensed the most important.

World boundaries (51MB) and coastlines (~200MB):
$> wget http://tile.openstreetmap.org/world_boundaries-spherical.tgz
$> wget http://hypercube.telascience.org/~kleptog/processed_p.zip
$> tar -zxvf world_boundaries-spherical.tgz
$> unzip processed_p.zip
$> mv coastlines/* world_boundaries/
$> rmdir coastlines
$> chmod -R 755 world_boundaries

#> mkdir /usr/local/share/mapnik
#> mv world_boundaries /usr/local/share/mapnik
Install osm2pgsql and the osm data
Needed is sci-libs/geos, the 3.0.0 version does not work; do
#> emerge =geos-2.2.3
Using svn (emerge subversion) get osm2pgsql from:
$> svn co http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/
$> cd osm2pgsql
$> make
Now, add your downloaded map data by
$> ./osm2pgsql -d gis ../yourmapdata.osm.bz2
Later, if GPSDrive shows the position off by some 20 km, re-add the data with the -m flag.
(-m|--merc Store data in proper spherical mercator, not OSM merc).
For me, atleast, I first used the -m flag and my position was way off to the south, so I guess for now it should not be used.

OSM icons:
$> svn co http://svn.openstreetmap.org/applications/share/map-icons
$> chmod -R 755 map-icons
#> mv map-icons /usr/share/icons
GPSDrive
I am not sure if these Perl modules are needed but other howtos suggest them:
dev-perl/DBI
dev-perl/DBD-Pg
dev-perl/DBD-SQLite

CMake is required for building, simply do
#> emerge cmake
libgda 3 is also needed, unmask in /usr/portage/profiles/package.mask, then
#> emerge =libgda-3.0.4
Then go on with GPSDrive:
$> svn co http://svn.gpsdrive.cc/gpsdrive/trunk gpsdrive-svn
$> cd gpsdrive-svn/build
$> cmake -DCMAKE_BUILD_TYPE=Debug ..
$> make
#> make install
If all went well, GPSDrive should now be installed.
There are however some things that need to be fixed before it will work.

Create an empty waypoint file, avoids complaining.
$> touch ~/.gpsdrive/way.txt
Misc symlinking:
#> mkdir -p /usr/lib/mapnik/0.5
#> ln -s /usr/lib/mapnik/fonts/ /usr/lib/mapnik/0.5/fonts
#> ln -s /usr/lib/mapnik/input/ /usr/lib/mapnik/0.5/input
#> mkdir /usr/local/share/icons
#> ln -s /usr/share/icons/map-icons /usr/local/share/icons/map-icons

#> mkdir /usr/share/fonts/truetype/ttf-dejavu
#> chmod -R 755 /usr/share/fonts/truetype
#> ln -n /usr/lib/mapnik/fonts/* /usr/share/fonts/truetype/ttf-dejavu/
Now GPSDrive should be possible to start. Click "Map Control" and check "Mapnik Mode".

Inga kommentarer: