如何在保留所有节点、方式和关系信息的同时合并 osm 文件?

How can I merge osm files while retaining all node, way, and relation information?

背景

我正在尝试为我正在为 Windows 桌面开发的紧凑型离线地图解决方案制作缩小尺寸的矢量 mbtiles 文件。为此,我发现 OsmAnd 的缩小尺寸 World_basemap_2.obf 正是我所需要的,但采用 mbtiles OSM 格式,因此我可以生成一个 mbtiles。 obf 是使用从形状文件生成的以下 OSM 文件创建的。它们可在 http://builder.osmand.net/basemap/

我遇到的问题是,为了制作一个 mbtiles,它们需要合并到一个 OSM 文件中。 osm2vectortiles' 生成 mbtiles 的指南在此处 http://osm2vectortiles.org/docs/own-vector-tiles/

首先我提取它们来处理osm文件。

问题

当我使用osmconvert使用--complete-ways--complex-ways标志组合文件时,删除了很多关系和方式并且文件大小非常不同。

例如:

osmconvert proc_line_tertiary_out.osm --complete-ways --complex-ways -o=tertiary.o5m

生成大小为 133,691 kb 的文件

osmconvert tertiary.o5m --complete-ways --complex-ways -o=tertiary.csv

生成的 CSV 文件共有 13131405 个节点、方式和关系

osmconvert tertiary.o5m proc_line_ferry_out.osm.o5m --complete-ways --complex-nodes -o=combined.o5m

tertiary.o5mproc_line_ferr_out.osm.o5m 合并(生成与上图相同)并转换为 CSV

生成的 CSV 文件中包含 1195239 个节点、方式和关系……明显更少,但非常令人担忧。合并两个文件应该不会比原始文件少节点、方式和关系。

问题

我做错了什么?

尝试合并的文件

OSMConvert

osmconvert 解释说

Merging two or more Geographical Areas

Under certain conditions, OSM data files can be merged. If they hold objects (nodes, ways, relations) with the same id, they must have the same content. For example: If a way crosses the geographical border between two regional files, the way dataset must contain every node reference, even the references to nodes which do not lie within the borders of the regarding file. I.e., such a region must not have been cut out using the option --drop-brokenrefs.

这是否意味着我不能做我想做的事?我想保留所有节点、方式和关系,即使文件中没有它们。

尝试

osmconvert polygon_aeroway_military_tourism.osm polygon_natural_landuse.osm -o=result.osm

结果

    <?xml version='1.0' encoding='UTF-8'?>
    <osm version="0.6" generator="osmconvert 0.7T">
        <node id="-10000000000001" lat="-1.0015443" lon="-80.5349586"/>
        <way id="-100000001" version="1">
            <nd ref="-10000000000001"/>
            <nd ref="-10000000000002"/>
            <nd ref="-10000000000003"/>
            <nd ref="-10000000000004"/>
            <nd ref="-10000000000005"/>
            <nd ref="-10000000000006"/>
            <nd ref="-10000000000007"/>
            <nd ref="-10000000000008"/>
            <nd ref="-10000000000009"/>
            <nd ref="-10000000000010"/>
            <nd ref="-10000000000011"/>
            <nd ref="-10000000000012"/>
            <nd ref="-10000000000013"/>
            <nd ref="-10000000000014"/>
            <nd ref="-10000000000015"/>
            <nd ref="-10000000000016"/>
            <nd ref="-10000000000017"/>
            <nd ref="-10000000000018"/>
            <nd ref="-10000000000019"/>
            <nd ref="-10000000000020"/>
            <nd ref="-10000000000021"/>
            <nd ref="-10000000000022"/>
            <nd ref="-10000000000023"/>
            <nd ref="-10000000000024"/>
            <nd ref="-10000000000025"/>
            <nd ref="-10000000000026"/>
            <nd ref="-10000000000027"/>
            <nd ref="-10000000000028"/>
            <nd ref="-10000000000029"/>
            <nd ref="-10000000000030"/>
            <nd ref="-10000000000031"/>
            <nd ref="-10000000000032"/>
            <nd ref="-10000000000033"/>
            <nd ref="-10000000000034"/>
            <nd ref="-10000000000035"/>
            <nd ref="-10000000000036"/>
            <nd ref="-10000000000037"/>
            <nd ref="-10000000000038"/>
            <nd ref="-10000000000039"/>
            <nd ref="-10000000000040"/>
            <nd ref="-10000000000041"/>
            <nd ref="-10000000000042"/>
            <nd ref="-10000000000043"/>
            <nd ref="-10000000000044"/>
            <nd ref="-10000000000045"/>
            <nd ref="-10000000000046"/>
            <nd ref="-10000000000047"/>
            <nd ref="-10000000000048"/>
            <nd ref="-10000000000049"/>
            <nd ref="-10000000000050"/>
            <nd ref="-10000000000051"/>
            <nd ref="-10000000000001"/>
        </way>
    </osm>

您的用例可能更容易从多个 OSM2VectorTiles 提取的 MBTiles 格式中合并已呈现的矢量切片(复制单个 PBF 切片),并将所有这些合并到一个 MBTiles 文件中。

您可以使用 MBUtil 包中的 patch 实用程序: https://github.com/mapbox/mbutil/blob/master/patch

或来自https://pypi.python.org/pypi/umimbutil

的工具

这两个实用程序应该 运行 用于基本合并不同的区域,其中不需要将各个图块组合在一起。

或者 - 您可以编写一个基本脚本,从行星 MBTiles 中删除所有您不需要的图块。 MBTiles 只是 SQLite 文件,所以这应该可以用基本的 SQL 命令来完成...

P.S。 如果有人需要合并栅格 (!!!) MBTiles,包括将 PNG 或 JPEG 瓦片中的栅格瓦片组合在一起,那么他们需要不同的合并实用程序:https://www.maptiler.com/how-to/merge-mbtiles/ on command-line merge_mbtiles available after filling the form at http://www.maptiler.com/demo/

选项 --complete-ways--complex-ways 用于应用边框时使用。如果您不裁剪 OSM 数据(选项 -b 或 -B),最好不要使用 --complete-ways--complex-ways除非您确定他们如何处理您的数据。至少我不是。

选择使用osmconvert合并OSM数据的方式是这样的:

osmconvert input1.o5m input2.o5m input3.o5m -o=output.o5m

OSM Wiki 中有一些关于 osmconvert 的更多信息:

https://wiki.openstreetmap.org/wiki/Osmconvert