Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

批量生成瓦片

我们提供 martin-cp 工具,用于从 Martin 支持的任何源批量生成瓦片,并将检索到的瓦片保存到新的或现有的 MBTiles 文件中。

martin-cp 可用于为大型区域或多个区域(边界框)生成瓦片。 如果多个区域重叠,它将确保每个瓦片仅生成一次 martin-cp 支持与 Martin 服务器相同的配置文件和 CLI 参数,因此它可以支持所有源甚至组合源。

复制后,martin-cp 将更新 agg_tiles_hash 元数据值,除非指定了 --skip-agg-tiles-hash。 这允许使用 mbtiles validate 命令验证 MBTiles 文件。

使用

这将使用规范化模式将 PostGIS 表 my_table 中的瓦片复制到 MBTiles 文件 tileset.mbtiles 中,缩放级别从 0 到 10,边界为整个世界。

martin-cp  --output-file tileset.mbtiles \
           --mbtiles-type normalized     \
           "--bbox=-180,-90,180,90"      \
           --min-zoom 0                  \
           --max-zoom 10                 \
           --source source_name          \
           postgres://postgres@localhost:5432/db

tip

除了常规源外,--source <SOURCE> 确实支持组合源。 这意味着 martin-cp 可用于将两个不同的源合并到一个 mbtiles 归档中。

如果关注性能,您还应该考虑

[!TIP] --concurrency <CONCURRENCY> 和 --pool-size <POOL_SIZE> 可分别用于控制并发请求数和 postgres 源的池大小。

最佳设置取决于:

  • 源的性能特征
  • 允许多少负载,例如在多租户环境中
  • 如何压缩存储在输出文件中的瓦片

您还应该考虑

tip

--encoding <ENCODING> 可用于减小 MBTiles 文件的最终大小或减少 martin-cp 的处理量。

默认的 gzip 对于大多数用例应该是一个合理的选择,但如果您更喜欢不同的编码,可以在此处指定。 如果设置为多个值,如 'gzip,br',martin-cp 将使用第一个编码,或者如果瓦片已编码且该编码未列出,则重新编码。 使用 identity 禁用压缩。 对于不可编码的瓦片(如 PNG 和 JPEG)将被忽略。

参数

使用 martin-cp --help 查看可用选项列表:

A tool to bulk copy tiles from any Martin-supported sources into an mbtiles file

Usage: martin-cp [OPTIONS] --output-file <OUTPUT_FILE> [CONNECTION]...

Arguments:
  [CONNECTION]...
          Connection strings, e.g. postgres://... or /path/to/files

Options:
  -s, --source <SOURCE>
          Name of the source to copy from. Not required if there is only one source

  -o, --output-file <OUTPUT_FILE>
          Path to the mbtiles file to copy to

      --mbtiles-type <SCHEMA>
          Output format of the new destination file. Ignored if the file exists. [DEFAULT: normalized]

          [possible values: flat, flat-with-hash, normalized]

      --url-query <URL_QUERY>
          Optional query parameter (in URL query format) for the sources that support it (e.g. Postgres functions)

      --encoding <ENCODING>
          Optional accepted encoding parameter as if the browser sent it in the HTTP request.

          If set to multiple values like gzip,br, martin-cp will use the first encoding, or re-encode if the tile is already encoded and that encoding is not listed. Use identity to disable compression. Ignored for non-encodable tiles like PNG and JPEG.

          [default: gzip]

      --on-duplicate <ON_DUPLICATE>
          Allow copying to existing files, and indicate what to do if a tile with the same Z/X/Y already exists

          [possible values: override, ignore, abort]

      --concurrency <CONCURRENCY>
          Number of concurrent connections to use

          [default: 1]

      --bbox <BBOX>
          Bounds to copy, in the format min_lon,min_lat,max_lon,max_lat. Can be specified multiple times. Overlapping regions will be handled correctly

      --min-zoom <MIN_ZOOM>
          Minimum zoom level to copy

      --max-zoom <MAX_ZOOM>
          Maximum zoom level to copy

  -z, --zoom-levels <ZOOM_LEVELS>
          List of zoom levels to copy

      --skip-agg-tiles-hash
          Skip generating a global hash for mbtiles validation. By default, martin-cp will compute and update agg_tiles_hash metadata value

      --set-meta <KEY=VALUE>
          Set additional metadata values. Must be set as "key=value" pairs. Can be specified multiple times

  -c, --config <CONFIG>
          Path to config file. If set, no tile source-related parameters are allowed

      --save-config <SAVE_CONFIG>
          Save resulting config to a file or use "-" to print to stdout. By default, only print if sources are auto-detected

  -b, --auto-bounds <AUTO_BOUNDS>
          Specify how bounds should be computed for the spatial PG tables. [DEFAULT: quick]

          Possible values:
          - quick: Compute table geometry bounds, but abort if it takes longer than 5 seconds
          - calc:  Compute table geometry bounds. The startup time may be significant. Make sure all GEO columns have indexes
          - skip:  Skip bounds calculation. The bounds will be set to the whole world

      --ca-root-file <CA_ROOT_FILE>
          Loads trusted root certificates from a file. The file should contain a sequence of PEM-formatted CA certificates

  -d, --default-srid <DEFAULT_SRID>
          If a spatial PG table has SRID 0, then this default SRID will be used as a fallback

  -p, --pool-size <POOL_SIZE>
          Maximum Postgres connections pool size [DEFAULT: 20]

  -m, --max-feature-count <MAX_FEATURE_COUNT>
          Limit the number of geo features per tile.

          If the source table has more features than set here, they will not be included in the tile and the result will look "cut off"/incomplete. This feature allows to put a maximum latency bound on tiles with extreme amount of detail at the cost of
          not returning all data. It is sensible to set this limit if you have user generated/untrusted geodata, e.g. a lot of data points at Null Island.

          Can be either a positive integer or unlimited if omitted.

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version

Use RUST_LOG environment variable to control logging level, e.g. RUST_LOG=debug or RUST_LOG=martin_cp=debug. See https://docs.rs/env_logger/latest/env_logger/index.html#enabling-logging for more information.