Mapnik/Old
From OpenStreetMap
Contents |
Old Stuff
Below is various old, out of date information or stuff that simply hasn't been included above yet.
Download
It is probably best to start off by checking out the OSM SVN tree. See Getting The Source. The mapnik source is linked automatically to this tree and will appear at svn.openstreetmap.org/applications/rendering/mapnik/mapnik.org/
Alternatively the Mapnik code can be downloaded on its own from mapnik.org
svn co svn://svn.mapnik.org/trunk mapnik
Then cd to mapnik directory and compile as below.
dependencies
- gcc/g++ compiler
- boost
- libpng
- libtiff
- libjpeg
- libltdl
- freetype2
- libpq
- foro
- postgresql access
- python-devel
For Fedora
may be incomplete
yum install libpng-devel libtiff-devel libjpeg-devel \ libtool-ltdl-devel proj-devel boost-devel freetype-devel \ libpqxx-devel postgis geos-devel python-devel libxml2-devel
Note: if you are compiling mapnik note that Mapnik looks for the multithreaded versions of boost, which didn't exist prior to FC8. So if you're running an older version you may need to use the THREADING=single option.
An RPM of Mapnik is available for download. The Mapnik RPM has been submitted for inclusion in Fedora. To install the current RPM do the following:
rpm -ivh http://www.passback.org.uk/packages/fedora/7/i386/passback-release-7-1.fc7.noarch.rpm yum install mapnik
That should install Mapnik and take care of any dependencies.
For Gentoo
To install required packages, try:
emerge --ask --noreplace dev-libs/boost media-libs/libpng \ media-libs/tiff media-libs/jpeg media-libs/freetype \ sci-libs/proj dev-db/postgis sci-libs/gdal
Note that dev-libs/boost must be built with the "threads" USE flag -- if it's not used, you'll receive a boost_thread-mt error.
After building, you can set up PostgreSQL with the command:
emerge --config =postgresql-8.0.13
and start the server with:
/etc/init.d/postgresql start
If the server refuses to start because there's no conf file, try the following (as root):
su -s /bin/bash -c "initdb -D /var/lib/postgresql/data" postgres
You should now be able to start the postgres server.
Compiling
On Debian do this first:
ln -s /usr/lib/libboost_python.so /usr/lib/libboost_python-gcc-mt.so
(You need to do this because the linker is expecting the latter library, but the Debian package provides the former.)
On Debian Etch, i had to issue the following commands described for Ubuntu - Florianschmitt 20:55, 17 November 2007 (UTC)
On Ubuntu you might need to do the following in /usr/lib:
ln -s libboost_python.so libboost_python-mt.so ln -s libboost_thread.so libboost_thread-mt.so ln -s libboost_filesystem.so libboost_filesystem-mt.so ln -s libboost_regex.so libboost_regex-mt.so ln -s libboost_program_options.so libboost_program_options-mt.so
(I don't know why, but it would not compile without it so I copied off the Debian instructions above and it seems to work. I made the libboost_python link as above too...)
On all platforms, to install:
python scons/scons install
or without bindings:
python scons/scons install BINDINGS=none
On Debian lenny I had to do
python scons/scons install THREADING=single
to persuade scons to find the boost libraries
On Gentoo, you may have to do:
python scons/scons GDAL_INCLUDES=/usr/include/ install
Demo
When installed, try the demo in mapnik/demo/c++:
g++ -O3 -I/usr/local/include -I/usr/include/boost -I/usr/include/freetype2 -L/usr/local/lib -lmapnik rundemo.cpp -o rundemo
and to run
./rundemo /usr/local/lib/mapnik/input
This will generate a JPEG and PNG of a map.
If you receive an error like:
./rundemo: error while loading shared libraries: libmapnik.so: cannot open shared object file: No such file or directory
you may need to make sure that /usr/local/lib is listed in /etc/ld.so.conf and to run ldconfig as root.
PostgreSQL
Note: On most PostgreSQL installs, you'll need to be root to be able to connect to the database as the postgres user (-Upostgres). Alternatively you may execute "su postgres" as root to take on the privileges of the postgres administrator. If you have problems connecting as postgres, or wish to change who can connect as postgres, you'll need to edit your pg_hba.conf, and possibly also pg_ident.conf.
If your user account hasn't been setup for postgres, run
createuser -Upostgres
and follow the prompts.
If you don't already have a database set up, you'll need to create one. If your user has "create database" privileges, just do:
createdb -EUNICODE <DBNAME>
Otherwise, you'll need to create the database as the postgres user, and then grant rights to yourself:
createdb -Upostgres -EUNICODE <DBNAME> psql -Upostgres <DBNAME> GRANT ALL ON SCHEMA PUBLIC TO <USERNAME>; \q
Note: the osm2pgsql program assumes the database name is gis, so you will need to use that unless you want to change the osm2pgsql code.
You are now ready to setup the PostGIS extensions.
PostGIS
You will need to set up various functions, tables etc as the database superuser (postgres). Once they are setup, you can grant permissions on them to the user you'll normally user.
You might need to copy usr/lib/postgresql/8.1/lib/liblwgeom.so.1.1 to /opt/postgresql/lib, creating the directory if needed. Then, add /opt/postgresql/lib to a new file /etc/ld.so.conf.d/postgis.conf, and run ldconfig.
Set up the Mapnik PostGIS plugin
python scons/scons.py PGSQL_INCLUDES=/usr/include/postgresql PGSQL_LIBS=/usr/lib/postgresql/8.1/lib install
Create the plpgsql language in the DB
For PostgreSQL earlier than v8.0, use psql -Upostgres <DBNAME>, and execute:
create language plpgsql;
For PostgreSQL 8.0 and later, run:
createlang -Upostgres plpgsql <DBNAME>
Load the postgis extensions
psql <DBNAME> < lwpostgis.sql
- Note 1: If you get permissions errors, add -Upostgres before <DBNAME>
- Note 2: If you don't know where lwpostgis.sql is, check
/usr/share/postgresql/contrib/(or/usr/share/postgresql-<version>-postgis/lwpostgis.sql).
To give your normal user permissions on the new PostGIS stuff, run psql -Upostgres <DBNAME>, and execute:
GRANT ALL on geometry_columns TO <DBUSER>; GRANT ALL on spatial_ref_sys TO <DBUSER>;
Getting planet.osm in to the db
Prerequisites
Geos
Get geos:
- On Debian, install 'libgeos-dev'
- On Gentoo, emerge sci-libs/geos
Otherwise:
cd /opt svn co http://svn.refractions.net/geos/trunk geos cd geos ./autogen.sh ./configure make
UTF8sanitize
Compile UTF8sanitize:
cd svn.openstreetmap.org/applications/utils/planet.osm/C make
7z
If you want to download the smaller 7z-compressed planets, get 7z
- On Gentoo: emerge app-arch/p7zip
osm2pgsql
cd svn.openstreetmap.org/applications/utils/export/osm2pgsql make
Importing planet.osm
Download planet.osm. Then, change to the osm2pgsql directory (cd svn.openstreetmap.org/applications/utils/export/osm2pgsql), and run the importer as follows:
If you have the 7-zip archive of planet.osm, use:
7z x -so /path/to/planet.osm.7z | ./osm2pgsql -
If you have the bzip2 version:
./osm2pgsql /path/to/planet.osm.bz2
or
bzcat planet.osm.bz2 | ./osm2pgsql -
If you already have planet.osm uncompressed, then you can simply do:
./osm2pgsql planet.osm
This process requires significant amounts of free memory (by rough estimate, at least 512 MB). If it runs out of memory, it can fail in somewhat unpredictable ways (e.g. messages suggesting that errors exist in the .osm file). Make sure that you have sufficient free RAM and swap space available before running osm2pgsql.
You can also enable a pgsql intermediate storage by calling osm2pgsql with the -s (or --slim) option. osm2pgsql will then store the intermediate data in the database, thereby using less RAM, but it will be much slower.
Note that that will connect to database 'gis' by default. If you want to use another database name, you'll need to pass it at run time (e.g. osm2pgsql -d foo )
Setting up mapnik
Mapnik uses external data for lower zoom levels, so you'll have to get that first (about 600M tarball, 1.2G unpacked):
wget http://artem.dev.openstreetmap.org/files/world_boundaries.tar.bz2 tar xjf world_boundaries.tar.bz2
Checkout the Mapnik stuff from the OSM subversion repository at svn.openstreetmap.org/applications/rendering/mapnik .
Create a local copy of the "set-mapnik-env" script and edit it to fit your local file names etc. All the settings are documented inside this script.
Create the osm.xml file from osm-template.xml by calling:
source ./set-mapnik-env ./customize-mapnik-map >$MAPNIK_MAP_FILE
You can now call
./generate_tiles.py
or
./generate_image.py
to generate maps.
More stuff
See in Trac: http://trac.openstreetmap.org/browser/applications/rendering/mapnik

