Osmarender bug

From OpenStreetMap

Jump to: navigation, search

The so-called Osmarender bug refers to the fact that when the osmarenderer renders an area, it selects the by lon/lat, but only truly projects one point in the middle; the rest is a linear interpolation, not a true projection.

A way of thinking about it is that instead of projecting a sphere, we're projecting a sphere-like object constructed out of 4096×4096 parallelograms. The advantage of this is that straight lines (like roads) project straight whereas in a true projection they would be curved. It means that at the edge of a tile roads may get a kink as they step from one projection to another.

Error

Obviously this means that when you put a point on a map, the actual lat/long coordinates are not what you expect. However, the error is not very large. If you look at the math behind Linear interpolation you get the following formula:

Error ≤ ((x1−x0)2)/8 max | f″(x) |

When f(x) is the function transforming the mercator y coordinate the actual degrees. f(x) = arctan(sinh(x)) (from Wikipedia:Mercator projection). Since the osmarender interpolation works over the range of π/4096 and the second derivative has a maximum of 0.5, it makes the maximum error of 3.63e−8 degrees, or about 1.5 metres on the earths surface. This error will be achieved at a latitude of ±51 degrees (approximately the latitude of London or Brussels).

Lowzoom

If you look at the formula you can see that as you move to lower zoom levels, the error grows by the square. This error doesn't occur if you stich the tile together. Thus error for lowzoom tiles are:

Zoom Error (distance) Scale (256px tiles) Error in pixels
11 6m 76m/px 1/12px
10 24m 153m/px 1/6px
8 384m 610m/px 1/2px
6 6144m 2441m/px 3px
4 98304m 9765m/px 10px

The pixel amounts seems small, but these are best case scenarios. If you do all your projection at zoom 8 and then go render zoom 12 tiles, the error gets magnified, in this case to 16*1/2 = 8 pixels. But if you use z4 as a base to project z8 tiles it'll be up to 16*10 = 160 pixels off!

Possible fix

The problem can be fixed by doing the projection outside of Osmarender. One would have to translate an OSM file with latitudes and longitudes to one with already projected x and y values (or Eastings and Northings if you prefer). This would likely have the following advantages:

  • No projection error
  • Faster processing since XSLT is not good at maths
  • Even faster in the tiles@home context since projection would have to be done only once per tileset, not once per zoom level, and tiles could be cut from one big bitmap (a la tilesPipe@home)
  • Easy changeover to other projections if desired

A disadvantage of this would probably be the fact that Osmarender would be unable to draw a lat/lon grid or in fact display a scale in metres or miles because it would not know anything about the geographic bounding box it is rendering.

User:Frederik Ramm has a prototype projection script and a modified Osmarender to work with its output. It seems to do what it should, but has to be tweaked and polished a bit before it can be used to revive tilesPipe@home.

Personal tools
recent changes