WhereAmI/OSM Binary Format

From OpenStreetMap Wiki
< WhereAmI(Redirected from OSM Binary Format)
Jump to: navigation, search
Available languages — WhereAmI/OSM Binary Format
Afrikaans Alemannisch aragonés asturianu azərbaycanca Bahasa Indonesia Bahasa Melayu Bân-lâm-gú Basa Jawa Baso Minangkabau bosanski brezhoneg català čeština dansk Deutsch eesti English español Esperanto estremeñu euskara français Frysk Gaeilge Gàidhlig galego Hausa hrvatski Igbo interlingua Interlingue isiXhosa isiZulu íslenska italiano Kiswahili Kreyòl ayisyen kréyòl gwadloupéyen Kurdî latviešu Lëtzebuergesch lietuvių magyar Malagasy Malti Nederlands Nedersaksies norsk bokmål norsk nynorsk occitan Oromoo oʻzbekcha/ўзбекча Plattdüütsch polski português português do Brasil română shqip slovenčina slovenščina Soomaaliga suomi svenska Tiếng Việt Türkçe Vahcuengh vèneto Wolof Yorùbá Zazaki српски / srpski беларуская български қазақша македонски монгол русский тоҷикӣ українська Ελληνικά Հայերեն ქართული नेपाली मराठी हिन्दी অসমীয়া বাংলা ਪੰਜਾਬੀ ગુજરાતી ଓଡ଼ିଆ தமிழ் తెలుగు ಕನ್ನಡ മലയാളം සිංහල ไทย မြန်မာဘာသာ ລາວ ភាសាខ្មែរ ⵜⴰⵎⴰⵣⵉⵖⵜ አማርኛ 한국어 日本語 中文(简体)‎ 吴语 粵語 中文(繁體)‎ ייִדיש עברית اردو العربية پښتو سنڌي فارسی ދިވެހިބަސް

OSM Binary Format

This is an alternative to the xml format commonly used for distribution of OSM map data. There are also a set of related additions for use in a mobile context OSM Mobile Binary Protocol.

Note that this format is rarely used as a general purpose binary format, for which PBF Format is preferred.

It is not related to OSMbin.

The Format

The formats base structure is a series of binary blocks, which specify their length followed by a type followed by encoded data.

  • Length - 32bit unsigned integer length (length does not include the 4 bytes used to specify the length)
  • Type - 8bit unsigned integer type (as defined in Types)
  • Data - binary data any format

To save space long/lat values are encoded as 32bit signed integers from the floating point values to six decimal places (eg lat/lon * 1000000). This gives ~11cm accuracy which is plenty for any mapping project. Time/Date fields are the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). Strings are truncated to 255 and are given as a length followed by characters utf8 encoded.

OSM nodes are not transmitted in their entirety, only interesting nodes are included, (nodes with some additional meta data - poi's).

Ways reduce the data needed to be transmitted by only sending the positions of nodes as long/lat pairs, the first long/lat pair using 32bits then subsequent ones are 16bit diffs from the previous node position, if the diff is too big then fake nodes filling the gap are given.

Header

[block length=0x02 0x00 0x00 0x00] 0x05 0x3B

This is an optional 6 byte header at the beginning of an OSM Binary format file. (decided because: 0=O, 5=S, 3=M, B=B)

This just indicates that the content is obf for use in file type recognisers and such.

POIs

  • Length (32bit)
  • Type - 'i' (8bit)
  • Node Id (64bit)
  • Longitude (32bit)
  • Latitude (32bit)
  • Primary property (8bit) see Node Property
  • Feature Tags (optional) see Feature Tags

Ways

  • Length (32bit)
  • Type - 'w' (8bit)
  • Way Id (32bit)
  • Node Count (32bit)
  • Longitude (32bit)
  • Latitude (32bit)
  • Followed by:
    • Longitude Diff (16bit)
    • Latitude Diff (16bit)
  • Feature Tags see Feature Tags

Relations

  • Length (32bit)
  • Type - 'r' (8bit)
  • Relation Id (32bit)
  • Relation Type (8bit) see Relations Types
  • Members Count (32bit)
  • Followed by:
    • Member Type/Role (8bit) see Relations Roles
    • Member Id (32bit way id/64bit poi id) (repeated as necessary)
  • Feature Tags see Feature Tags

Usage and intended use

The OSM binary format is intended for the following types of clients:

  • mapping programs

It is not intended for:

It is optimized for:

  • general usage

This format is supported by the following clients: