Marble/OSMVectorTileCreation: Difference between revisions

From KDE TechBase
mNo edit summary
 
(7 intermediate revisions by 2 users not shown)
Line 4: Line 4:


As an example we'd like to render tiles for tile level 13, 15 and 17 of San Francisco.  
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:
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
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
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 osmfilter ===
=== 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:
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:
Line 19: Line 19:
gcc -O3 -o osmconvert osmconvert.c -lz
gcc -O3 -o osmconvert osmconvert.c -lz
sudo mv osmconvert /usr/local/bin
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
</source>
</source>


Line 29: Line 25:
<source lang="bash">
<source lang="bash">
osmconvert -h
osmconvert -h
</source>
and also
<source lang="bash">
osmfilter -h
</source>
</source>
should output usage instructions.
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 ===
=== 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
Now our tool is needed. In a shell, go to the marble build directory and then
<source lang="bash">
<source lang="bash">
cd tools/vectortilecreator
cd tools/vectorosm-tilecreator
</source>
</source>
now running
now running
<source lang="bash">
<source lang="bash">
./vectortilecreator.py -h
./marble-vectorosm-tilecreator -h
</source>
</source>
should give usage instructions.
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 current 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
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.
-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
=== Full Example ===
* It parses the region file to read which file to work on and which boundaries it has
If you follow the steps above, the final tile creation run after installing the required tools will look like this:
* 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? ===
<source lang="bash">
Now you might have created your own tiles already. But what are possible pitfalls if your own tile data doesn't show up?
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.
</source>


* 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
=== Smaller Regions ===
* Check the bounding rect definition inside the text file. It should specify the bottom left and top right corner of your area.
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:
<source lang="bash">
osmconvert --complex-ways --complete-ways -b=8.3735,49.0016,8.4409,49.0261 -o=smallregion.pbf largeregion.pbf
./marble-vectorosm-tilecreator smallregion.pbf
</source>
The four numbers of the bounding box passed with the -b=... parameter can be obtained from the [https://www.openstreetmap.org/export#map=15/49.0139/8.4072 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:
<source lang="bash">
$ 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
[...]
</source>

Latest revision as of 19:38, 8 January 2017

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
[...]