This article describes how to generate tilestats and how to add them to your vector MBTiles.
Tilestats
Tilestats or tile statistics, also known as geostats or layer statistics, encapsulate comprehensive information regarding the layers within your tileset, offering insights into all attributes and geometry types associated with each layer. Tilestats also provide helpful information about available language mutations.
You can find more about tilestats and how they enhance user experience in Customize in this article: Tilestats.
Tilestats tool
MapTiler provides the Tilestats Tool, an utility for generating tile statistics. It's an open-source project with its own GitHub repository. The Tilestats Tool generates tilestats and provides their seamless integration into the metadata of MBTiles. Please,make sure that you use the version 2.0.0 or higher.
How to install
To utilize the Tilestats Tool, you must first install it. Detailed installation instructions can be found at the Installation section of README. Ensure you have the following prerequisites:
- Git
- npm (version greater than 16)
The installation process involves the following steps:
git clone https://github.com/maptiler/tilestats.git
cd tilestats
npm i
./bin/tilestats-generate --help
How to generate tilestats into JSON file
The Tilestats Tool empowers users to generate tilestats for their MBTiles and save them in standalone JSON files. Execute the following command to achieve this:
tilestats/bin/tilestats-generate path/to/your.mbtiles > tilestats.json
This command extracts tile statistics from your MBTiles and stores them in a JSON file, allowing for easy access and analysis of the generated tilestats. An example of such a JSON file and its structure is at the end of this article.
How to generate tilestats into MBTiles metadata
If your objective is to generate tilestats and seamlessly integrate them into the metadata of your MBTiles, employ the "--into-md" option as follows:
tilestats/bin/tilestats-generate path/to/your.mbtiles --into-md
By using this option, your tilestats are directly added to the MBTiles metadata, making them available for Customize .
Advanced usage
For users seeking more advanced configuration options and capabilities, the Tilestats Tool offers a range of advanced features. To explore these options, execute:
tilestats/bin/tilestats-generate --help
Additionally, consult the tool's README on its GitHub page for comprehensive guidance and detailed explanations of its advanced functionalities.
Tilestats example
"tilestats":
{
"languages": ["de","en","fr","it"],
"layerCount": 3,
"layers": [
{
"layer": "place",
"attributeCount": 4,
"attributes": [
{
"attribute": "name",
"type": "String"
},
{
"attribute": "class",
"type": "String",
"values": ["city","town","village"]
},
{
"attribute": "population",
"type": "Number",
"min": 12,
"max": 5213267
},
{
"attribute": "capital",
"type": "Boolean",
"values": [true,false]
}
],
"geometry": "Point"
},
{
"layer": "transporation",
"attributeCount": 3,
"attributes": [
{
"attribute": "ref",
"type": "String"
},
{
"attribute": "type",
"type": "String",
"values": ["cycleway","ferry","motorway","rail"]
},
{
"attribute": "level",
"type": "Number",
"values": [0,1,2,3,4]
}
],
"geometry": "LineString"
},
{
"layer": "water",
"attributeCount": 1,
"attributes": [
{
"attribute": "class",
"type": "String",
"values": ["lake","ocean","river"]
}
],
"geometry": ["LineString","Polygon"]
},
]
}
This tilestats example for the place layer reveals the following technical details:
- Number of layers: 3
- Layer name: "place"
- Geometry type: "Point"
- Attributes: Four attributes are associated with this layer.
- "name" of type String
- "class" of type String with a predefined set of values
- "population" of type Number with the minimum and maximum value
- "capital" of type Boolean
- Layer name: "transportation"
- Geometry type: "LineString"
- Attributes: Four attributes are associated with this layer.
- "ref" of type String
- "type" of type String with a predefined set of values
- "level" of type Number with a predefined set of values
- Layer name: "water"
- Geometry type: "LineString" or "Polygon"
- Attributes: One attribute is associated with this layer.
- "type" of type String with predefined set of values
- Layer name: "place"
-
Available languages - language codes according to ISO 639-1 codes:
- "de" - German
- "en" - English
- "es" - Spanish
- "fr" - French
- "it" - Italian
Tilestats structure
{ // The list of all languages in the vector data "languages": Array<string> // The number of layers in the source data (max. 1000) "layerCount": Number, // An array of details about the first 100 layers "layers": [ { // The name of this layer "layer": String, // The geometry type(s) in this layer "geometry": String | Array<String>, // The number of unique attributes in this layer (max. 1000) "attributeCount": Number // An array of details about the first 100 attributes in this layer "attributes": [ { // The name of this attribute "attribute": String, // The type of this attribute's values "type": String, // More info below ... // An array of this attribute's if less than VALUES LIMIT unique values "values": [ // ... ], // If there are more number values than VALUES LIMIT, the following // numeric stats will be reported instead "min": Number, "max": Number } // ... ] } // ... ] }
Conclusion
MapTiler provides an open-source tool to generate tilestats into your own vector MBTiles. Tilestats greatly improve user experience when creating a custom style for your own tileset in Customize.
Useful links
Tilestats
How to make custom map design in MapTiler Cloud
Global map settings
Layer styling
Layer filters
Comments
0 comments
Please sign in to leave a comment.