Convert PBF to CSV: What Survives the Trip from Binary Map Data to a Flat Table

What converting a PBF file to CSV actually changes, what gets lost, how to keep text readable after export, and when a flat table is the wrong target.

Turning a PBF file into CSV is a format conversion, not a cosmetic text effect. Nothing is reversed, mirrored or restyled. The real question is whether a flat, comma- or tab-separated table can hold enough of the original data to be useful for your task. This review explains what the conversion changes, where meaning tends to drop out, and when CSV is the right target.

First, which PBF do you have?

"PBF" is ambiguous, and the right conversion depends on which kind of file you have. Most people searching for this conversion are working with OpenStreetMap data saved in the Protocolbuffer Binary Format, usually named with an .osm.pbf extension. The same three letters also appear on vector map tiles, which are separate binary tiles that often use a .pbf extension too. Both formats encode data with Protocol Buffers, but they are structured differently. This article focuses on OpenStreetMap extracts. Vector tiles are mentioned briefly where the advice differs.

Is converting PBF to CSV suitable for your use?

Bounded recommendation: CSV is a good target when you need a specific, narrow slice of the data, such as points of interest with an ID, coordinates and a few chosen tags. You can then open, filter, join or hand off that slice in tools that do not understand map formats. The main benefit is reach, because almost any spreadsheet, database or scripting language can read a plain-text table. The decisive tradeoff is structure. CSV has one row per record and a fixed set of columns. OpenStreetMap data has open-ended tags, lines and areas built from references to other objects, and relations that group objects together. Anything that does not fit a row-and-column shape has to be flattened, encoded as text, or dropped.

Keep the data in PBF, or convert it to a geospatial format such as GeoPackage or GeoJSON, in these cases:

  • You need real line and polygon geometry for mapping or spatial analysis, not just point coordinates.
  • You need relations, such as routes, multipolygons or administrative boundaries, with their membership intact.
  • You plan to update the extract later or exchange it with other OpenStreetMap tools.
  • The extract covers a large region and you do not filter it first. The flat text output will be much larger than the compressed binary source and may exceed what a spreadsheet can open.

What the conversion actually changes

An OpenStreetMap PBF file stores three kinds of objects. Nodes are points with coordinates. Ways are ordered lists of node references that form lines or closed areas. Relations are groups of nodes, ways or other relations, each with a role. Any object can carry any number of key=value tags. The file stores all of this as compressed binary blocks, so you cannot read it as text.

Converting to CSV changes the stored representation in several concrete ways:

  • Binary to text: numbers, coordinates and tag strings are written out as characters, which is why the output is human-readable but larger.
  • Open tags become fixed columns: you choose which keys become columns. Tags you do not choose are usually discarded. Some tools can pack all remaining tags into a single text field instead.
  • References become either text or nothing: a way's geometry exists only as references to its nodes. A converter must look up those nodes and write the shape as text, for example as Well-Known Text (WKT). Otherwise the export is limited to nodes or to a single representative point per object.
  • Hierarchy flattens: relation membership and roles have no natural place in a single row.
  • Metadata is optional: version, timestamp and editor fields may or may not be carried over, depending on the tool and settings.

Tag values themselves, such as names, should come through as the same Unicode characters, provided the tool writes UTF-8. Nothing is substituted for look-alike glyphs and no styling is applied. What can go wrong is how a later application interprets those characters, which is covered in the section on readability and sharing.

Common ways to do it

Two widely used command-line routes are GDAL's ogr2ogr and osmconvert. With ogr2ogr, the OpenStreetMap driver exposes the file as layers: points, lines, multilinestrings, multipolygons and other_relations. You export one layer at a time, and the CSV driver can write the geometry column as WKT. The example below uses placeholder file names. Check option names against the help output of your installed version.

ogr2ogr -f CSV points.csv input.osm.pbf points -lco GEOMETRY=AS_WKT
ogr2ogr -f CSV areas.csv input.osm.pbf multipolygons -lco GEOMETRY=AS_WKT

osmconvert has a CSV mode. You list the fields you want, using built-in fields such as @id, @lon and @lat plus any tag keys. The --all-to-nodes option reduces ways and relations to single points so that they can appear as rows. Check its documentation for the default separator and the option that changes it, because the default may not be a comma.

osmconvert input.osm.pbf --all-to-nodes --csv="@id @lon @lat amenity name" --csv-headline > output.csv

Online converters also exist. Their output quality, size limits and handling of uploaded files cannot be judged from their pages alone. Do not assume any retention or privacy practice unless the provider documents it, especially if the extract contains data you are not free to share. For vector-tile PBF files, GDAL also has a driver that reads that format. A single tile, though, holds only the clipped and simplified data that was prepared for display, not the full source data.

Will the result stay readable and usable after copying or sharing?

CSV is plain text, so copying it between programs does not depend on fonts or styling the way decorative Unicode text does. Its weak points are parsing and interpretation. The illustrative snippet below shows the structure with placeholder values. A tag value containing a comma must be wrapped in double quotes, or every program that reads the file will split it into an extra column.

id,lon,lat,name
1,0.0,0.0,"Cafe, Bakery & Bar"
  • Quoting: commas, double quotes and line breaks inside tag values must be escaped consistently. Inspect a sample of the output before relying on it.
  • Encoding: OpenStreetMap names cover many scripts. If a spreadsheet opens a UTF-8 file under a different encoding, names turn into garbled characters. Importing the file with the encoding set explicitly avoids this.
  • Type coercion: spreadsheets may reformat numeric-looking columns. They can strip leading zeros from postal codes or show long IDs in scientific notation. Importing those columns as text preserves them.
  • Right-to-left names: Arabic, Hebrew and other right-to-left names are stored in logical order. CSV keeps that order unchanged. Whether a name displays correctly next to left-to-right columns depends on the viewing application's bidirectional text handling, not on the conversion.
  • Geometry as text: a WKT column is readable but long. It is useful to GIS software and of little use in an ordinary spreadsheet view.

Accessibility follows from the destination rather than from the CSV itself. A file with a clear header row and meaningful column names gives screen readers and other assistive technology something to announce when the file is opened in a spreadsheet or table view. Packed tag fields and long WKT strings are hard to navigate by ear. If the output is meant for people rather than software, publish a trimmed version with descriptive columns and no raw geometry. Searching and editing are straightforward in plain text, but editing values by hand breaks the link to the source data. Any change then has to be made again if you re-export.

Quick comparison

Aspect | PBF (OpenStreetMap) | CSV export
Human-readable | No, binary | Yes, plain text
Tags | Any number per object | Only the keys you choose, or packed into one field
Lines and areas | Built from node references | Written as WKT text, or reduced to points
Relations | Fully represented | Usually flattened or omitted
Tool support | OpenStreetMap and GIS tools | Nearly universal
Relative size | Compact | Larger for the same content

Gaps in this review

No subject-specific test results were available for this review. The commands above reflect documented tool options and were not run against a sample file here. No timings, file-size ratios or row counts are given, and no particular online converter or spreadsheet application was tested. Before you depend on an export, run it on a small extract and open the result in the program you will actually use. Then confirm that names, quoting, IDs and geometry come through as expected.