Creating your own tiles

From OpenStreetMap Wiki
Jump to: navigation, search
Available languages — Creating your own tiles
· Afrikaans · Alemannisch · aragonés · asturianu · azərbaycanca · Bahasa Indonesia · Bahasa Melayu · Bân-lâm-gú · Basa Jawa · Baso Minangkabau · bosanski · brezhoneg · català · čeština · dansk · Deutsch · eesti · English · español · Esperanto · estremeñu · euskara · français · Frysk · Gaeilge · Gàidhlig · galego · Hausa · hrvatski · Igbo · interlingua · Interlingue · isiXhosa · isiZulu · íslenska · italiano · Kiswahili · Kreyòl ayisyen · kréyòl gwadloupéyen · Kurdî · latviešu · Lëtzebuergesch · lietuvių · magyar · Malagasy · Malti · Nederlands · Nedersaksies · norsk bokmål · norsk nynorsk · occitan · Oromoo · oʻzbekcha/ўзбекча · Plattdüütsch · polski · português · português do Brasil · română · shqip · slovenčina · slovenščina · Soomaaliga · suomi · svenska · Tiếng Việt · Türkçe · Vahcuengh · vèneto · Wolof · Yorùbá · Zazaki · српски / srpski · беларуская · български · қазақша · македонски · монгол · русский · тоҷикӣ · українська · Ελληνικά · Հայերեն · ქართული · नेपाली · मराठी · हिन्दी · অসমীয়া · বাংলা · ਪੰਜਾਬੀ · ગુજરાતી · ଓଡ଼ିଆ · தமிழ் · తెలుగు · ಕನ್ನಡ · മലയാളം · සිංහල · ไทย · မြန်မာဘာသာ · ລາວ · ភាសាខ្មែរ · ⵜⴰⵎⴰⵣⵉⵖⵜ · አማርኛ · 한국어 · 日本語 · 中文(简体)‎ · 吴语 · 粵語 · 中文(繁體)‎ · ייִדיש · עברית · اردو · العربية · پښتو · سنڌي · فارسی · ދިވެހިބަސް

Creating your own tiles is a great way to use OpenStreetMap data. In fact it helps the project if more people do this, since it is a great way to demonstrate the flexibility of OpenStreetMap (you can create your own map style, and render your certain tags more prominently) and it means less load on our tile serving infrastructure.

Tiles are small square map images which, typically get pieced together by the web browser running a javascript library for display "slippy map" (See Deploying your own Slippy Map for the options). Serving a set of tiles can involve simply creating a few folders full of tile images on your web server, following some tile naming conventions. However there are several refreshing and caching strategies to think about (particularly for large areas, or worldwide tilesets) and also several rendering options for creating the map images in the first place.

The Switch2OSM website carries some nicely formatted guides to creating and serving tiles

Creating tiles using Mapnik and generate_tiles.py

This is the method used by, for example, the OSM cycle map. Its main advantage is that nothing needs to run on the webserver - it just needs a directory of image files. So, for example, you can install all the software on your home PC, and transfer the tiles to your webhost when you're finished.

  • Download the planet file from planet.openstreetmap.org
  • Import into a PostGIS database using osm2pgsql
  • Set up mapnik and test using osm.xml and the generate_image.py
  • When everything works, use generate_tiles.py to create 1000s of tiles in a special hierarchy of folders
  • Copy/move tiles into your webserver's document root.
  • Change the OpenLayers instance to use your own tileserver instead of the main one

Creating tiles using Mapnik and mod_tile

This is the new system deployed on the main OSM map in 2008. It uses a custom C implementation to efficiently serve tiles from the disk and schedule rendering requests.

  • Download the planet file from planet.openstreetmap.org
  • Import into a PostGIS database using osm2pgsql
  • Set up mapnik and test using osm.xml and the generate_image.py
  • Compile and install mod_tile
  • Run the rendering daemon and ensure it can write to the tile storage directory
  • Configure your Apache server to load and run the module
  • Change the OpenLayers instance to point to your server like this: http://wiki.openstreetmap.org/wiki/OpenLayers_Simple_Example#Extensions

Creating tiles using Mapnik and Mysql/Ruby/Python

This solution which was in use on the main OSM map for almost all of 2007. The tiles were served by a ruby script which fetched the tiles from a MySQL database. If the tile was old or missing then the database would be updated to mark the tile for rendering. A background script would scan the database and render the tiles using a python script.

  • Download the planet file from planet.openstreetmap.org
  • Import into a PostGIS database using osm2pgsql
  • Set up mapnik and test using osm.xml and the generate_image.py
  • Copy the scripts from SVN tile.openstreetmap.org
  • Setup a tile database in MySQL using the schema.sql file
  • Setup mod_ruby to run the cat_tile.rb script on your web server
  • Setup mod_rewrite with a rule to call the ruby script:
 RewriteRule ^//(-?[0-9]+)/(-?[0-9]+)/(-?[0-9]+).png  /ruby/cat_tile.rb?x=$2&y=$3&z=$1 [PT,T=image/png]
  • Periodically run the render_some_tiles.rb script to fulfill the tile rendering requests
  • Change the OpenLayers instance to point to your server instead of the pre-rendered tiles.

Creating tiles using Mapnik and tilecache

This is the method lets you generate the map as you view it instead of requiring any pre-rendering. This method can struggle at higher load levels if too many people try to look at unrendered tiles simultaneously. You need pretty much full control over your webserver in order to install everything.

  • Download the planet file from planet.openstreetmap.org
  • Import into a PostGIS database using osm2pgsql
  • Set up mapnik and test using osm.xml and the generate_image.py
  • Set up tilecache to render tiles on-demand
  • Change the OpenLayers instance to use your own tilecache server instead of the pre-rendered tiles.

Another "HOWTO deploy you mapnik slippy map" with real-time rendering

Howto real time rendering

Displaying your Tiles

Map Application (UI)

Whether you use Mapnik or Osmarender to generate the tiles, you will need a web interface to browse them.

The logic that does the zooming and panning is usually implemented in Javascript. You can either use OpenLayers, or you could also use the Google API to access the tiles. In both cases you will have to somehow add your layer to the list of layers available for selection, and adding your layer will require specifying the web server and base path - the interface will then add /zoom/x/y.png depending on which tile it needs (See Slippy map tilenames)

We use the OpenLayers javascript for our our main map and also at informationfreeway.org. The OpenLayers 'Getting Started' doc explains how to initialize a 'map' object in javascript. To make this work with our tiling scheme, you need a 'TMS' layer and bit more javascript logic. See our OpenLayers Simple Example. For more slippy map features (supporting layer selector, permalinks, etc) you might like to poke around in the javascript source of informationfreeway.org

Using Maperitive

Maperitive has a command for generating tiles which can be invoked both through the GUI and through scripting (so it can be automated). The tiling scheme is compatible with OpenLayers.

Notes

Links