Map tiles and bounding boxes
Why does Mapnik render so much of Germany and so little of Cleveland?
That's a great question from one regular reader.
Let's go through how to get Mapnik to render the areas that interest you. Follow along and I'll make this general enough that you can render Cleveland, Columbus or even Cincinnati!
First decide on the bounding box that you want to render. You'll select a minimum and maximum of both longitude and latitude to generate tiles that cover a rectangular area[1]. Visit OpenStreetMap and navigate to your area of interest.
Then select the Export
tab on OpenStreetMap. The export window will display the coordinates of your current bounding box. It is probably not exactly what you want.
Use the super-secret OpenLayers select an area hack. Use [shift]-[click]-[drag] to select your area of interest. It will be highlighted in the map window. When you release the [click] your new bounding box coordinates will be displayed in the export area window.

To render your Cleveland tiles ~/mapnik/generate_tiles.py is going to do the trick for you. You probably want to copy the default to your own cleveland_generate_tiles.py or something similar. Then get rid of the areas that you don't care to render, like Europe. Nothing against Europe of course, but we're talking about Cleveland here.
In this example I've deleted everything below the section shown here. This will render the coastline for all of the world, from zoom 0 to zoom 5.
#-------------------------------------------------------------------------
#
# Change the following for different bounding boxes and zoom levels
#
# Start with an overview
# World
bbox = (-180.0,-90.0, 180.0,90.0)
render_tiles(bbox, mapfile, tile_dir, 0, 5, "World")
Now let's add our Cleveland rendering immediately below the World
section.

Transpose the bounding box coordinates from the export box to the cleveland_generate_tiles.py script in the order shown.
bbox = (-81.898,41.37, -81.498,41.612)
render_tiles(bbox, mapfile, tile_dir, 6, 18, "Cleveland")
Also set the minzoom, maxzoom lavues to suit your purposes. This example will generate tiles for the selected area in Cleveland from zoom 6 to zoom 18.
You could easily generate a bounding box for Ohio, or the midwest and generate tiles for that region from zoom 5 to zoom 11, then just do Cleveland for the higher zoom levels. Additional bbox and render_tiles lines will be executed in order until the end of the file.
[1] Rectangular area
? Have you not heard of projection!?!?! Don't you know that the Earth is spherical-ish? Yes. I get it. We're generating square tiles for presentation on flat paper or a flat computer screen. For the purposes of this tutorial the Earth is flat.




Articles © 2010
Map images and data © 2010
"Use the super-secret
"Use the super-secret OpenLayers select an area hack. Use [shift]-[click]-[drag] to select your area of interest. It will be highlighted in the map window. When you release the [click] your new bounding box coordinates will be displayed in the export area window."
Or just click the "Manually select a different area" link and drag rather than playing about with key combos.
Thanks for that tip!
Thanks for that tip!
how to calculate number of tiles that will be downloaded
Do you have any tool to calculate the number of tiles that will be downloaded for a specific bounding box at a specific zoom level? It would be good to be able to estimate how many tiles (and filesize) a higher zoom level will add.
Post new comment