Marble/OSMVectorTileCreation: Difference between revisions

From KDE TechBase
No edit summary
Line 63: Line 63:


* Check the directory ~/.local/share/marble/maps/earth/vectorosm . It should have subdirectories of the levels that you created. Since the vector tiles are created as .osm.zip files you can zgrep their content in order to look for features that should be inside the data you wanted to create
* Check the directory ~/.local/share/marble/maps/earth/vectorosm . It should have subdirectories of the levels that you created. Since the vector tiles are created as .osm.zip files you can zgrep their content in order to look for features that should be inside the data you wanted to create
* Check the bounding rect definition inside the text file. It should specify the lowerbottom corner and uppertop corner of your area.
* Check the bounding rect definition inside the text file. It should specify the bottom left and top right corner of your area.

Revision as of 15:41, 23 October 2015

OSM Vector Tiles

Creating tiles from a pbf file

As an example we'd like to render tiles for tile level 13, 15 and 17 of San Francisco. First you need the osm.pbf file for that region. In our case we download that from:

http://download.geofabrik.de/north-america/us/california.html

or to be more specifically: http://download.geofabrik.de/north-america/us/california-latest.osm.pbf

Creating the tools - osmconvert and osmfilter

Now we need the tools for conversion and filtering the pbf file into tiles. In order to compile the tools you should have zlib installed on your system (e.g. via sudo apt-get install zlib1g-dev). Then run:

cd /tmp
wget http://m.m.i24.cc/osmconvert.c
gcc -O3 -o osmconvert osmconvert.c -lz
sudo mv osmconvert /usr/local/bin
and pretty much the same for osmfilter
wget http://m.m.i24.cc/osmfilter.c
gcc -O3 -o osmfilter osmfilter.c
sudo mv osmfilter /usr/local/bin

if that works, running

osmconvert -h

and also

osmfilter -h

should output usage instructions.

Running the VectorTileCreator

Now our tool is needed. You need python version 2 or 3 to be installed. In a shell, go to the marble sources directory and then

cd tools/vectortilecreator

now running

./vectortilecreator.py -h

should give usage instructions.

The tile cutter tool works as follows: You call it with a region file as parameter (or several). It will generate tiles in the currenty directory unless you use the -d option: For example -d ~/.local/share/marble/maps/earth/vectorosm is what you want for local tiles. By default it will generate tiles for zoom levels 13, 15, 17. You can overwrite that using the -z switch -z 13 15.

This would allow to exclude e.g. level 17 (which can take between < 1 sec for small tiles but > 10 secs for large tiles depending on the input size). Once called, the script does the following

  • It parses the region file to read which file to work on and which boundaries it has
  • To speed things up, it then creates another file with only the given boundaries inside (e.g. if you pass california-latest.osm.pbf and work on san francisco it will create a temporary file that has only san francisco inside)
  • Afterwards it iterates over the zoom levels passed. For each level it calculates the tiles that are inside the boundaries.

Then it calls osmconvert for each tile to generate the tile

  • If it also finds a file levels/$ZOOM.level it will call osmfilter afterwards
  • And finally the result is zipped

What should I do if this doesn't seem to work for my own data?

Now you might have created your own tiles already. But what are possible pitfalls if your own tile data doesn't show up?

  • Check the directory ~/.local/share/marble/maps/earth/vectorosm . It should have subdirectories of the levels that you created. Since the vector tiles are created as .osm.zip files you can zgrep their content in order to look for features that should be inside the data you wanted to create
  • Check the bounding rect definition inside the text file. It should specify the bottom left and top right corner of your area.