Tile Server (2011): Difference between revisions

From Planimate Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 15: Line 15:
*I found I had to install 'unzip', might as well do that first
*I found I had to install 'unzip', might as well do that first
<pre>sudo apt-get install unzip</pre>  
<pre>sudo apt-get install unzip</pre>  
*Leter in the guide it says to do this:
*Later in the guide it says to do this:
<pre>psql -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql -d gis</pre>  
<pre>psql -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql -d gis</pre>  
This directory didn't exist so instead I did:  
This directory didn't exist so instead I did:  
Line 21: Line 21:
If you read the article's comments, you'll find this is how it used to be.  
If you read the article's comments, you'll find this is how it used to be.  


*I only downloaded Australian data, so my import was:<br>
*I only downloaded Australian data, so my import was different. Also notice the -C parameter. This is the amount of RAM the import uses for caching, you might want to reduce it if space is tight.<br>
<pre>cd ~/bin/osm2pgsql
<pre>cd ~/bin/osm2pgsql
./osm2pgsql -S default.style --slim -d gis -C 2048 ~/planet/australia.osm.bz2
./osm2pgsql -S default.style --slim -d gis -C 2048 ~/planet/australia.osm.bz2
Line 27: Line 27:
It took about 15 minutes. I continued with the mapnik installation while the database ground away. Take care copying those long URLs in the prepared data section.  
It took about 15 minutes. I continued with the mapnik installation while the database ground away. Take care copying those long URLs in the prepared data section.  


The guide got me to generating a map from the command line with little fuss.  
The guide got me to generating a map from the command line with little fuss.


=== Create an OSM file for your database  ===
=== Create an OSM file for your database  ===

Revision as of 13:10, 30 July 2011

The Planimate Map object enables the use of tiled map data in models. These notes describe the setup of a map tile web server which can be used with Planimate or other open Street Maps projects.

The bulk of the install is described here and credit to the author for this guide, which gets you from a bare linux install to locally creating map tiles.

Setting up the VM

Create a new VM, pointing it to a Ubuntu 10.04 ISO (ubuntu-10.04-server-amd64.iso). I selected 3.5GB RAM, 100GB HDD and bridged networking. Selected defaults for the rest. In a few minutes you'll be at a linux login.

This was a first test, only for the Australia region. I'll see how it copes with the whole world when I get round to downloading some 8GB of data.

Installing PostGIS, Mapnik

Follow the guide linked above. Its useful to ssh in and copy/paste in a line at a time. I used PUTTY as the terminal. The guide is pretty well spot on except these:

  • I found I had to install 'unzip', might as well do that first
sudo apt-get install unzip
  • Later in the guide it says to do this:
psql -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql -d gis

This directory didn't exist so instead I did:

psql -f /usr/share/postgresql/8.4/contrib/postgis.sql -d gis

If you read the article's comments, you'll find this is how it used to be.

  • I only downloaded Australian data, so my import was different. Also notice the -C parameter. This is the amount of RAM the import uses for caching, you might want to reduce it if space is tight.
cd ~/bin/osm2pgsql
./osm2pgsql -S default.style --slim -d gis -C 2048 ~/planet/australia.osm.bz2

It took about 15 minutes. I continued with the mapnik installation while the database ground away. Take care copying those long URLs in the prepared data section.

The guide got me to generating a map from the command line with little fuss.

Create an OSM file for your database

This file tells renderd about your database. I also edited some of the other py files like render_tiles.py to point to "my_osm.py".

cd ~/bin/mapnik
./generate_xml.py osm.xml my_osm.xml --dbname gis --symbols ./symbols/ --world_boundaries ./world_boundaries/ --user rick --accept-none

Web Server

The module uses a multithreaded version of apache.

sudo apt-get remove apache2
sudo apt-get install apache2-threaded-dev

Build Apache Tile Module & renderd

Make sure you are the user that can access the DB, not root.

cd ~/src
svn co http://svn.openstreetmap.org/applications/utils/mod_tile/
cd mod_tile
make
sudo make install
mkdir /var/lib/mod_tile
mkdir /var/run/renderd

(if directories already exist, make sure they have write access to the user).

Edit renderd configuration

The make install above copied /etc/renderd.conf from the src directory. In this setup, both Apache and the renderd program use this configuration file.

sudo vim /etc/renderd.conf

Edit as follows, adjust the home directory as appropriate:

[renderd]
socketname=/var/run/renderd/renderd.sock
num_threads=4
tile_dir=/var/lib/mod_tile ; DOES NOT WORK YET
stats_file=/var/run/renderd/renderd.stats

[mapnik]
plugins_dir=/usr/local/lib/mapnik/input
font_dir=/usr/share/fonts/
font_dir_recurse=1

[default]
URI=/tiles/
XML=/home/rick/bin/mapnik/my_osm.xml
#HTCPHOST=proxy.openstreetmap.org

Start renderd

For debugging, do this in a separate window - as regular user, not root.

~/src/mod_tile/renderd -f

You should see activity as tiles are requested. You'd start a single instance in the background using

~/src/mod_tile/renderd

or multiple instances (for each thread) using

 ~/src/mod_tile/renderd.py &

Set up Apache configuration

Copy the configuration file for mod_tile then edit it:

cd ~/src/mod_tile
sudo cp mod_tile.conf /etc/apache2/mods-available
sudo vim /etc/apache2/mods-available/mod_tile.conf

The changes are in the first few lines:

  • comment this out, we'll load it separately
#LoadModule tile_module modules/mod_tile.so
  • change the servername and comment out the alias line
ServerName maps
  • update the document root
DocumentRoot /var/www/
  • enable the use of the config file in /etc
LoadTileConfigFile /etc/renderd.conf

Thats it for the edits.

Now create a load file for the module and create the links in mods-enabled.

sudo echo LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so > /etc/apache2/mods-available/mod_tile.load
sudo ln -s /etc/apache2/mods-available/mod_tile.load /etc/apache2/mods-enabled/mod_tile.load
sudo ln -s /etc/apache2/mods-available/mod_tile.conf /etc/apache2/mods-enabled/mod_tile.conf

You can now restart apache and check the module is loaded:

apache2ctl restart

From a web browser, navigate to the IP of your VM

http://192.168.0.151/mod_tile

Now fetch a tile

http://192.168.0.151/tiles/0/0/0.png

If things dont work, check:

  • Can renderd write to /var/lib/mod_tile and /bar/run/renderd
  • Apache's error log
  • Is font path correct in renderd.conf