Producing Vector Tiles

From Maria GDK Wiki
Jump to navigation Jump to search

The FME and OGR translation processes described in this documentation produce intermediary m6m files. These must be indexed and converted to datasets or vector tiles before they can be used in Maria GDK. Conversion to vector tiles is done with the command line tool ToVectorTileset.exe, which is developed by Teleplan Globe. The completed Vector Tiles files can subsequently be analyzed with the command line tool ExtractMapInfo.exe.

Building Vector Tiles

Use ToVectorTileset.exe as follows:

ToVectorTileset.exe <source folder> <target filename> <-level n> [-recursive]
    [-attribs "a1,a2,..,an"][-zip][-fastclip]
    [-lborder <value>][-aborder <value>]
    [-pborder <value>] [-namedborder<i> <layer name> <value>]
    [-layers <layer spec>]

Note that the target folder must exist prior to execution.

  • -recursive goes through sub-folders looking for m6m source files.
  • -zip compresses database blob data using zlib compression
  • -attribs is used if only specific feature attributes should be included. Only including the required attributes can substantially reduce target filesize.
  • -[l|a|p|named]border parameters create a buffer around the indicated features. This is done to prevent clipping of any larger graphical elements of the styling when the features are near tile borders. -lborder, -aborder, -pborder define defaults for lines, areas and points, respectively. -namedborder override these, using the name of a layer. The layer names can contain wildcards ? and *. Border values are specified in tile coordinates, where 4096 is a full tile.

Example:

ToVectorTileset.exe "c:\sourcemaps\lvl10" "c:\targetmaps\mymap.vtiles.sqlite" -level 10
-attribs "name,type,geotype,date" 
-pborder 512 -namedborder1 byg* 0 -nameborder2 *light* 4096
-layers "-BoundingBox"

Level

The level parameter is a number that describes the tile level (also called "zoom level") and roughly corresponds to a map scale where level 0 covers the whole earth at 1:256M and each level means scale/2, see table.

Level Scale Comment
0 1:256M Whole earth between 85N and 85S
1 1:128M 256M/2level
2-18 1:64M-1:1000 Level 18 roughly corresponds to 1:1000

The level parameter should be selected so that it matches typical display scales for the map data. If the same map data is to be used on several levels, it is possible to run multiple conversions with different level values in order to produce tilings for different levels.

Note that the vector tile files are sqlite databases and can be inspected using free applications such as DB Browser for Sqlite or the command line tool sqlite3.exe.

To determine the average tile size across all levels, use this SQL-statement:

select avg(length(tile_data)) from tiles;

As a rule of thumb, average tile size should range between 1000 bytes and 50000 bytes and max tile size should be less than 1MB. In the end, the tile level must be tuned based on experience and intended map data scales along with map previews. Increasing the level will tend to increase total data size while decreasing size per tile.

Layers

Layer spec is a comma-separated list of layers to include or exclude. If first element in layer spec is preceeded by -, all layers in list will be excluded from conversion. The layers correspond to the file names (without extension) of the m6m source files. The layer spec can contain wildcards ? and *.

Merging

ToVectorTileset.exe -merge <target filename> <source filename>

Merge tiles from database given by source filename into database given by target filename. Overlapped tiles are supported. Blob-compression is used only if target database uses blob-compression.

Make boundaries

Generating boundaries in the database after merging is neccessary for it to work properly.

ToVectorTileset.exe -makebounds <db filename>

Compacting

To compress all tiles in the database using zlib, use:

ToVectorTileset.exe -compact <db filename>

Depending on data, this should compress the database to approximately 0.5-0.7 times the original size. Note that vector service shipped with MARIA GDK 2.1 or newer is required. Also note that vacuuming and unused tile data removal is also performed as part of the compression.

Analyzing Vector Tiles

ExtractMapInfo.exe can analyze a Vector Tiles file and produce an XML report. This report contains statistics on zoom levels, tilesizes and features, as well as a full description of feature types (layers) and attributes contained in the Vector Tiles file. Use as follows:

extractmapinfo.exe <srcdir | srcfile> <report file name>
[-progress] [-json | -jsonpretty] [-maxcomplete <n>] [-maxsample <n>] [-maxanalyze <n>]

Example:

extractmapinfo.exe "c:\data\naturalearth\borders.vtiles.sqlite" "c:\data\naturalearth\borders.report.xml"