I have a question about the MapViewer tile storage scheme.
I checked cache folder of my tileLayer and noticed that in some zooms there are just tile files with x and y numbers (x_y.png). But in higher zooms (in my case zoom 5 and above) mapviewer creates folders and then put the files inside those folders. In fact, It tessellates the area in each zoom and then put tiles in each tessellation. What I want to is when (in what condition) mapviewer does so? and what is the algorithm that it uses?
On file system, each tile layer has its own storage root directory, which is under $DEFAULT_TILE_STORAGE_ROOT/[tile_layer_name]. Under the tile layer storage root, each zoom level has its own directory, with the zoom level number as its name, served as zoom level's root directory. Tiles are stored in a tree-like directory structure with leaf nodes contain only tile image files. Non-leaf nodes contain only directories. Mesh code is used to name these directories and tile names.
Tile mesh code is represented by X (horizontal) and Y (vertical) integer arrays, in a form of [meshX0, meshX1, meshX2, … meshXn] and [meshY0, meshY1, meshY2, … meshYn]. At each zoom level, the length for the X and Y mesh code array is always the same ( by taking the maximum of the two). Different zoom level may have different length, and the longer the mesh code, the more tile images the zoom level contains.
For a tile with mesh code of [meshX0, meshX1, meshX2, … meshXn] and [meshY0, meshY1, meshY2, … meshYn], its storage location is at: $DEFAULT_TILE_STORAGE_ROOT/[tile_layer_name]/[zoom_level]/[meshX0]_[meshY0]/ [meshX1]_[meshY1]/ [meshX2]_[meshY2]/…/ [meshXn]_[meshYn].png.
For example, a tile of tile layer MVDEMO.DEMO_MAP at zoom level 10, with X mesh code of [1, 12, 11] and Y mesh code of [3, 12, 9] is stored at: /scratch/map_cache/MVDEMO.DEMO_MAP/10/1_3/12_12/11_9.png
Tile mesh code is intended to be used internally by MapViewer server to determine the location of the tile image file on a file system.
A tile's location in a map coordinate system contains a tile's (x, y) coordinates and is first calculated by the client using the following formula and send the request to MapViewer server; MapViwer server then converts it into mesh code to fetch the tile and respond the client's request.
tileIndexX = (tileMinX–CoordinateSystem.minX) / tileWidth;
tileIndexY = (tileMinY–CoordinateSystem.minY) / tileHeight;
Creating directory tree for storing tile images is for file retrieval optimization. When the number of tile images is small for a given zoom level, all tiles may be stored in its root directory. But when the number gets to millions or even larger, storing them in sub-directories has benefit.
First, let's look at how many tiles in a zoom level. It can be evaluated using:
maxMeshCodeX = coordinateSystem.width/tileWidth;
maxMeshCodeY = coordinateSystem.height/tileHeight;
total_tiles = maxMeshCodeX* maxMeshCodeY;
Then a constant TILING_FACTOR needs to be introduced before determining the depth of the directory tree for a given zoom level's storage. When taking a default value of 20, then at each level in the storage tree, there will be no more than 400 (20 x 20) sub-directories or tile images stored. The mesh code length for X equals to logarithm of maxMeshCodeX with base 20.
This is more like math homework in the high school, and I'll give you some two examples, but leave the algorithm to you to solve.