How to generate vector tiles for offline using from OSM metadata

1 minute read | April 22, 2018

Hi everyone! Today I want to talk about generating vector tiles for offline using from OSM metadata. I’ll tell you about my journeys with them and give some links. Let’s get started.

Why did I need them?

Once, I wrote a about blog-post dowloading open street maps tiles. After release, client decided to switch application from usual tiles to vector ones. And that was the strange journey, but I want to share this expirience with you.

Why Mapsforge?

Mapsforge is an open-source solution and the client wanted to use it)

So, what should I do?

First of all, you need to dowload a file with OSM raw-data. In my case I needed the whole planet’s map (because the client wanted to generate different places from it), so I downloaded a file for the whole planet ……

A few days later…

After the file had been downloaded, I started to investigate, what I could do with it. So, this is the list of steps.

  1. Read about generation maps for Mapsforge
  2. Read about Osmosis tool and grab it
  3. Read about mapsforge map-writer
  4. Configure osmosis and mapsforge map-writer

Generation

You need to call the commands

osmosis --read-pbf planet-latest.osm.pbf --bounding-box top={top} left={left} bottom={bottom} right={right} --write-pbf map.pbf
osmosis --rb file="map.pbf" --mapfile-writer file="map.map"

Coordinates for left|bottom|right|top, you can check at tiles calculator

An hour later …

Generating of one map takes about an hour. So, just wait and you get a result.

P.S. for C# developers

There is a possibility to use .net libraries instead of

osmosis --read-pbf planet-latest.osm.pbf --bounding-box top={top} left={left} bottom={bottom} right={right} --write-pbf map.pbf

Go to OsmSharp’s repo. These guys did a great job and you can parse some_area.osm.pbf without osmosis. It’s regrettable, but I haven’t find the solution for generating vector maps in geofabrik format without mapsforge map-writer.

Conclusion

That’s all, thank you for you attention!

Leave a Comment