A Rust library for reading the OpenStreetMap PBF file format (*.osm.pbf).

osmformat.proto 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /** Copyright (c) 2010 Scott A. Crosby. <scott@sacrosby.com>
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU Lesser General Public License as
  4. published by the Free Software Foundation, either version 3 of the
  5. License, or (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU Lesser General Public License for more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. option optimize_for = LITE_RUNTIME;
  14. option java_package = "crosby.binary";
  15. package OSMPBF;
  16. /* OSM Binary file format
  17. This is the master schema file of the OSM binary file format. This
  18. file is designed to support limited random-access and future
  19. extendability.
  20. A binary OSM file consists of a sequence of FileBlocks (please see
  21. fileformat.proto). The first fileblock contains a serialized instance
  22. of HeaderBlock, followed by a sequence of PrimitiveBlock blocks that
  23. contain the primitives.
  24. Each primitiveblock is designed to be independently parsable. It
  25. contains a string table storing all strings in that block (keys and
  26. values in tags, roles in relations, usernames, etc.) as well as
  27. metadata containing the precision of coordinates or timestamps in that
  28. block.
  29. A primitiveblock contains a sequence of primitive groups, each
  30. containing primitives of the same type (nodes, densenodes, ways,
  31. relations). Coordinates are stored in signed 64-bit integers. Lat&lon
  32. are measured in units <granularity> nanodegrees. The default of
  33. granularity of 100 nanodegrees corresponds to about 1cm on the ground,
  34. and a full lat or lon fits into 32 bits.
  35. Converting an integer to a lattitude or longitude uses the formula:
  36. $OUT = IN * granularity / 10**9$. Many encoding schemes use delta
  37. coding when representing nodes and relations.
  38. */
  39. //////////////////////////////////////////////////////////////////////////
  40. //////////////////////////////////////////////////////////////////////////
  41. /* Contains the file header. */
  42. message HeaderBlock {
  43. optional HeaderBBox bbox = 1;
  44. /* Additional tags to aid in parsing this dataset */
  45. repeated string required_features = 4;
  46. repeated string optional_features = 5;
  47. optional string writingprogram = 16;
  48. optional string source = 17; // From the bbox field.
  49. /* Tags that allow continuing an Osmosis replication */
  50. // replication timestamp, expressed in seconds since the epoch,
  51. // otherwise the same value as in the "timestamp=..." field
  52. // in the state.txt file used by Osmosis
  53. optional int64 osmosis_replication_timestamp = 32;
  54. // replication sequence number (sequenceNumber in state.txt)
  55. optional int64 osmosis_replication_sequence_number = 33;
  56. // replication base URL (from Osmosis' configuration.txt file)
  57. optional string osmosis_replication_base_url = 34;
  58. }
  59. /** The bounding box field in the OSM header. BBOX, as used in the OSM
  60. header. Units are always in nanodegrees -- they do not obey
  61. granularity rules. */
  62. message HeaderBBox {
  63. required sint64 left = 1;
  64. required sint64 right = 2;
  65. required sint64 top = 3;
  66. required sint64 bottom = 4;
  67. }
  68. ///////////////////////////////////////////////////////////////////////
  69. ///////////////////////////////////////////////////////////////////////
  70. message PrimitiveBlock {
  71. required StringTable stringtable = 1;
  72. repeated PrimitiveGroup primitivegroup = 2;
  73. // Granularity, units of nanodegrees, used to store coordinates in this block
  74. optional int32 granularity = 17 [default=100];
  75. // Offset value between the output coordinates coordinates and the granularity grid in unites of nanodegrees.
  76. optional int64 lat_offset = 19 [default=0];
  77. optional int64 lon_offset = 20 [default=0];
  78. // Granularity of dates, normally represented in units of milliseconds since the 1970 epoch.
  79. optional int32 date_granularity = 18 [default=1000];
  80. // Proposed extension:
  81. //optional BBox bbox = XX;
  82. }
  83. // Group of OSMPrimitives. All primitives in a group must be the same type.
  84. message PrimitiveGroup {
  85. repeated Node nodes = 1;
  86. optional DenseNodes dense = 2;
  87. repeated Way ways = 3;
  88. repeated Relation relations = 4;
  89. repeated ChangeSet changesets = 5;
  90. }
  91. /** String table, contains the common strings in each block.
  92. Note that we reserve index '0' as a delimiter, so the entry at that
  93. index in the table is ALWAYS blank and unused.
  94. */
  95. message StringTable {
  96. repeated bytes s = 1;
  97. }
  98. /* Optional metadata that may be included into each primitive. */
  99. message Info {
  100. optional int32 version = 1 [default = -1];
  101. optional int64 timestamp = 2;
  102. optional int64 changeset = 3;
  103. optional int32 uid = 4;
  104. optional uint32 user_sid = 5; // String IDs
  105. // The visible flag is used to store history information. It indicates that
  106. // the current object version has been created by a delete operation on the
  107. // OSM API.
  108. // When a writer sets this flag, it MUST add a required_features tag with
  109. // value "HistoricalInformation" to the HeaderBlock.
  110. // If this flag is not available for some object it MUST be assumed to be
  111. // true if the file has the required_features tag "HistoricalInformation"
  112. // set.
  113. optional bool visible = 6;
  114. }
  115. /** Optional metadata that may be included into each primitive. Special dense format used in DenseNodes. */
  116. message DenseInfo {
  117. repeated int32 version = 1 [packed = true];
  118. repeated sint64 timestamp = 2 [packed = true]; // DELTA coded
  119. repeated sint64 changeset = 3 [packed = true]; // DELTA coded
  120. repeated sint32 uid = 4 [packed = true]; // DELTA coded
  121. repeated sint32 user_sid = 5 [packed = true]; // String IDs for usernames. DELTA coded
  122. // The visible flag is used to store history information. It indicates that
  123. // the current object version has been created by a delete operation on the
  124. // OSM API.
  125. // When a writer sets this flag, it MUST add a required_features tag with
  126. // value "HistoricalInformation" to the HeaderBlock.
  127. // If this flag is not available for some object it MUST be assumed to be
  128. // true if the file has the required_features tag "HistoricalInformation"
  129. // set.
  130. repeated bool visible = 6 [packed = true];
  131. }
  132. // THIS IS STUB DESIGN FOR CHANGESETS. NOT USED RIGHT NOW.
  133. // TODO: REMOVE THIS?
  134. message ChangeSet {
  135. required int64 id = 1;
  136. //
  137. // // Parallel arrays.
  138. // repeated uint32 keys = 2 [packed = true]; // String IDs.
  139. // repeated uint32 vals = 3 [packed = true]; // String IDs.
  140. //
  141. // optional Info info = 4;
  142. // optional int64 created_at = 8;
  143. // optional int64 closetime_delta = 9;
  144. // optional bool open = 10;
  145. // optional HeaderBBox bbox = 11;
  146. }
  147. message Node {
  148. required sint64 id = 1;
  149. // Parallel arrays.
  150. repeated uint32 keys = 2 [packed = true]; // String IDs.
  151. repeated uint32 vals = 3 [packed = true]; // String IDs.
  152. optional Info info = 4; // May be omitted in omitmeta
  153. required sint64 lat = 8;
  154. required sint64 lon = 9;
  155. }
  156. /* Used to densly represent a sequence of nodes that do not have any tags.
  157. We represent these nodes columnwise as five columns: ID's, lats, and
  158. lons, all delta coded. When metadata is not omitted,
  159. We encode keys & vals for all nodes as a single array of integers
  160. containing key-stringid and val-stringid, using a stringid of 0 as a
  161. delimiter between nodes.
  162. ( (<keyid> <valid>)* '0' )*
  163. */
  164. message DenseNodes {
  165. repeated sint64 id = 1 [packed = true]; // DELTA coded
  166. //repeated Info info = 4;
  167. optional DenseInfo denseinfo = 5;
  168. repeated sint64 lat = 8 [packed = true]; // DELTA coded
  169. repeated sint64 lon = 9 [packed = true]; // DELTA coded
  170. // Special packing of keys and vals into one array. May be empty if all nodes in this block are tagless.
  171. repeated int32 keys_vals = 10 [packed = true];
  172. }
  173. message Way {
  174. required int64 id = 1;
  175. // Parallel arrays.
  176. repeated uint32 keys = 2 [packed = true];
  177. repeated uint32 vals = 3 [packed = true];
  178. optional Info info = 4;
  179. repeated sint64 refs = 8 [packed = true]; // DELTA coded
  180. }
  181. message Relation {
  182. enum MemberType {
  183. NODE = 0;
  184. WAY = 1;
  185. RELATION = 2;
  186. }
  187. required int64 id = 1;
  188. // Parallel arrays.
  189. repeated uint32 keys = 2 [packed = true];
  190. repeated uint32 vals = 3 [packed = true];
  191. optional Info info = 4;
  192. // Parallel arrays
  193. repeated int32 roles_sid = 8 [packed = true];
  194. repeated sint64 memids = 9 [packed = true]; // DELTA encoded
  195. repeated MemberType types = 10 [packed = true];
  196. }