1 Reply Latest reply on Aug 29, 2013 2:44 PM by Honglei Zhu-Oracle

    Chache Tiles Structure on Disk

    Farid Cher

      Hi all,

      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?

      Thank you.

        • 1. Re: Chache Tiles Structure on Disk
          Honglei Zhu-Oracle

          Here is a note and hope it answers your quesiton:

          Tile Mesh Code and File Storage Structure

          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

          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;

          Directory Tree Depth (Mesh Code Length)

          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.

          From Tile (x,y) Coordinates to Mesh Code

          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.

          1. Given that TILING_FACTOR is 20, for zoom level 6, mesh code length is 4, tile coordinate (x,Y)=(6063, 7403), then its mesh code is x=[0,15,3,3], y=[0,18,10,3], and the tile is stored at:[tile_layer_name]\6\0_0\15_18\3_10\3_3.png
          2. Look at it from a different perspective by changing TILING_FACTOR to 10, lets say mesh code length becomes 5, zoom level and tile coordinate stay the same, then its mesh code is x=[0, 6, 0, 6, 3], y=[0,7,4,0,3], and the tile is stored at: [tile_layer_name]\6\0_0\6_7\0_4\6_0\3_3.png