[Mapcss] My mapcss implementation
Sebastian Spaeth
Sebastian at SSpaeth.de
Mon Jul 5 06:54:26 BST 2010
Dear all (anyone but Richard F so far? :-))
here I am. I loved toying with mapcss and the result became kind of more useful
than just a simple toy, so I am putting my results out early:
I implemented a mapcss parser and dead-simple renderer in python. It
needs python >= 2.5 and python-cairo installed (but that should be all).
The code is here: http://bitbucket.org/spaetz/mapcss-renderer
(if you just want to see it in action and you have python-cairo
installed, get the whole thing
http://bitbucket.org/spaetz/mapcss-renderer/get/tip.tar.gz
unpack it, and run (don't let the "svg" mislead you):
./osm2svg.py > test.png (and admire the resulting image file).
./osm2svg.py -h gives you the command line options.
It is still a bit unclean, but I want to get it out now. So here are the
dirty details:
- License: There are no licences attached yet, it is likely to become a GPL v2+
thing unless someone convinces me of anything else. (I wouldn't mind
BSD/GPL v2+ combo although I prefer the GPL somewhat).
- Mapcss parsing is all done in that osm2svg.py file (needs to be put
into it's own module) and it has some limitations yet. This works:
way[!highway], node[highway=bus_stop] {color:red;}
node[bus_line>15] {color: #2030AC; z-index=1;}
way .important {width: 5;}
It uses C-style comments /* */ for allowing comments.
This does not work:
- no support for pseudo class ":area" yet,
- no nested rules yet:
way[highway] node[highway=pissoir] {color:red;}
- no stacked rule sets yet
way {z-index:1;color:green;} {z-index: 2;color:magenta;}
- no regex searches
- no declarations { .set foo }, and no @imports
The result of the MapCSS parser is the .osm file as an python
ElementTree structure with all suitable CSS rules added to each way or
node. It's all loaded to RAM now, so it might well bomb out on large
data sets, I haven't tried bigger ones than the small test data in the repository.
My test renderer is in OSM/OSMrenderer.py taking that ElementTree
structure and outputting things into a .png file. All it currently
does is drawing lines for ways and circles for nodes, honoring
z-index, color, and width arguments from MapCSS. It is not very
efficient but does its (simple) job.
OK, there you go. I have more specific questions on MapCSS but will
postpone that to another day and mail. I am interested who else is
interested in (ab)using mapcss. My implementation is a toy and I don't
have any comercial interests in pursuing its implementation and I easily
might lose interest into putting in the 80% of effort to reach the last
20% of perfection.
spaetz
More information about the Mapcss
mailing list