postgisopenstreetmapmaplibre-glopenmaptiles

Include all OSM tags in OpenMapTiles


I'm looking at generating some vector mbtiles for a very small subset of the OSM data, namely anything with a railway tag over a limited area. The namespace for railways:* is fairly large, which means that including tags in mapping.yaml is unwieldy. This would mean that I could pick and mix which features to render without having to serve multiple sets of vector tiles.

So two questions, is it possible to:

I've seen some conversations regarding this but they're back in 2021:

Does anyone have any knowledge on if this is possible, and if so how to do so.


Solution

  • This is going to be difficult (perhaps not impossible, but extremely difficult with OpenMapTiles specifically).

    Background

    OpenMapTiles is actually two things: a schema and a set of build tools for generating vector tiles.

    OSM data is fundamentally unstructured (schemaless). This makes it infinitely flexible and easy to edit, but it poses some challenges when it comes to consuming it (ex: for a map).

    A schema imposes order on the unstructured sea of endless tags. This isn't just about lumping groups of amenities into a "clean" layer; even determining geometry is not straightforward. The schema defines rules that, for example, certain way tags turn it into an area and put it in a specific layer.

    The problem(s)

    Going from OSM to MVTs (ex: in an mbtiles archive) requires having at least some sort of translation rule from OSM to vector tile layers and features. Your first problem will be arriving at a decision for which layers to have. It looks like there are 40-ish railway-related tags, but this may change over time. Do you want all of these to end up in one layer, or multiple layers?

    This is fundamentally incompatible with OpenMapTiles the schema since, well, you can see the schema on the website and this isn't it ;) Could the build tooling be adapted? Maybe.... But it probably won't be easy.

    The other problem is that vector tiles are designed for visualization. You NEED a schema to do visualization effectively with the current tools (ex: MapLibre Styles). You need to have specific predicates when you style based on some key. Having arbitrary key names becomes challenging.

    I suppose one option could be to generate a style skeleton programmatically, but then you're going to need to fill in styles for dozens of attributes. You can probably do this for railways, but it won't be easy. Doing this for all OSM tags is going to be impossible.

    Reframing the problem

    What is your end goal?

    If it's to visualize something about the rail network, then vector tiles are (probably) a good solution. But I'm not sure OMT is the best build tooling to make it happen. I would have a look at tilemaker instead. I've linked an example configuration because, unlike OMT's YAML approach, tilemaker is extremely flexible; you could define a railway layer dynamically with regular expressions and rules written in arbitrary Lua code to do the mapping. This sounds more aligned with your needs than OMT.

    If you are trying to do some analysis of the data, I think importing to postgres with osm2pgsql is probably a better approach.

    In both cases, you still need to decide your yourself how to map OSM ways, nodes, and relations to objects though. The OSM "schema" has no info on geometry types, so it is up to you (and the convention of mappers) to impose order.

    Sorry this isn't an easy answer, but I hope it helps!