[OSM-dev] Converting OSM Mapnik stylesheet to Cascadenik or Carto

Komяpa me at komzpa.net
Fri Jul 29 22:42:41 BST 2011

>> It is rather easy to produce SQL queries that will take out of the
>> database only data referred by stylesheet. In fact that's already done
>> in both Komap and Kothic.
> I don't doubt you do, however I would have to know a little more about your
> solution to comment.


Everything is open source and you're free to fix something if you find
some mistakes.
Mostly in python, SQL and javascript.

We still use mapnik for rendering, but Mapnik stylesheets are hell,
and mapnik is quite limited, so we
wanted solution that will let us change the renderer without making
people rewrite stylesheets. At the
moment when we started Carto wasn't on the horizon, Cascadenik was too
mapnik-bound, and there was
MapCSS supported by (at least then) Halcyon, Kothic, Ceyx. Rendered
images were quite nice, so I
implemented mapcss translator, named Komap. It heavily uses Kothic
MapCSS parser, and its SQL query generator.

Komap isn't a full-featured MapCSS-to-mapnik translator: it doesn't
handle eval() (as there's no eval() in mapnik and
it wasn't worth implementing eval-to-SQL translator, though it's
possible), and it doesn't handle cascading, as enabling
cascading in mapnik0.7 leads to 100+mb stylesheets with rules like "if
it's highway=bus_stop, but not a shop, not a
place, not ... - do this. if it's highway=bus_stop, and a shop in the
same time, and not a place, and not... - do slightly different thing".

(If you'd like to experiment more with cascading-enabled Komap, it's
checked into its own branch, although I don't really try to make it
work any more.)

Even with those limitations, it lets me write one and the same
stylesheet for Mapnik, Kothic JS, and Potlatch 2, which is impossible
now in Carto or Cascadenik.

Kothic JS was made as an attempt to break client/server-side rendering
barrier. It's server part (json_getter) is also
heavily based on Kothic MapCSS parser, and selects (and generalizes,
which is a lot more computationally harder) only features referred by
It's not currently used in production environment, although it can
handle everything we need already - the only thing we're waiting for
is Mozilla and Google
to fix their browsers to let it render data faster.

Now, links to code and things:

http://code.google.com/p/kothic/source/browse/src/komap.py - Komap;
- dumb script to make default.style for osm2pgsql that will refer only
tags used in given mapcss stylesheet;
http://code.google.com/p/kothic/source/browse/src/json_getter.py - a
tool that generates generalized tiles for Kothic JS;
- mapcss stylesheet, used by us when rendering OSM for kosmosnimki.ru;
http://kothic.org/js/ - firebug it and see generalization on lower zoom levels;

Also, you may have a look at OSM layer on http://maps.kosmosnimki.ru/.
There's also "English" link in right-upper corner that will switch
labels on the map into latin.

Darafei "Komяpa" Praliaskouski
xmpp:me at komzpa.net mailto:me at komzpa.net

More information about the dev mailing list