Marble/OSMVectorTileCreation

From KDE TechBase
Revision as of 19:38, 8 January 2017 by Earthwings (talk | contribs) (→‎Resolving errors)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 get it from:

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

where we locate the link to the pbf file as http://download.geofabrik.de/north-america/us/california-latest.osm.pbf

Creating the tools - osmconvert and marble-vectorosm-tilecreator

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

if that works, running

osmconvert -h

should output usage instructions.

Please compile Marble from source code as well as described in https://marble.kde.org/sources.php and make sure to compile the development version (master branch). Pass the option -DBUILD_MARBLE_TOOLS=TRUE to cmake in order to compile all Marble tools.

Running the VectorTileCreator

Now our tool is needed. In a shell, go to the marble build directory and then

cd tools/vectorosm-tilecreator

now running

./marble-vectorosm-tilecreator -h

should give usage instructions.

The tile cutter tool works as follows: You call it with a link to an osm .pbf file as parameter.

The tool will generate tiles for zoom levels 11, 13, 15 and 17 by default. You can overwrite that using the -z switch, e.g. -z 13 15.

Full Example

If you follow the steps above, the final tile creation run after installing the required tools will look like this:

cd ~/marble/build/
cd tools/vectorosm-tilecreator
./marble-vectorosm-tilecreator http://download.geofabrik.de/north-america/us/california-latest.osm.pbf
 [========================================>]  100%  734.4/734.4 MB  Downloading california-latest.osm.pbf
 [========================================>]  100%  0.0/0.0 MB  Downloading california.poly
 [========================================>]  100%  osm cache tiles complete.
 [========================================>]  100%  landmass cache tiles complete.                    
 [========================================>]  100%  Vector OSM tiles complete.

Smaller Regions

For large countries the tile creation can take several hours or even days. If you're just interested in a certain region (say, a city), you can preprocess the pbf and extract the region you're interested in. Use osmconvert for that like this:

osmconvert --complex-ways --complete-ways -b=8.3735,49.0016,8.4409,49.0261 -o=smallregion.pbf largeregion.pbf
./marble-vectorosm-tilecreator smallregion.pbf

The four numbers of the bounding box passed with the -b=... parameter can be obtained from the OSM export tool in the order left, bottom, right, top.

Resolving errors

If you get an error message after the tile creation downloaded the cache files, a likely cause is that you are missing the shapelib (libshp) dependency. It's an optional dependency of Marble, but a required dependency for vector tile creation.

To check whether shapelib (libshp) was found, examine the first few lines of cmake. They should contain a list of dependencies needed, with a note if it was found or not. You might get a warning that shapelib (libshp) is missing. Installing it and recompiling Marble will then fix the error.

In the example cmake output below, the optional packages libgps and libwlocate are missing, but shapelib (libshp) is found after installing it using the package manager of the Linux distribution:

$ cmake -DBUILD_MARBLE_TOOLS=TRUE ../marble
-- Could NOT find libgps (missing:  LIBGPS_INCLUDE_DIR LIBGPS_LIBRARIES) 
-- Could NOT find libwlocate (missing:  LIBWLOCATE_INCLUDE_DIR LIBWLOCATE_LIBRARIES) 
-- 
-- The following OPTIONAL packages have been found:
[...]
 * libshp , reading and writing of ESRI Shapefiles (.shp) , <http://shapelib.maptools.org/>
   reading and displaying .shp files
[...]