OBF Format
The OBF file format is used by OsmAnd to store map data. It is based on PBF (Protocol Buffers) container format. OBF files contain offline GPS vector maps, as well as POIs and address indexes for offline search.
Implementation
This description is based on the source of OsmAnd and a reverse engineering of the obf file bremen.osm.pbf.
Basic types
In the following, we will have a look into the bytes of an OSM PBF file. The regional extract is used as an example.
Every data is preceded by a variable identifier. This identifier consists of type and id; the bits 0 through 2 stand for the type, bits 3 and above for the id. These types May Be used:
0: V (Varint) int32, int64, uint32, uint64, sint32, sint64, bool, enum
1: D (64-bit) fixed64, sfixed64, double
2: S (Length-delimited) string, bytes, embedded messages, packed repeated fields
5: I (32-bit) fixed32, sfixed32, float
6: unsigned int 32-bit in BigEndian order
Definition of the OBF-Header fileblock
message OBF-HeaderGroup {
required Varint version = 1; // kVersionFieldNumber
required Varint Date = 18; // kDateCreatedFieldNumber
repeated TransportIndexField transportindexfield = 4; // kTransportIndexFieldNumber
repeated MapIndexField mapindexfield = 6; // kMapIndexFieldNumber
repeated AddressIndexField addressindexfield = 7; // kAddressIndexFieldNumber
}
00000000 08 02 - Varint 1 - Version number - 2
00000000 __ __ 90 01 D9 99 9C AC 9A 28 - Varint 18 - 'date'
00000000 __ __ __ __ __ __ __ __ __ __ 36 04 02 11 78 - U32 6 - Block MapIndexField - length 0x04021178 bytes
Definition of the MapIndexField fileblock
message MapIndexFieldGroup {
required String name = 2; // kNameFieldNumber
repeated Varint [...] = 4; //
repeated String StringTableValue = 3; //
}
--- MapIndexFieldGroup --->
00000000 12 07 48 75 6E 67 61 72 79 - S 2 - length 7 - 'Hungary'
00000000 __ __ __ __ __ __ __ __ __ 22 0A - Varint 4 - ??? - 0x0A
00000000 __ __ __ __ __ __ __ __ __ __ __ 1A 04 6E 61 6D
00000010 65 - S 3 - 'name'
00000010 __ 48 00 50 02 22 0C 1A 08 │ 62 75 69 6C 64 69 6E
See also
- PBF Protocol Buffers
External links
- The PBF description in OSM wiki
- Encoding Protocol Buffers by Google
- OsmAndMapCreator Java program to create OBF from PBF