You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让TileServer GL读取.osm.gz与.mbt格式数据?

TileServer GL数据导入问题解决方案

一、.osm.gz 转 MBTiles 解决边界框错误

你碰到的 Can't read shapefiles unless a bounding box is provided. 错误,是因为转换工具需要明确数据的地理范围。以下是可行的转换流程:

  1. 先解压 .osm.gz 文件:
    gzip -d your_data.osm.gz
    
  2. 用 osmium-tool 转成更高效的 .osm.pbf 格式:
    osmium cat your_data.osm -o your_data.osm.pbf
    
  3. 用 tippecanoe 转成 MBTiles,必须指定边界框:
    # 全球范围用这个边界框
    tippecanoe -o your_data.mbtiles -b -180,-85,180,85 your_data.osm.pbf
    # 区域数据替换成对应经纬度,比如中国区域:-b 73.5,18.1,135.1,53.5
    
    如果用 ogr2ogr 转换出错,同样加上 -spat 参数指定边界框:
    ogr2ogr -f MBTiles your_data.mbtiles your_data.osm.pbf -spat 73.5 18.1 135.1 53.5
    

二、处理 .mbt 文件

大部分 .mbt 文件本质就是 MBTiles 格式,只是后缀名不同,直接改后缀就能用:

  • 把 your_data.mbt 重命名为 your_data.mbtiles,放到 TileServer GL 的 data 目录。
  • 如果改后缀后无法识别,用 sqlite3 验证结构(MBTiles 基于SQLite):
    sqlite3 your_data.mbt ".tables"
    
    要是输出包含 tiles、metadata 这些表,说明就是标准 MBTiles,直接使用即可;如果不是,用 tippecanoe 重新转换:
    tippecanoe -o your_data.mbtiles your_data.mbt
    

三、TileServer GL 加载配置

把生成的 .mbtiles 放进数据目录后,修改 config.json 添加数据源:

{
  "options": {
    "paths": {
      "root": "/data"
    }
  },
  "data": {
    "custom_layer": {
      "mbtiles": "your_data.mbtiles"
    }
  }
}

重启服务即可加载数据。


内容的提问来源于stack exchange,提问作者Veit Bjarsch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 18:02:32