Rotated Maps
The follwing graphics are examples for a series of maps along a cycle route (and incidentally along part of a river, the Danube), the EuroVelo6 (EV6) between Linz and Vienna. The images are rendered in 1:100,000 scale (assuming 72dpi screen resolution), but scaled according to the web browser screen space (thus the maybe hardly readable text), as an overview. By clicking on the images you can download more detailed and readable 1:50,000 scale renderings.
Technique
There are some issues involved when rendering a rotated map, compared to a normal north oriented map. Some of these are specific to the mapnik rendering stack, but others would also require special attention for osmarender based rendering. In summary, the following topics had to be solved:
- Making mapnik rotate the output of rendering (while keeping the text upright); there does not seem to be a possibility (yet) to do that; neither did I find an appropriate projection, which would have as one parameter the orientation. So, the next best solution is:
- Rotating OSM data in the database, while keeping track of the original bounding box (no longer aligned along the main axes of the coordinate system). The first part is easy, using the PostGIS function ST_Affine, after the maths of calculating the rotation angle and the parameters of the corresponding affine transformation matrix have been done. The latter is done by applying similar transformations to the edges of the bounding box (but manually in program code instead of in PostGIS). Afterwards, PostGIS can easily render the requested bounding box, which is now aligned to the pseudo north of the data base.
- A north-arrow is usually necessary to make orientation of the viewer easier. This is done by including some artificial lines in the data base, before rotating it, because then it is still easy to make it point exactly north. These lines can later be visualized with mapnik rules, to show a north-arrow.
- Most problematic is the adaptation of the georeferenced raster images, which
can be put in the background. The easiest approach would probably be to
manipulate the affine transformation stored in GeoTIFFs to relate the image
axes to that of the used spatial reference system (they would not need to be
aligned). Unfortunately, I was not able to make this work with mapnik rendering
(the images did not even appear in the bounding box), although it worked very
well (although slow) with qgis.
The solution to this is an extraction of the georeferenced information using listgeo, then an external rotation (e.g. using ImageMagick convert), a manipulation of the extraced geo information (because of the rotation the image size grows and the corner coordinates have to be recalculated), and a restoration of the geo information into the rotated image. This did not work in the beginning either, but with a final gdal_translate, to restore information about missing values and, probably most importantly, the bands to use and their interpretation, this approach works out well, as can be seen in the images above. - Finally, an easy to use interface would be necessary for easy creation of such maps. This so far has stalled due to missing time/other things of higher priority. In the meantime, I obtain the configuration parameters for the script (basically the starting and end coordinates of a line specifying the position and orientation of the map, and four numbers specifying the margins to include around this line) as follows: There is the web page CycleRoute, which allows to edit a route (some points connected by lines) which can be saved as a gpx file. This is read in, and the coordinates stored there can easily be converted to the configuration parameters just mentioned.