I'm using CartoCSS together with an OSM Postgres DB (hstore on). I want to set the line color depending on the operator tag of relations (routes). How can I do that?


Thanks to Paul Norman for showing how to include tags only in hstore. As Andre Joost points out, for the operator tag that's not necessary, because it's already included with the default osm2psql config.

Doing some more research, I could dig deeper into the problem and with some surprise found out that there's a divergence between the documentation on http://wiki.openstreetmap.org/wiki/Osm2pgsql/schema and my DB instance.

It says: planet_osm_line: This table contains all non-closed ways which were imported. Additional rows are created for ways which are members of type=route relations. ... The osm_id is the negative ID of the relation

While there are rows with negative osm_id's in the DB, I could not find such an entry for 2 randomly tested ways, e.g. for http://www.openstreetmap.org/way/280802857. As you can see, this way is a member of a relation (3731203) fulfilling the mentioned requirements.

Now I'm not sure if that's the source of my problem. I don't know if that osm2pgsql doc is up to date and I don't know if mapnik uses this DB entries with negative osm_id to evaluate relation tags. But I would guess so.

As a quick fix I manually added a column to the planet_osm_line table with the info I need. But I'd prefer to get rid of that hack asap.

Any hints how to proceed?

2 Answers 2


Mapnik doesn't directly support hstore, so in your SQL queries you need to extract the value you want from the hstore column. An example of this would be

( SELECT way, name, (tags->'operator') AS operator FROM planet_osm_line WHERE ...) AS routes

In your MSS you can then colour based on the operator column in the SQL result, which is the value extracted from the hstore column in the table.


According to the default style of osm2pgsql for carto,


the operator tag should be imported as a separate column. So no need to use the hstore column for that.

Routes from relations are stored in a osm2pgsql populated database with negative IDs, so you can add that condition to your table query too.

Keep in mind that the road that is used by the route is styled differently, independent from the route(s). So make sure the route is rendered on top of the road.

The CartoCSS definition file project.mml is processed from top to bottom, so your route.mss should be placed somewhere after the road.mss. And it should have a separate entry in the Layers section, if you want to filter the osm_id by negative sign.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.