3

I am trying to understand how a typical tile server is implemented in practice. I am not considering setting up a tile server but rather trying to understand from a conceptual point of view the algorithms behind a typical tile server.

So for example, as a starting point, a tile server receives a request similar to the following URL template http://[abc].tile.openstreetmap.org/zoom/x/y.png.

What are exactly the next chain of events in the processing of such a request? In the typical case of OpenStreetMap, I know that the actual data is stored in PostGis and that mapnick is used for rendering the tile.

However I have a hard time understanding how the tile is actually rendered given the zoom, x, and y inputs.

Edit: I found the following diagram, which gives you a high-level architecture of the OpenStreetMaps tile server. http://wiki.openstreetmap.org/wiki/Component_overview

2 Answers 2

4

The client is responsible for taking the template and filling in the zoom, x & y values before calling the server. So all the server sees is a URL that looks like:

http://a.tile.openstreetmap.org/0/0/0.png

which is a simple request for an image. So the simplest possible tile server is just an ordinary Apache (or Nginx) server with a series of folders for each zoom level with sub folders for each row (x) inside them containing all the tile images for that row (y.png).

More complex tile servers generate the tiles as they are requested by rendering some data and save the tile to the disk to save time later if the tile is requested again.

1
2

@iant has given you a very clear reply for the bulk of your question. To answer your last sentence, given the zoom,x,y portion of the URL, a tile server that also renders the tiles will compute the bounding box of the given tile and then use a renderer with a style definition to generate the tile. A very common renderer is Mapnik. An alternative is that the tiles are produced 'up-front' (for example by GDAL). Other renderers are available.

The renderer uses the style definition to call the GIS data from files or databases and then creates a raster image based on the style for each layer (and the layer order) limited to the bounding box, much like making a map in QGIS or ArcGIS. This image is then sent to the user and usually simultaneously cached to disk to speed up the process next time.

EDIT re bounding boxes
The tiles are based on a grid, and usually conform to a well known grid defined as part of the TMS or WMS protocol. Other grids can be used but the convention is to start with a single square tile that covers the entire globe of side 256 x256 pixels. That is zoom level 0. Then for each zoom level increment subdivide the tile by powers of two (so z1 has two tiles, z2 has four and so on). If you scroll down in the link you posted you will actually find information on defining the bounding box (bbox) assuming the standard powers-of-two grid system. The bbox (or a meta tile based on it) is indeed used to fetch the data from a database, raster or shapefile etc. Have a look at Getting Started tutorial for Geoserver as this will help you understand what's going on. Geoserver is an excellent and open source package that renders, serves and caches tiles. I recommend you actually set up an instance of Geoserver locally on your PC as there's nothing like actually doing it to really understand something.

2
  • @iant thanks for the feedback. One more point: how is the bounding box determined (given, zoom, x &y)? I suppose there is a formula to find the upper left and lower right corners? Then I suppose you need to fetch the map data in postgis (or a similar gis database?). I found the following link explaining how to map (lat,long) to x,y. However no mention of bounding boxes: wiki.openstreetmap.org/wiki/Slippy_map_tilenames Commented May 8, 2017 at 20:18
  • Your link does contain information on bboxes (scroll down). See my edits for additional related information. Commented May 9, 2017 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.