↑ OpenStreetmap Hacker's guide ↑↑ Net & Web  

Custom map style (2) - advanced modifications

Changing the map projection

This page describes modifications to the OpenStreetmap style that are more involved than those from the previous page. The old standard OpenStreetmap style in XML format will remain out starting point, and the OpenStreetmap database will still be the main data source.

Changing the map projection

The projection in which the map is rendered is specified in the srs attribute of the Map tag in the XML mapnik style file. In the standard OpenStreetmap style, it is located at the start of the top-level XML style file, osm.xml. Mapnik supports changing the projection of the map to be rendered independently of the projections of data sources. So modifying the srs attribute of the Map tag gets you a style suitable for rendering a map in a different projection. There is one caveat: Mapnik expects the map region to render in the target coordinate system. So your rendering program has to use the projection from the style file to convert the map region from latitude/longitude or whatever corrdinates it is specified in. My example rendering program supports that.

Why would you want to change the map projection? Both Wikipedia and the proj manual agree that the Mercator projection is not well suited for world maps, and the pseudo-Mercator default projection of OpenStreetmap is a close relative. The region the Mercator projection is best suited for is near the equator. If you render a map of a small to medium-size country somewhere else, you can find a projection with much less distortion. Many projections have parameters that determine where they are most accurate. The the proj manual contains a list of those supported by the proj library, which Mapnik uses.

I have generated a comparison of three renders of Scotland and northern England with different projections. Start here and cycle through them to see the differences. The first is the Mercator projection, the second the transverse Mercator centred on the map region, and the third the Lambert cylindrical equal area projection. The first two are conformal, i.e. angle-preserving. The Mercator projection shows significant distortion so far from the equator, while the transverse Mercator is much more accurate for being centred on the map. It would also have been possible to use the oblique Mercator projection with parameter +alpha=90 to get an equivalent of the ordinary (non-transverse) Mercator projection centred on the map. But the distortion near the centre point is so small that the result does not differ visibly from the transverse Mercator map.

Hill shading and contour lines

Adding supplementary data


Licensed under the Creative Commons Attribution-Share Alike 4.0 Germany License

TOS / Impressum