1

I am wondering how to find the parent map tiles of a particular tile or the tiles contained within a particular map tile. I know tiles usually have the structure of somedir/{z}/{x}/{y}.png/jpg and I know their is a formula for projecting WGS84-coordinates to tile-names:

http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames

E.g. If you change a geometry on a zoom level 18 map tile, do you then have to calculate the tilename on zoomlevels 17 - 1 using the formula to find out which tiles are effected or is there a more efficient way of finding the parents or children of a certain tile?

I have also found this link with notes on how to update tiles, but there seems to be no information concerning my question:

http://wiki.openstreetmap.org/wiki/Tirex/Tile_Update_Strategies

1

Basically, No. Most of the time, you can simply divide/multiply x and y by 2 when zooming in/out. However, if you look at the equations from the slippy map links you provided, you will note that both lon2tile and lat2tile functions include the FLOOR function, which means that occasionally the series will be x/2-1 or x/2+1 and the same for y, depending on whether you are zooming in or out. Furthermore, while the equation for longitude is linear, the function for latitude includes the arctangent, which is one of the reasons why scale gets distorted in 3857, the further north/south you go.

If you load the Postgres example function, lon2tile and lat2tile, you can quickly generate a few x/y/z combinations and see this effect (or Javscript, Python, Haskell, whatever takes your fancy).

SELECT z, lon2tile(25,z), lat2tile(25,z) FROM generate_series(1, 20) z;

 z  | lon2tile | lat2tile 
----+----------+----------
  1 |        1 |        0
  2 |        2 |        1
  3 |        4 |        3
  4 |        9 |        6
  5 |       18 |       13
  6 |       36 |       27
  7 |       72 |       54
  8 |      145 |      109
  9 |      291 |      219

etc.

There is no deterministic way of knowing when a tile will be a power of 2, relative to a previous layer, and when you will have to +/-1.

The cost of calculting lat/lon to tile and vice versa is so cheap computationally, that I wouldn't think it matters anyway.

  • Thanks for the detailed answer! So if I understand correctly: When editing a very large geometry (e.g. Aral Sea drying up; new political borders) with a large number high zoom tiles (e.g. zoom:18 = 3 million tiles), one would have to calculate the tile name 3'000'000 x 18 = 54'000'000 times to get the names of all effected tiles in all zoom levels? – Mfbaer Nov 3 '17 at 12:22
  • Well, that is a different question. But, no, you would not, you would only need to calculate the 4 tiles that would make up the bounding box, of say, the Aral sea at any zoom level. So, for four lat/lon points, this would only be 72, ie, 4 * 18 tile calculations, and the rest you could just fill in. – John Powell Nov 3 '17 at 12:38
  • I see where you're going with this (you would theoretically only need 2 tiles: bottomleft & topright i guess). The problem is that if you want to identify which tiles must be rerendered, then a boundingbox is only suboptimally suited, because alot of tiles not needing rerendering would be identified as lying inside the boundingbox and thus be marked to be rerendered. But I guess this is truely another question. – Mfbaer Nov 3 '17 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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