wiki:ZoomLevels

Version 5 (modified by Uriel, 7 years ago) (diff)

--

Generating a set of web tiles from SRTM data involves a careful dance of loading just enough data into RAM to generate the world one "slice" at a time. This is a theoretical discussion of how it might be done. It's similar to what was used to write the python script gen_terrain_tiles_script.py, but isn't the same. Truthfully that python script would be much improved if this document was written first. . .

Zoom Levels

Zoom LevelDegrees Lon.
0 360
1 180
2 90
3 45
4 22.5
5 11.25
6 5.625
7 2.8125
8 ~1.406
9 ~.703
10 ~.352

More info can be found on the OSM Wiki

Generating A Map

Obviously we can't just load up all the SRTM data at once and click "go". This would require many Gigabytes of RAM, and presumably you do not have access to that kind of hardware. Instead, let's think about breaking the world down into smaller, manageable pieces.

Let's assume we want to generate a map at zoom level 7. Each web tile at this zoom level is a square, 2.8125 degrees on a side. SRTM data comes in squares, 1 degree on a side. It's not possible to load only part of an SRTM tile in Maperitive. We also need to be sure to load more data than we need. If we only load a single 1 degree tile, Maperitive will not be able to fill the entire 2.8125 degree tile with data and will generate nothing instead.

How much data do we need to load at a time? To keep things simple and small, we'll do our math in only one dimension, and we'll only try to generate 2 web tiles at a time. In practice one would generate these tiles, then start Maperitive over to clear the RAM and generate the next two tiles.

The most data we could possibly waste on the left side of the tile is just about 1 degree. We'll say .999. So if our (fictional) tile at zoom 7 starts at 6.999 degrees, we will still need to load the SRTM data starting at 6.0 to ensure we cover that little bit before 7.0. The right border of our two-tile window is 6.999 + 5.625 = 12.624 degrees. Since our SRTM data needs to overshoot that, our SRTM window must go from 6 to 13 degrees. That's 7 tiles.

Starting from 0, how would this play out if it was scripted?

  1. The first two web tiles run from 0 to 5.625. Our 7 degree window covers 0 to 6, more than enough to capture both tiles. We will be throwing away the data after 5.625, which is not a problem.
  1. The next two web tiles run from 5.625 to 11.25. We need to start our 7 degree window at 5 to catch the start of the tile, so it covers 5 to 12 degrees. Again we throw away a bit but fully cover two tiles.
  1. The next two web tiles run from 11.25 to 16.875. Following the pattern, our 7 degree window runs covers 11 to 18 degrees.
  1. And so on, starting the each 7 degree window at the rounded-down (westward, really) coordinate of the previously generated tile.