OSMIUM-EXPORT(1)
๐ OSMIUM-EXPORT โ export OSM data
okay so bestie, welcome to osmium-export(1), the glow-up machine for your OSM data. it takes your nodes/ways/relations and turns them into actual GIS geometries. it's giving "makeover montage" energy and i'm obsessed. โจ
๐ธ SYNOPSIS
osmium export [OPTIONS] OSM-FILE
๐ฆ DESCRIPTION
so like, the OSM data model (nodes, ways, relations) is completely different from the data model geodata people usually use, where features have point, linestring, or polygon geometries โ or their cousins, multipoint, multilinestring, multipolygon. two totally different vibes, no cap.
The export command transforms OSM data into a more usual GIS data model. Here's the translation table in my head:
- Nodes โก๏ธ points
- Ways โก๏ธ linestrings or polygons (if they are closed ways)
- Multipolygon and boundary relations โก๏ธ multipolygons
โ ๏ธ heads up: this transformation is not loss-less. especially, information in non-multipolygon, non-boundary relations is lost. gone. bye. ๐
All tags are preserved in this process. But ngl, most GIS formats (such as Shapefiles, etc.) do not support arbitrary tags. Transformation into other GIS formats will need extra steps mapping tags to a limited list of attributes. That's outside the scope of this command, so don't @ me.
The osmium export command has to keep an index of the node locations in memory or in a temporary file on disk while doing its work. There are several different ways it can do that which have different advantages and disadvantages. The default is good enough for most cases, but see the osmium-index-types(5) man page for details. iykyk.
Objects with invalid geometries are silently omitted from the output. That's the case for ways with less than two nodes, or closed ways or relations that can't be assembled into a valid (multi)polygon. Wanna change that behaviour? See the options --show-errors/-e and --stop-on-error/-E. ๐ซถ
The input file will be read twice (once for the relations, once for nodes and ways), so this command can not read its input from STDIN. sorry bestie, no pipe dreams here.
This command will not work on full history files.
This command will work with negative IDs on OSM objects (for instance on files created with JOSM). slay. ๐
โจ OPTIONS โจ
-c,--config=FILEโ Read configuration from specified file. your lil settings file, your rules.-C,--print-default-configโ Print the default config to STDOUT. Useful if you want to change it and not write the whole thing manually. โ ๏ธ If you use this option all other options are ignored.-e,--show-errorsโ Output any geometry errors on STDERR. This includes ways with a single node or areas that can't be assembled from multipolygon relations. ngl this output is not suitable for automated use โ there are other tools that can create very detailed errors reports that are better for that (seehttps://osmcode.org/osm-area-tools/).-E,--stop-on-errorโ Usually geometry errors (due to missing node locations or broken polygons) are ignored and the features are omitted from the output. If this option is set, any error will immediately stop the program. dramatic, but fair. ๐ญ--geometry-types=TYPESโ Specify the geometry types that should be written out. Usually all created geometries (points, linestrings, and (multi)polygons) are written to the output, but you can restrict the types using this option. TYPES is a comma-separated list of the types ("point","linestring", and"polygon").-a,--attributes=ATTRSโ In addition to tags, also export attributes specified in this comma-separated list. By default, none are exported. See the ATTRIBUTES section below for the known attributes list and an explanation. ๐-i,--index-type=TYPEโ Set the index type. For details see theosmium-index-types(5)man page.-I,--show-index-typesโ Shows a list of available index types. For details see theosmium-index-types(5)man page. โ ๏ธ If you use this options all other options are ignored.-n,--keep-untaggedโ If this is set, features without any tags will be in the exported data. By default these features will be omitted from the output. Just so we're clear: "Tags" are the OSM tags, not attributes (likeid,version,uid, ...) without the tags removed by theexclude_tagsorinclude_tagssettings.-u,--add-unique-id=TYPEโ Add a unique ID to each feature. TYPE can be eithercounter, in which case the first feature will get ID1, the next ID2and so on โ the type of object does not matter in this case. Or the TYPE istype_id, in which case the ID is a string: the first character is the type of object (`n'for nodes,`w'for linestrings created from ways, and`a'for areas created from ways and/or relations), and after that there is a unique ID based on the original OSM object ID(s). For nodes and ways the numeric part of the ID is identical to the original node or way ID. For areas, the ID is calculated from the original ID: for ways it is twice the original ID, for relations it is twice the original ID plus one. If the input file has negative IDs, this can create IDs such as`w-12'. math girlie behaviour fr fr ๐งฎ-x,--format-option=OPTION(=VALUE)โ Set an output format option. The options available depend on the output format. See the OUTPUT FORMAT OPTIONS section for available options. If the VALUE is not set, the OPTION will be set to"true". If needed you can specify this option multiple times to set several options. Options set on the command line overwrite options set in the config file. ๐
๐ COMMON OPTIONS
-h,--helpโ Show usage help.-v,--verboseโ Set verbose mode. The program will output information about what it is doing to STDERR.--progressโ Show progress bar. Usually a progress bar is only displayed if STDOUT and STDERR are detected to be TTY. With this option a progress bar is always shown. Note that a progress bar will never be shown when reading from STDIN or a pipe.--no-progressโ Do not show progress bar. Usually a progress bar is displayed if STDOUT and STDERR are detected to be a TTY. With this option the progress bar is suppressed. Note that a progress bar will never be shown when reading from STDIN or a pipe.
๐ INPUT OPTIONS
-F,--input-format=FORMATโ The format of the input file(s). Can be used to set the input format if it can't be autodetected from the file name(s). โ ๏ธ This will set the format for all input files, there is no way to set the format for some input files only. Seeosmium-file-formats(5)or the libosmium manual for details.
๐ฆ OUTPUT OPTIONS
-f,--output-format=FORMATโ The format of the output file. Can be used to set the output file format if it can't be autodetected from the output file name. See the OUTPUT FORMATS section for a list of formats.--fsyncโ Callfsyncafter writing the output file to force flushing buffers to disk. committing to the bit. ๐พ-o,--output=FILEโ Name of the output file. Default is`-'(STDOUT).-O,--overwriteโ Allow an existing output file to be overwritten. Normally osmium will refuse to write over an existing file. respectful king.
๐ CONFIG FILE
The config file is in JSON format. The top-level is an object which contains the following optional names:
attributes: An object specifying which attributes of OSM objects to export. See the ATTRIBUTES section.format_options: An object specifying output format options. The options available depend on the output format. See the OUTPUT FORMAT OPTIONS section for available options. These options can also be set using the command line option--format-option/-x.linear_tags: An expression specifying tags that should be treated as linear tags. See below for details and also look at the AREA HANDLING section.area_tags: An expression specifying tags that should be treated as area tags. See below for details and also look at the AREA HANDLING section.exclude_tags: A list of tag expressions. Tags matching these expressions are excluded from the output. See the FILTER EXPRESSION section.include_tags: A list of tag expressions. Tags matching these expressions are included in the output. See the FILTER EXPRESSION section.
The area_tags and linear_tags can have the following values:
trueโ All tags match. (An empty list[]can also be used to mean the same, but this use is deprecated because it can be confusing.) ๐falseโ No tags match.- Array โ The array contains one or more expressions as described in the FILTER EXPRESSION section.
nullโ If thearea_tagsorlinear_tagsis set tonullor not set at all, the inverse of the other setting is used. So if you do not set thelinear_tagsbut have some expressions inarea_tags, areas will be created for all objects matching those expressions and linestrings for everything else. This can be simpler, because you only have to keep one list, but in cases where an object can be interpreted as both an area and a linestring, only one interpretation will be used.
The exclude_tags and include_tags options are mutually exclusive. If you want to just exclude some tags but leave most tags untouched, use the exclude_tags setting. If you only want a defined list of tags, use include_tags.
When no config file is specified, the following settings are used:
{
"attributes": {
"type": false,
"id": false,
"version": false,
"changeset": false,
"timestamp": false,
"uid": false,
"user": false,
"way_nodes": false
},
"format_options": {
},
"linear_tags": true,
"area_tags": true,
"exclude_tags": [],
"include_tags": []
}
๐ FILTER EXPRESSIONS ๐
okay so a filter expression is literally just you telling osmium export which tag or tags you want matched in the data. that's it. that's the whole vibe.
some examples, bestie, so you can see what we're working with:
amenityโ matches every object that has the keyamenity. all of them. no cap.highway=primaryโ matches every object with keyhighwayAND valueprimary.highway!=primaryโ matches every object with keyhighwayand any value that is notprimary.type=multipolygon,boundaryโ matches objects with keytypeand valuemultipolygonorboundary.name,name:de=Kastanienallee,Kastanienstrasseโ matches any object with anameorname:detag whose value isKastanienalleeorKastanienstrasse.addr:*โ matches every object with any key starting withaddr:. yes, all the addr besties.name=*Parisโ matches every object with a name that contains the wordParis.
so here's the rules of the game ๐
if there is no equal sign (=) in the expression, only keys get matched and the values can be literally anything. if there is an equal sign (=) in the expression, then the key is on the left and the value is on the right. an exclamation sign (!) before the equal sign means: a tag with that key, but not the value(s) to the right of the equal sign.
a leading or trailing asterisk (*) can be used for substring or prefix matching, respectively. and commas (,) can be used to separate several keys or several values.
โ ๏ธ all filter expressions are case-sensitive. there is no way to escape the special characters such as=,*and,. and you can not mix comma-expressions and*-expressions. that's just how it is, sorry not sorry ๐
๐ธ ATTRIBUTES ๐ธ
all OSM objects (nodes, ways, and relations) have attributes, and areas inherit their attributes from the ways and/or relations they were created from. here's the attributes that osmium export knows about:
- type (
node,way, orrelation) - id (64 bit object ID)
- version (version number)
- changeset (changeset ID)
- timestamp (time of object creation in seconds since Jan 1 1970)
- uid (user ID)
- user (user name)
- way_nodes (ways only, array with node IDs)
for areas, the type will be way or relation if the area was created from a closed way or a multipolygon or boundary relation, respectively. and the id for areas is the id of the closed way or the multipolygon or boundary relation. ๐
by default the attributes will not be in the export, because honestly they're not necessary for most uses of OSM data. but if you're interested in some (or all) of them, add an attributes object to the config file. add a member for each attribute you're interested in, and the value can be either false (do not output this attribute), true (output this attribute with the attribute name prefixed by the @ sign) or any string, in which case the string will be used as the attribute name. slay.
another option is to specify the attributes list in a comma-separated string for the --attributes/-a command-line option. this way you can't control column names, but also you won't have to create a config file. tradeoffs, bestie.
depending on your choice of values for the attributes objects, attributes can have the same name as tag keys. if that's the case, the conflicting tag is silently dropped. so if there's a tag @id=foo and you've set id to true in the attributes object, the tag will not show up in the output. just gone. ๐
๐จ note that the id is not necessarily unique. even the combination of type and id is not unique, because a way may end up in the output file as LineString and as (Multi)Polygon. see the--add-unique-id/-uoption if you want a unique ID.
๐ฆ AREA HANDLING ๐ฆ
multipolygon relations will be assembled into multipolygon geometries forming areas. some closed ways will also form areas. here are the detailed rules, no gatekeeping:
- Non-closed way โ a non-closed way (with the last node location not the same as the first node location) is always (regardless of any tags) a linestring, not an area. periodt.
- Relation โ a relation tagged
type=multipolygonortype=boundaryis always (regardless of any tags) assembled into an area. - Closed way โ for a closed way (with the last node location the same as the first node location) the tags are checked: if the way has an
area=yestag, an area is created. if the way has anarea=notag, a linestring is created. anareatag with a value other thanyesornois ignored. the configuration settingsarea_tagsandlinear_tagscan be used to augment the area check. if any of the tags matches thearea_tags, an area is created. if any of the tags matches thelinear_tags, a linestring is created. if both match, an area and a linestring is created. this is important because some objects have tags that make them both, an area and a linestring. iconic chaotic energy tbh. โจ
๐ OUTPUT FORMATS ๐
the following output formats are supported:
geojson(alias:json): GeoJSON (RFC7946). the output file will contain a singleFeatureCollectionobject. this is the default format. ๐geojsonseq(alias:jsonseq): GeoJSON Text Sequence (RFC8142). each line (beginning with a RS (0x1e, record separator) and ending in a linefeed character) contains one GeoJSON object. used for streaming GeoJSON.pg: PostgreSQL COPY text format. one line per object containing the WGS84 geometry as WKB, the tags in JSON format and, optionally, more columns for id and attributes. you have to create the table manually, then use the PostgreSQLCOPYcommand to import the data. enable verbose output to see the SQL commands needed to create the table and load the data.text(alias:txt): a simple text format with the geometry in WKT format followed by the comma-delimited tags. this is mainly intended for debugging at the moment. > THE FORMAT MIGHT CHANGE WITHOUT NOTICE! ๐จ (not me warning you twice, it's giving unstable)
๐ OUTPUT FORMAT OPTIONS ๐
print_record_separator(default:true). set tofalseto not print the RS (0x1e, record separator) character when using the GeoJSON Text Sequence Format. ignored for other formats.tags_type(default:jsonb). set tohstoreto use HSTORE format instead of JSON/JSONB when using the Pg Format. ignored in other formats.
๐ DIAGNOSTICS ๐
osmium export exits with exit code:
0โ if everything went alright,1โ if there was an error processing the data, or2โ if there was a problem with the command line arguments.
๐ง MEMORY USAGE ๐ง
osmium export will usually keep all node locations and all objects needed for assembling the areas in memory. for larger data files, this can need several tens of GBytes of memory. ๐ญ see the osmium-index-types(5) man page for details. your RAM is the main character here and she is stressed.
โญ EXAMPLES โญ
export into GeoJSON format:
osmium export data.osm.pbf -o data.geojson
use a config file and export into GeoJSON Text Sequence format:
osmium export data.osm.pbf -o data.geojsonseq -c export-config.json
๐ซถ SEE ALSO ๐ซถ
osmium(1),osmium-file-formats(5),osmium-index-types(5),osmium-add-node-locations-to-ways(1)- Osmium website
- GeoJSON
- RFC7946
- RFC8142
- Line delimited JSON
๐ COPYRIGHT ๐
Copyright (C) 2013-2026 Jochen Topf <jochen@topf.org>.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. this is free software: you are free to change and redistribute it. there is NO WARRANTY, to the extent permitted by law.
๐ CONTACT ๐
if you have any questions or want to report a bug, please go to https://osmcode.org/contact.html โ they're lovely, go say hi.
๐ธ AUTHORS ๐ธ
Jochen Topf <jochen@topf.org>.
and that's a wrap on OSMIUM-EXPORT(1), bestie ๐
โจ this beauty lives at version 1.19.1 โ go forth and export, you absolute icon, and remember: no cap, only GeoJSON. ๐ฆ๐๐
๐ฆ where this page comes from
- fedora 44: osmium-tool 1.19.1-1.fc44 ยท GPL-3.0-only
- nixos 26.05: osmium-tool 1.19.1
- nixpkgs unstable: osmium-tool 1.19.1
- ubuntu stonking: osmium-tool 1.19.1-1 ยท GPL-3.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms