Integration of TileJSON with MicroJSON
Purpose
This specification outlines how to use TileJSON to integrate tiled MicroJSON data, both in json form as well as binary form. It provides examples of how TileJSON can be used to specify the tiling scheme and zoom levels for MicroJSON data and its binary equievalent. It is based on the TileJSON 3.0.0 specification, but extends it by recommending additional properties to enable integration of MicroJSON data and fit purposes of microscopy imaging. The recommendations provided here are not intrinsic to the original TileJSON specification but have been tailored to suit the needs of microscopy metadata annotation and integration with MicroJSON. However, all suggestions are designed to maintain compatibility with the original TileJSON specification.
Background of TileJSON
TileJSON is a widely-used format in mapping applications for specifying tilesets. Developed to streamline the integration of different map layers, TileJSON is essential for ensuring consistency across mapping platforms. It describes tilesets through a JSON object, detailing properties like tile URLs, zoom levels, and spatial coverage.
TileJSON for MicroJSON Object Structure
tilejson
: Specifies the version of the TileJSON spec being used. Required for all TileJSON objects.name
: The name of the tileset. Optional but recommended.description
: Provide a brief description of the tileset. Optional but recommended.version
: The version of the tileset. Optional but recommended.attribution
: A link to the data source or other attribution information, e.g. organisational origin. Optional but recommended.tiles
: Required. The URL pattern for accessing the vector tiles. Theurlbase/{zlvl}/{t}/{c}/{z}/{x}/{y}
is the recommended default naming pattern for the tiles, in this order, whereurlbase
is the base URL (e.g.http://example.com/tiles
),{zlvl}
is the zoom level,{t}
is the tileset timestamp,{c}
is the channel,{z}
is the z coordinate, and{x}
and{y}
are the x and y coordinates, respectively. If not using a timestamp, channel, or z coordinate, these can be omitted. The zoom level should always be first.minzoom
andmaxzoom
: Defines the range of zoom levels for which the tiles are available.bounds
: Optional. Specifies the geometrical bounds included in the tileset. Specified as an array of minimum four numbers in the order[minX, minY, maxX, maxY]
, but may include up to a further six numbers for a total of ten,[minT, minC, minZ, minX, minY, maxT, maxC, maxZ, maxX, maxY]
, whereminT
is the minimum tileset timestamp,minC
is the minimum channel,minZ
is the minimum z coordinate,minX
andminY
are the minimum x and y coordinates,maxT
is the maximum tileset timestamp,maxC
is the maximum channel,maxZ
is the maximum z coordinate, andmaxX
andmaxY
are the maximum x and y coordinates.center
: Optional. Indicates the center and suggested default view of the tileset. Minimum of three numbers in the order[x, y, zoom]
, but may include up to a further three numbers for a total of six,[t,c,z,x,y,zoom]
, wheret
is the tileset timestamp,c
is the channel,z
is the z coordinate,x
andy
are the x and y coordinates, andzoom
is the zoom level. Zoom level should be last.-
vector_layers
: Required. Describes each layer within the vector tiles, and has the following structure: -
id
: Required. A unique identifier for the layer. Required for each layer. fields
: Required. A list of fields (attributes) and their data types. For MicroJSON, this can either be an empty list, or a simple datatype indicator, that is either ofString
,Number
, orBool
. Complex data types, such as arrays or objects are not allowed. Required for each layer.fieldranges
: Optional. A dictionary of field names and their ranges. For example,{"label": [0,100], "channel": [0,10]}
. Optional.fieldenums
: Optional. A dictionary of field names and their possible values. For example,{"plate": ["A1", "A2", "B1", "B2"], "image": ["image1.tif", "image2.tif", "image3.tif"]}
. Optional.fielddescriptions
: Optional. A dictionary of field names and their descriptions. For example,{"plate": "Well plate identifier", "image": "Image filename", "label": "Label identifier", "channel": "Channel identifier"}
. Optional.description
: Optional. A brief description of the layer.minzoom
andmaxzoom
: Optional. The range of zoom levels at which the layer is visible.fillzoom
: Optional. An integer specifying the zoom level from which to generate overzoomed tiles.legend
: Optional. Contains a legend to be displayed with the tileset.
The following fields of TileJSON may be used if the use case requires it, and are included here for completeness:
scheme
: The tiling scheme of the tileset.grids
: The URL pattern for accessing grid data.data
: Optional. The URL pattern for accessing data. Used for GeoJSON originally, which in this specification is replaced by MicroJSON and used in thetiles
field.template
: Optional. Contains a mustache template to be used to format data from grids for interaction.
Pydantic Model for TileJSON for MicroJSON
TileJSON
Bases: RootModel
The root object of a TileJSON file.
Source code in src/microjson/tilemodel.py
78 79 80 |
|
TileModel
Bases: BaseModel
A TileJSON object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tilejson
|
str
|
The TileJSON version. |
required |
tiles
|
List[Union[Path, AnyUrl]]
|
The list of tile URLs. |
required |
name
|
Optional[str]
|
The name of the tileset. |
required |
description
|
Optional[str]
|
The description of the tileset. |
required |
version
|
Optional[str]
|
The version of the tileset. |
required |
attribution
|
Optional[str]
|
The attribution of the tileset. |
required |
template
|
Optional[str]
|
The template of the tileset. |
required |
legend
|
Optional[str]
|
The legend of the tileset. |
required |
scheme
|
Optional[str]
|
The scheme of the tileset. |
required |
grids
|
Optional[Union[Path, AnyUrl]]
|
The grids of the tileset. |
required |
data
|
Optional[Union[Path, AnyUrl]]
|
The data of the tileset. |
required |
minzoom
|
Optional[int]
|
The minimum zoom level of the tileset. |
required |
maxzoom
|
Optional[int]
|
The maximum zoom level of the tileset. |
required |
bounds
|
Optional[conlist(float, min_length=4, max_length=10)]
|
The bounds of the tileset. |
required |
center
|
Optional[conlist(float, min_length=3, max_length=6)]
|
The center of the tileset. |
required |
fillzoom
|
Optional[int]
|
The fill zoom level of the tileset. |
required |
vector_layers
|
List[TileLayer]
|
The vector layers of the tileset. |
required |
Source code in src/microjson/tilemodel.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
TileLayer
Bases: BaseModel
A vector layer in a TileJSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
The unique identifier for the layer. |
required |
fields
|
Union[None, Dict[str, str]]
|
The fields in the layer. |
required |
minzoom
|
Optional[int]
|
The minimum zoom level for the layer. |
required |
maxzoom
|
Optional[int]
|
The maximum zoom level for the layer. |
required |
description
|
Optional[str]
|
A description of the layer. |
required |
fieldranges
|
Optional[Dict[str, List[Union[int, float, str]]]]
|
The ranges of the fields. |
required |
fieldenums
|
Optional[Dict[str, List[str]]
|
The enums of the fields. |
required |
fielddescriptions
|
Optional[Dict[str, str]]
|
The descriptions of the fields. |
required |
Source code in src/microjson/tilemodel.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
General tiling requirements
This specification is designed to be compatible with the Vector Tile Specification and the TileJSON 3.0.0 specification. The Vector Tile Specification specifically requires vector tiles to be agnostic of the global coordinate system, and thus followingly each tile has a relative coordinate system, which instead is defined in the TileJSON. Our ambitions in general are to follow the same principles.
One difference is that we here recommend that the file ending for binary tiles is .pbf
instead of .mvt
to avoid confusion with the Mapbox Vector Tile format. The binary tiles should be encoded in the Protobuf format as defined in the Vector Tile Specification.
MicroJSON2vt
The MicroJSON2vt module is a helper module that can be used to convert MicroJSON objects to vector tiles. It is designed to be used in conjunction with the TileJSON for MicroJSON specification, and can be used to generate vector tiles from MicroJSON objects. The module is designed to be compatible with the Vector Tile Specification, and can be used to generate vector tiles in the intermediate vector tile JSON-format, which then, using vt2pbf
may be transformed into protobuf. The module is included in the microjson
package, and its wrapper function can be imported using the following code:
from microjson import microjson2vt
The module:
MicroJsonVt class, which is the main class for generating vector tiles from MicroJSON data
Source code in src/microjson/microjson2vt/microjson2vt.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
__init__(data, options, log_level=logging.INFO)
Constructor for MicroJsonVt class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
dict
|
The data to be converted to vector tiles |
required |
options
|
dict
|
The options to be used for generating vector tiles |
required |
log_level
|
int
|
The logging level to be used |
INFO
|
Source code in src/microjson/microjson2vt/microjson2vt.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
split_tile(features, z, x, y, cz=None, cx=None, cy=None)
Splits features from a parent tile to sub-tiles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features
|
list
|
The features to be split |
required |
z
|
int
|
The zoom level of the parent tile |
required |
x
|
int
|
The x coordinate of the parent tile |
required |
y
|
int
|
The y coordinate of the parent tile |
required |
cz
|
int
|
The zoom level of the target tile |
None
|
cx
|
int
|
The x coordinate of the target tile |
None
|
cy
|
int
|
The y coordinate of the target tile |
None
|
Source code in src/microjson/microjson2vt/microjson2vt.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
TileHandler module
The TileHandler module is a helper module that can be used to generate binary tiles from a large MicroJSON file, my utilizing both microjson2vt and vt2pbf.
TileHandler
Class to handle the generation of tiles from MicroJSON data
Source code in src/microjson/tilecut.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
__init__(tileobj, pbf=False)
Initialize the TileHandler with a TileJSON configuration and optional PBF flag
Args: tileobj (TileModel): TileJSON configuration pbf (bool): Flag to indicate whether to encode the tiles in PBF
Source code in src/microjson/tilecut.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
microjson2tiles(microjson_data_path, validate=False)
Generate tiles in form of JSON or PBF files from MicroJSON data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
microjson_data_path
|
Union[str, Path]
|
Path to the MicroJSON data file |
required |
validate
|
bool
|
Flag to indicate whether to validate the MicroJSON data |
False
|
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: List of paths to the generated tiles |
Source code in src/microjson/tilecut.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
getbounds(microjson_file)
Get the max and min bounds for coordinates of the MicroJSON file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
microjson_file
|
str
|
Path to the MicroJSON file |
required |
Returns:
Type | Description |
---|---|
List[float]
|
List[float]: List of the bounds [minx, miny, maxx, maxy] |
Source code in src/microjson/tilecut.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
TileJSON for MicroJSON example with Vector Layers
The below example illustrates a TileJSON for a MicroJSON tileset multiple layers of detail. The tileset has a single vector layer, image_layer
id of vector_layers
, which contains a single vector layer describing images. The fields
property of the this layer specifies the attributes of the layer, including the data types of the attributes. The tiles
property specifies the URL pattern for accessing the vector tiles, which in this case is a 2D data set (no channels, time or z-axis) with zoom level.
This file is located in the examples/tiles
directory of the repository, and is named tiled_example.json
. It has a corresponding MicroJSON file for each tile, located in the examples/tiles/tiled_example
directory of the repository. The MicroJSON files are organized according to the tiling scheme, with the directory structure zlvl/x/y.json
where zlvl
is the zoom level, x
is the x coordinate, and y
is the y coordinate. The MicroJSON files contain the MicroJSON objects for the corresponding tiles, and are named according to the tiling scheme. For example, the MicroJSON object for the tile at zoom level 1, tile at (0,1) in the tiling scheme is located at examples/tiles/tiled_example/1/0/1.json
. Examples for MicroJSON objects at zoom levels 0, 1, and 2 are provided below.
{
{
"tilejson": "3.0.0",
"name": "2D Data Example",
"description": "A tileset showing 2D data with multiple layers of detail.",
"version": "1.0.0",
"attribution": "<a href='http://example.com'>Example</a>",
"tiles": [
"http://example.com/tiled_example/{zlvl}/{x}/{y}.json"
],
"minzoom": 0,
"maxzoom": 10,
"bounds": [0, 0, 24000, 24000],
"center": [12000, 12000, 0],
"vector_layers": [
{
"id": "Tile_layer",
"description": "Tile layer",
"minzoom": 0,
"maxzoom": 10,
"fields": {
"plate": "String",
"image": "String",
"label": "Number",
"channel": "Number"
}
}
],
"fillzoom": 3
}
Tiled binary TileJSON
In addition to json format, tiles may be encoded in a binary protobuf format. Below follows a similar example to the one above, but with binary tiles. The tiles
property specifies the URL pattern for accessing the binary tiles, which in this case is a 2D data set (no channels, time or z-axis) with zoom level. The fillzoom
property specifies the zoom level from which to generate overzoomed tiles, which in this case starts at level 3, after the last specified layer.
{
"tilejson": "3.0.0",
"name": "2D Data Example",
"description": "A tileset showing 2D data with multiple layers of detail.",
"version": "1.0.0",
"attribution": "<a href='http://example.com'>Example</a>",
"tiles": [
"http://example.com/tiled_example/{zlvl}/{x}/{y}.pbf"
],
"minzoom": 0,
"maxzoom": 10,
"bounds": [0, 0, 24000, 24000],
"center": [12000, 12000, 0],
"vector_layers": [
{
"id": "tile_layer",
"description": "Tile layer",
"minzoom": 0,
"maxzoom": 10,
"fields": {
"plate": "String",
"image": "String",
"label": "Number",
"channel": "Number",
},
"fieldranges": {
"label": [0,100],
"channel": [0,10]
},
"fieldenums": {
"plate": ["A1", "A2", "B1", "B2"],
"image": ["image1.tif", "image2.tif", "image3.tif"],
}
"fielddescriptions": {
"plate": "Well plate identifier",
"image": "Image filename",
"label": "Label identifier",
"channel": "Channel identifier"
}
}
],
"fillzoom": 3
}
Tiled binary example
The examples folder contains an example of how to generate binary tiles from one large MicroJSON file. It uses a helper module that generates a large random polygon grid, as could be expected in an imaging setting, using typical imaging coordinates. It is also included below for reference.
Example of creating binary tiles from a large MicroJSON file
Source code in src/microjson/examples/tiling.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
Tiled MicroJSON Example
Level 0
The following is an example of a MicroJSON object at zoom level 0, tile at (0,0) in the tiling scheme. Example URL: http://example.com/tiles/0/0/0.json
{
"tilejson": "3.0.0",
"name": "2D Data Example",
"description": "A tileset showing 2D data with multiple layers of detail.",
"version": "1.0.0",
"attribution": "<a href='http://example.com'>Example</a>",
"tiles": [
"http://example.com/tiled_example/{zlvl}/{x}/{y}.json"
],
"minzoom": 0,
"maxzoom": 10,
"bounds": [0, 0, 24000, 24000],
"center": [12000, 12000, 0],
"format": "json",
"vector_layers": [
{
"id": "image_layer",
"description": "Image layer",
"minzoom": 0,
"maxzoom": 10,
"fields": {
"plate": "String",
"image": "String",
"label": "Number",
"channel": "Number"
}
}
],
"fillzoom": 3
}
Level 1
The following is an example of a MicroJSON object at zoom level 1, tile at (0,1) in the tiling scheme. Example URL: http://example.com/tiles/1/0/1.json
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
0,
10000
],
[
10000,
10000
],
[
10000,
20000
],
[
0,
20000
],
[
0,
10000
]
]
]
},
"properties": {
"label": 3
}
}
],
"multiscale": {
"axes": [
{
"name": "x",
"type": "space",
"unit": "micrometer",
"description": "x-axis"
},
{
"name": "y",
"type": "space",
"unit": "micrometer",
"description": "y-axis"
}
]
},
"properties": {
"plate": "label",
"image": "x00_y01_p01_c1.ome.tif",
"channel": 1.0
}
}
Level 2
The following is an example of a MicroJSON object at zoom level 2, tile at (1,1) in the tiling scheme. Example URL: http://example.com/tiles/2/1/3.json
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
5000,
15000
],
[
10000,
15000
],
[
10000,
20000
],
[
5000,
20000
],
[
5000,
15000
]
]
]
},
"properties": {
"label": 13
}
}
],
"multiscale": {
"axes": [
{
"name": "x",
"type": "space",
"unit": "micrometer",
"description": "x-axis"
},
{
"name": "y",
"type": "space",
"unit": "micrometer",
"description": "y-axis"
}
]
},
"properties": {
"plate": "label",
"image": "x00_y01_p01_c1.ome.tif",
"channel": 1.0
}
}