[OSM-dev] Mercator projection in XSL / Osmarender

Alexander Wittig alexander at wittig.name
Sun Aug 10 21:26:22 BST 2008


Hello

I hope this is the right list for this: I may have a solution for the 
missing Mercator projection in Osmarender, aka the "Osmarender bug" 
(http://wiki.openstreetmap.org/index.php/Osmarender_bug).
For some of my completely OSM unrelated research had to implement 
certain trigonometric functions and it wasn't too hard to re-implement 
them in XSL. What I can offer are fully standard compliant XSLT 
templates to calculate sine, cosine, tangent, cotangent, secant, and 
cosecant as well as the natural logarithm up to almost IEEE double 
precision (each yields 14 valid digits or so).

Given these it is obviously trivial to implement the inverse 
Gudermannian, i.e. the function that does a Mercator projection of 
latitudes (according to the Wiki article linked in the Osmarender Bug 
page above). The Gudermannian yields about 14 valid digits for arguments 
between -89 and 89 degrees, which should be well beyond where you want 
to use Mercator anyway.

All of these operations are implemented with performance in mind, so 
they are actually relatively fast (at least so I think).
To test this I wrote the a XSLT that will take an osm file and project 
every node using Mercator projection and write them all to an html 
output file. My test set has about 4100 nodes. Using the Mac OS X 10.5 
stock xsltproc to process the 1.6 MB OSM data the whole process took 
about 0.6 seconds CPU time from start to finish on my 2Ghz MacBook. That 
of course includes the time to read, parse, process and write all the 
data. Considering that Osmarender ran for about an hour to process the 
same file into a SVG image the time used for projections seems 
negligible (although I don't know how often Osmarender needs to project 
a point, nor how big a typical OSM data set is).

If anyone is interested you can download the xslt file, my OSM test data 
set and the resulting html output at http://bt.pa.msu.edu/~alex/OSM/

Cheers,
Alexander





More information about the dev mailing list