OSM中国区数据表总体概览与结构分析

在本地 PostgreSQL / PostGIS 实例中,数据库 osmchina 是通过工具 osm2pgsql(版本 2.3.1,slim 增量模式)将中国区域的 china-latest.osm.pbf 原始数据导入生成的。整个数据库占用磁盘空间约为 33 GB。

本文档系统性地梳理 PBF 导入完成后生成的各张核心表、数据存储容量、要素数量以及底层架构设计。


一、数据库基本环境与导入模式

根据数据库中元数据表 osm2pgsql_properties 的记录:

  • osm2pgsql 版本: v2.3.1
  • 导入模式: slim(增量更新模式,updatable = true)
  • 数据更新源: https://download.geofabrik.de/asia/china-updates
  • 输出风格: /usr/share/osm2pgsql/default.style
  • 输出表前缀: planet_osm
  • 数据库总容量: 约 33 GB
-- 查询 osm2pgsql 导入参数与复制序列号
SELECT property, value FROM osm2pgsql_properties;

二、数据表总体概况与存储分布

osm2pgsql 在 slim 模式下导入数据时,会生成两类表:

  1. 渲染与查询要素表(Geometry Tables):带空间几何索引(PostGIS way 字段),可直接用于 GIS 空间分析与地图切片服务。
  2. 拓扑与中间存储表(Slim Middle Tables):记录 OSM 原始 Node、Way、Relation 的拓扑关系与完整标签,供 osm2pgsql --append 增量更新与几何重构使用。

此外,数据库中还融合了中国行政区划辅助表(china_provinces, map_*)。

表容量与估算记录数一览

表名 类型 / 用途 总容量 表实体大小 索引大小 估算记录数 几何类型与 SRID
planet_osm_nodes Slim 中间节点表 15 GB 10 GB 5,196 MB 2.42 亿 整数坐标 (lon, lat)
planet_osm_line 线性要素要素表 5,246 MB 3,928 MB 640 MB 1,028 万 LineString (EPSG:3857)
planet_osm_ways Slim 中间路径表 5,166 MB 4,031 MB 1,054 MB 1,855 万 节点数组 bigint[]
planet_osm_polygon 面状要素要素表 4,079 MB 2,767 MB 515 MB 819 万 Geometry (EPSG:3857)
planet_osm_roads 骨干路网要素表 1,630 MB 1,119 MB 164 MB 256 万 LineString (EPSG:3857)
planet_osm_point 点状要素要素表 1,188 MB 757 MB 431 MB 705 万 Point (EPSG:3857)
planet_osm_rels Slim 中间关系表 328 MB 165 MB 150 MB 31.4 万 JSONB 成员关系
china_provinces 省级行政区图层 1,024 kB 112 kB 32 kB 35 Geometry (EPSG:4326/3857)
map_county 区县级边界扩展表 33 MB 6,024 kB 600 kB 2,784 MultiPolygon (EPSG:4326)
map_citys 市级边界扩展表 20 MB 12 MB 608 kB 2,818 MultiPolygon (EPSG:4326)
map_province 省级边界扩展表 3,384 kB 1,736 kB 176 kB 476 MultiPolygon (EPSG:4326)
map_info 行政区拓扑字典表 2,656 kB 1,984 kB 520 kB 3,238 Point (EPSG:4326)

三、空间坐标系(SRID)与索引规范

在 osmchina 数据库中存在两种坐标系:

  1. EPSG:3857(Web Mercator)

    • 包含表:planet_osm_point、planet_osm_line、planet_osm_polygon、planet_osm_roads。
    • 特点:投影坐标系,单位为米(meter)。适合前端 Web 地图切片(Mapbox、OpenLayers、Leaflet)直接渲染,计算距离与面积无需椭球体复杂换算。
    • 索引机制:所有要素表的 way 列均创建了 GiST 空间索引(如 planet_osm_line_way_idx)。
  2. EPSG:4326(WGS 84 经纬度)

    • 包含表:china_provinces、map_china、map_province、map_citys、map_county、map_info。
    • 特点:大地经纬度坐标,单位为度(degree)。
    • 跨表关联注意:当需要将行政区划边界与 OSM 要素做空间关联(如 ST_Contains)时,需使用 ST_Transform(geom, 3857) 进行动态投影转换,或预先建立 EPSG:3857 几何列。

四、核心表的功能划分

flowchart TD
    PBF["china-latest.osm.pbf (原始数据)"] --> OSM2PGSQL["osm2pgsql (slim mode)"]
    
    subgraph SlimTables["拓扑与增量存储 (约 20.5 GB)"]
        N["planet_osm_nodes (2.42亿 节点坐标)"]
        W["planet_osm_ways (1855万 线构拓扑)"]
        R["planet_osm_rels (31.4万 复合关系)"]
    end
    
    subgraph GeoTables["业务分析与渲染图层 (约 12.1 GB)"]
        P["planet_osm_point (705万 POI/设施点)"]
        L["planet_osm_line (1028万 道路/河流/管线)"]
        PG["planet_osm_polygon (819万 建筑物/水体/绿地)"]
        RD["planet_osm_roads (256万 低缩放骨干路网)"]
    end
    
    OSM2PGSQL --> SlimTables
    OSM2PGSQL --> GeoTables
  • 数据检索与分析:日常 SQL 分析与地理计算主要基于 planet_osm_point、planet_osm_line、planet_osm_polygon 和 planet_osm_roads 展开。
  • 扩展标签查询:标准模式将常用标签提升为独立字段(如 name, highway, amenity, building),其余丰富非标准标签以 PostgreSQL hstore 格式存储在 tags 字段中。