ES:Crear tus propias teselas

From OpenStreetMap Wiki
(Redirected from ES:Creating your own tiles)
Jump to navigation Jump to search

broom

Help (89606) - The Noun Project.svg

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, or use a prepackaged extract
  • Import into a PostGIS database (PostgreSQL 9 and 10 are known to work) using osm2pgsql
  • Get the files generate_image.py and generate_tiles.py from Mapnik Github
  • Install npm and nodeJs. These need to be fairly recent to support carto.
  • Use npm to install carto: npm install -g carto
  • Clone https://github.com/gravitystorm/openstreetmap-carto and look in the scripts folder for a script that downloads necessary resources.
  • Create a mapnik xml: carto project.mml > osm.xml
  • 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

For another description of this method, see Mark Meyer's blog post OSM Tile Creation on AWS Spot.

Creating tiles using Mapnik and mod_tile

See the detailed step-by-step instructions here: [1].

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.

Displaying your Tiles

Map Application (UI)

Two javascript libraries are recommended for allowing access to raster tiles - Leaflet or OpenLayers. Each has different strengths, but Leaflet is probably easier to learn and more extensible.

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.

Links

  • Switch2OSM - Make the switch to OpenStreetMap Has step by step instructions on how to set up your own tile server.
  • This article describes an automated way to generate tiles using mapnik and carto on Ubuntu 16 running on AWS spot. The described tileset is around 250MB in size (80,000 tiles), completes in 30 minutes and costs around $0.50.