# Working with OpenStreetMap files

## Converting PBF to OSM XML

A lot of routing software used in the OpenStreetMap (OSM) project supports Protocolbuffer Binary Format (PBF). There are several tools to convert from PBF to OSM XML and vice versa, if required, including Osmconvert, Osmosis and Osmium:

<table data-header-hidden><thead><tr><th width="151"></th><th width="239"></th><th width="133"></th><th></th></tr></thead><tbody><tr><td><strong>Tool</strong></td><td><strong>Description</strong></td><td><strong>Functionality</strong></td><td><strong>Example</strong></td></tr><tr><td><a href="https://wiki.openstreetmap.org/wiki/Osmconvert">Osmconvert</a></td><td>Lightweight (but fast) application to convert and process OSM files.</td><td>Basic</td><td><code>osmconvert OSMulti-modalRoutingNetwork.pbf >OSMulti-modalRoutingNetwork.osm</code></td></tr><tr><td><a href="https://wiki.openstreetmap.org/wiki/Osmosis">Osmosis</a></td><td>Command-line application for processing OSM data.</td><td>Intermediate</td><td><code>osmosis --read-pbf OSMulti-modalRoutingNetwork.pbf --write-xml OSMulti-modalRoutingNetwork.osm</code></td></tr><tr><td><a href="https://osmcode.org/osmium-tool/">Osmium</a></td><td>Multipurpose command-line tool based on the Osmium Library.</td><td>Advanced</td><td><code>osmium cat OSMulti-modalRoutingNetwork.pbf -o OSMulti-modalRoutingNetwork.osm</code></td></tr></tbody></table>

## Sorting OSM files

OSM files are usually sorted in a specific way: first the nodes ordered by ID, then ways ordered by ID, then relations ordered by ID. But this is not necessarily always the case.

{% hint style="warning" %}
It is important to check if a file is sorted correctly as many commands only work properly if a file is sorted.
{% endhint %}

To check if a file is sorted, in [Osmium](https://docs.osmcode.org/osmium/latest/osmium-fileinfo.html) use `fileinfo` :

```
> osmium fileinfo -e input.osm.pbf
...
Objects ordered (by type and id): yes
...
```

To sort a file using [Osmium](https://docs.osmcode.org/osmium/latest/osmium-sort.html):

```
> osmium sort input.osm.pbf -o output.osm.pbf
```

To sort a file using [Osmosis](https://wiki.openstreetmap.org/wiki/Osmosis):

```
osmosis --read-pbf input.osm.pbf --sort --write-pbf output.osm.pbf
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.os.uk/os-downloads/products/transport-network-portfolio/os-multi-modal-routing-network/os-mrn-getting-started-guide/working-with-openstreetmap-files.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
