I have a few (~50) PBF files came from SRTM conversion using phyghtmap.

How to merge all of them before importing with osm2pgsql?

3 Answers 3


You can use osmium for merging:

osmium merge file1.osm file2.osm -o merged.osm.

Alternatively try osmosis:

osmosis --rx file1.osm --rx file2.osm --merge --wx merged.osm

Note that osmosis has a weird syntax and you need to specify the --merge commands n-1 times for merging n files.

  • Ok. But how to merge several files at once? I have a lot of them.
    – Magno C
    Commented Jun 6, 2017 at 11:18
  • 2
    Just specify as many files as you want: omium merge file*.osm -o merged.osm.
    – scai
    Commented Jun 6, 2017 at 11:21
  • 1
    BTW: Can I do the same with PBF files?
    – Magno C
    Commented Jun 6, 2017 at 13:22
  • 1
    Can't find merge option. : osmcode.org/osmium-tool/manual.html#command-line-completion
    – Magno C
    Commented Jun 6, 2017 at 13:25
  • 3
    For PBF files use osmosis --rb file1.osm --rb file2.osm --merge --wb merged.osm. rx is for XML files.
    – Milanka
    Commented Jul 26, 2019 at 12:24

On Ubuntu:

sudo apt-get install osmium-tool
osmium cat new-york.osm.pbf new-jersey.osm.pbf connecticut.osm.pbf -o ny-nj-ct.osm.pbf
  • Easy to follow these for osmium with the following version >> osmium --version ``` osmium version 1.16.0 libosmium version 2.20.0 Supported PBF compression types: none zlib lz4```
    – Sid
    Commented Oct 23, 2023 at 22:04
  • Note that osmium cat is often not what you want, take a look at osmium merge instead!
    – centic
    Commented Nov 30, 2023 at 23:10

osmconvert did trick for me on windows for two files.

osmconvert a.pbf --out-o5m | osmconvert - b.pbf -o=all.pbf


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.