MS RFC 122:MapCache多sqlite缓存覆盖率分析工具

日期

2018-07-26

作者

杰罗姆·布伊

版本

MAPCACHE 1.8

1。动机

mapcache用户可能希望脱机使用覆盖给定地理区域的mapcache缓存的一部分。为此,他们需要从现有缓存中标识相关文件,检查这些文件中是否缺少磁贴(如有必要,可能会播种丢失的部分),并提取这些文件以构建所请求区域的新缓存。

本RFC中描述的工具名为 mapcache_detail ,帮助用户进行其中一些活动。它适用于多个SQLite缓存,其中一个文件可能包含数千个切片。它能够:

  • 确定需要缓存中的哪些sqlite文件覆盖给定缩放级别范围内的给定地理区域;

  • 计算覆盖区域所需的瓷砖数量以及每个文件中已经存在的瓷砖数量,给出文件级别、缩放级别和全局级别的覆盖率;

  • 估计丢失的图块的数据大小,这些图块需要下载以完全覆盖请求的区域,再次覆盖文件级别、缩放级别和全局级别。

mapcache_detail 采用使用MapCache库的独立CLI可执行文件的形式。它被提议作为对MapCache项目的一个简单贡献,在 contrib/mapcache_detail/ 文件夹,由于其特定用途(仅处理SQLite缓存)。

2。支持的sqlite缓存

这个 mapcache_detail 工具支持:

三。功能概述

根据初始高速缓存配置、请求的地理区域和缩放级别, mapcache_detail 找出哪些SQLite文件与所述请求的区域匹配。然后,对于每个SQLite文件,该工具测量:

  • 文件大小和文件中实际存在的磁贴数,无论它们对区域覆盖率的贡献如何;这些度量用于估计磁贴的平均大小和完全覆盖请求区域的缓存大小。

  • 文件中实际存在并需要覆盖请求区域的瓷砖数量。

  • 覆盖请求区域所需的瓷砖数量,是否存在于文件中。最后两个度量用于确定缓存相对于请求区域的覆盖率。

然后会提供一个报告,其中包含每个sqlite文件的所有度量,并在缩放级别和全局级别进行组合。本报告采用标准输出的JSON数据形式。

3.1输入参数

mapcache_detail 需要两种参数:

  • 缓存描述,由以下部分组成:

    • 初始缓存的mapcache配置文件,

    • 层、SRS和尺寸(如需要)

    • 用于计算矩形区域中瓷砖数的SQL查询。如果使用mapcache的默认设置构建了sqlite缓存,则不需要使用此缓存。

  • 区域描述,由以下部分组成:

    • 最低和最高要求的缩放级别,

    • 请求区域的几何图形,以以下格式之一提供:

      • xmin, ymin, xmax, ymax 定义区域的矩形

      • 以支持的文件格式之一指定任意形状区域的矢量文件。 OGR/GDAL 类库。

联机帮助提供了设置输入参数的可用选项的说明。这些选项类似于 mapcache_seeder's options

$ mapcache_detail --help

Usage:   mapcache_detail <options>

    -h | --help
                Display this message and exit
    -c | --config <value>
                Configuration file (/path/to/mapcache.xml)
    -D | --dimension <value>
                Set the value of a dimension: format DIMENSIONNAME=VALUE.
                Can be used multiple times for multiple dimensions
    -t | --tileset <value>
                Tileset to analyze
    -g | --grid <value>
                Grid to analyze
    -e | --extent <value>
                Extent to analyze: format minx,miny,maxx,maxy. Cannot be
                used with --ogr-datasource.
    -d | --ogr-datasource
                OGR data source to get features from. Cannot be used with
                –extent.
    -l | --ogr-layer
                OGR layer inside OGR data source. Cannot be used with
                –ogr-sql.
    -w | --ogr-where
                Filter to apply on OGR leyr features. Cannot be used with
                –ogr-sql.
    -s | --ogr-sql
                SQL query to filter inside OGR data source. Cannot be used
                with –ogr-layer or –ogr-where.
    -z | --zoom <value>
                Set min and max zoom levels to analyze, separated by a
                comma, eg: 12,15
    -q | --query <value>
                Set query for counting tiles in a rectangle. Default value
                works with default schema of SQLite caches.
    -o | --short-output
                Only Existing SQLite files are reported, missing SQLite
                files are still Taken into account for level and global
                coverage.

3.2识别文件和计数牌

为了说明这个过程,这里有一个虚拟网格的例子。瓷砖由网格上最小的正方形表示。较大的25个方块代表sqlite文件。小索引表示瓦坐标,而大索引表示数据库坐标。彩色矩形表示请求的缓存提取区域。较暗的图块表示缓存中存在的图块。

../../_images/mapcache-detail.png

以图块表示,区域坐标*(xmin、ymin、xmax、ymax)*为(11、7、27、20)。用sqlite文件表示,这些坐标是(2,1,5,4)。包含坐标在(2,1)和(5,4)之间的所有文件应是缓存提取的一部分。坐标在(11,7)和(27,20)之间的所有瓷砖应计入区域覆盖范围。

下表根据工具的流程给出了所请求区域的图块计数和覆盖率:

SQLite文件

(2,1)

(2,2)

(2,3)

(2,4)

(3,1)

(3,2)

(3,3)

(3、4)

(4,1)

(4,2)

(4,3)

(4,4)

(5,1)

(5,2)

(5,3)

(5、4)

合计

缓存和覆盖区域中存在的磁贴

0

4

3

0

4

9

8

0

4

6

3

0

2

0

0

0

43

完全覆盖区域所需的瓷砖

12

20

20

4

15

25

25

5

15

25

25

5

9

15

15

3

238

新闻报道

0

0.2

0.15

0

0.267

0.36

0.32

0

0.267

0.24

0.12

0

0.222

0

0

0

0.181

3.3输出报告

该工具的输出采用JSON格式,为用户提供要从缓存中提取的sqlite文件列表。详细说明了有助于区域覆盖的瓷砖数量。还为每个缩放级别和全局级别提供了合成。

下面是一个虚构的例子,描述了工具输出中存在的信息。

{                                   _______________________________________
    "layer": "example",            | Report starts with general information
    "grid": "local",               | on cache and requested region
    "unit": "m",
    "region": {
        "bounding_box": [ 11, 7, 27, 20 ],
        "geometry": {
            "type": "Polygon",
            "coordinates": [[ [11,7], [11,20], [27,20], [27,7], [11,7] ]]
        }
    },
    "zoom-levels": [ {
            "level": 1,
            "files": [ {            _______________________________________
                                   | For each file, output report gives:
                                   | its name, its size, its bounding box
                                   | and intersection of that bounding box
                                   | with requested region

                "file_name": "/path/to/cache/example/1/2-1.sqlite",
                "file_size": 54632,
                "file_bounding_box": [ 10, 5, 14, 9 ],
                "region_in_file": {
                    "bounding_box": [ 11, 7, 14, 9 ],
                    "geometry": {
                        "type": "Polygon",
                        "coordinates":
                            [[ [11,7], [11,9], [14,9], [14,7], [11,7] ]]
                    }
                },
                "nb_tiles_in_region": { ___________________________________
                                   | Measures associated to a SQLite file
                                   | are: number of tiles belonging to
                                   | requested region and present in file,
                                   | number of tiles belonging to region
                                   | present or not in file, and resulting
                                   | coverage ratio

                    "cached_in_file": 0,
                    "max_in_file": 12,
                    "coverage": 0
                }
            }, {
                "file_name": ...
                ...
            } ],
            "nb_tiles_in_region": { _______________________________________
                                   | Measures associated to a zoom level
                                   | are the sum of the ones for each SQLite
                                   | file of that level

                "cached_in_level": 43,
                "max_in_level": 238,
                "coverage": 0.1807
            }
    }, {
            "level": 2,
            ...
    } ],
    "nb_tiles_in_region": {         _______________________________________
        "cached_in_cache": 43,     | Global measures are the sum of all
        "max_in_cache": 238,       | zoom level measures
        "coverage": 0.1807
    },
    "sizes": {                      _______________________________________
                                   | At global level estimations about
                                   | cache size to be extracted for a full
                                   | region coverage are also given. These
                                   | estimations are based on the mean size
                                   | of a tile obtained from all SQLite file
                                   | sizes and how many tiles they contain

        "total_size_of_files": 1599442,
        "total_nb_tiles_in_files": 60,
        "average_tile_size": 26658,
        "estimated_max_cache_size": 6344604,
        "estimated_cached_cache_size": 1146294,
        "estimated_missing_cache_size": 5198310
    }
}

第四章。实施细节

4.1。依赖关系

cJSON

输出报告以JSON文档的形式呈现。因此 mapcache_detail needs JSON printing features. For that purpose an off-the-shelf solution is proposed, namely cJSON ,可以通过麻省理工学院的许可证在GitHub上获得。预期集成ElasticSearch维度后端(请参见 RFC-121 ),它也需要JSON,文件 cJSON.hcJSON.c 简单地复制到MapCache项目中,分别位于 include/lib/ 目录。

OGR/GDAL, GEOS

要进入使用 xminyminxmaxymax 、OGR/GDAL和GEOS第三方库是必需的。如果这些库不可用,可以在CMake阶段使用 -DWITH_GEOS=OFF -DWITH_OGR=OFF 争论。

4.2。建造

mapcache_detail 在使用CMake构建MapCache时自动构建,请参阅MapCache 编译与安装 指示。

4.3.受影响的文件

文件名

状态

描述

contrib/mapcache_detail/:

mapcache_detail.c,cmakelists.txt,mapcache_detail_config.h.in

新的

实施 mapcache_detail 工具

包括/cjson.h、lib/cjson.c

新的

嵌入式JSON解析器和打印机

CMakeLists.txt

被改进的

构建链中工具的集成

5。信用

多亏了法国国防部的资助。