From 0cf5b901201641e0619fea3d6fafb510dd891c76 Mon Sep 17 00:00:00 2001 From: Oliver Tonnhofer Date: Mon, 6 May 2013 07:29:43 +0200 Subject: [PATCH] add osmpbf package --- osmpbf/fileformat.pb.go | 97 +++++++++ osmpbf/fileformat.proto | 54 +++++ osmpbf/osmformat.pb.go | 444 ++++++++++++++++++++++++++++++++++++++++ osmpbf/osmformat.proto | 260 +++++++++++++++++++++++ parser/lowlevel.go | 2 +- parser/pbf.go | 2 +- 6 files changed, 857 insertions(+), 2 deletions(-) create mode 100644 osmpbf/fileformat.pb.go create mode 100644 osmpbf/fileformat.proto create mode 100644 osmpbf/osmformat.pb.go create mode 100644 osmpbf/osmformat.proto diff --git a/osmpbf/fileformat.pb.go b/osmpbf/fileformat.pb.go new file mode 100644 index 0000000..bdca8ee --- /dev/null +++ b/osmpbf/fileformat.pb.go @@ -0,0 +1,97 @@ +// Code generated by protoc-gen-go. +// source: fileformat.proto +// DO NOT EDIT! + +package osmpbf + +import proto "code.google.com/p/goprotobuf/proto" +import json "encoding/json" +import math "math" + +// Reference proto, json, and math imports to suppress error if they are not otherwise used. +var _ = proto.Marshal +var _ = &json.SyntaxError{} +var _ = math.Inf + +type Blob struct { + Raw []byte `protobuf:"bytes,1,opt,name=raw" json:"raw,omitempty"` + RawSize *int32 `protobuf:"varint,2,opt,name=raw_size" json:"raw_size,omitempty"` + ZlibData []byte `protobuf:"bytes,3,opt,name=zlib_data" json:"zlib_data,omitempty"` + LzmaData []byte `protobuf:"bytes,4,opt,name=lzma_data" json:"lzma_data,omitempty"` + OBSOLETEBzip2Data []byte `protobuf:"bytes,5,opt,name=OBSOLETE_bzip2_data" json:"OBSOLETE_bzip2_data,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *Blob) Reset() { *this = Blob{} } +func (this *Blob) String() string { return proto.CompactTextString(this) } +func (*Blob) ProtoMessage() {} + +func (this *Blob) GetRaw() []byte { + if this != nil { + return this.Raw + } + return nil +} + +func (this *Blob) GetRawSize() int32 { + if this != nil && this.RawSize != nil { + return *this.RawSize + } + return 0 +} + +func (this *Blob) GetZlibData() []byte { + if this != nil { + return this.ZlibData + } + return nil +} + +func (this *Blob) GetLzmaData() []byte { + if this != nil { + return this.LzmaData + } + return nil +} + +func (this *Blob) GetOBSOLETEBzip2Data() []byte { + if this != nil { + return this.OBSOLETEBzip2Data + } + return nil +} + +type BlobHeader struct { + Type *string `protobuf:"bytes,1,req,name=type" json:"type,omitempty"` + Indexdata []byte `protobuf:"bytes,2,opt,name=indexdata" json:"indexdata,omitempty"` + Datasize *int32 `protobuf:"varint,3,req,name=datasize" json:"datasize,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *BlobHeader) Reset() { *this = BlobHeader{} } +func (this *BlobHeader) String() string { return proto.CompactTextString(this) } +func (*BlobHeader) ProtoMessage() {} + +func (this *BlobHeader) GetType() string { + if this != nil && this.Type != nil { + return *this.Type + } + return "" +} + +func (this *BlobHeader) GetIndexdata() []byte { + if this != nil { + return this.Indexdata + } + return nil +} + +func (this *BlobHeader) GetDatasize() int32 { + if this != nil && this.Datasize != nil { + return *this.Datasize + } + return 0 +} + +func init() { +} diff --git a/osmpbf/fileformat.proto b/osmpbf/fileformat.proto new file mode 100644 index 0000000..0f4235b --- /dev/null +++ b/osmpbf/fileformat.proto @@ -0,0 +1,54 @@ +/** Copyright (c) 2010 Scott A. Crosby. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . + +*/ + +option optimize_for = LITE_RUNTIME; +option java_package = "crosby.binary"; +package osmpbf; + +//protoc --java_out=../.. fileformat.proto + + +// +// STORAGE LAYER: Storing primitives. +// + +message Blob { + optional bytes raw = 1; // No compression + optional int32 raw_size = 2; // When compressed, the uncompressed size + + // Possible compressed versions of the data. + optional bytes zlib_data = 3; + + // PROPOSED feature for LZMA compressed data. SUPPORT IS NOT REQUIRED. + optional bytes lzma_data = 4; + + // Formerly used for bzip2 compressed data. Depreciated in 2010. + optional bytes OBSOLETE_bzip2_data = 5 [deprecated=true]; // Don't reuse this tag number. +} + +/* A file contains an sequence of fileblock headers, each prefixed by +their length in network byte order, followed by a data block +containing the actual data. types staring with a "_" are reserved. +*/ + +message BlobHeader { + required string type = 1; + optional bytes indexdata = 2; + required int32 datasize = 3; +} + + diff --git a/osmpbf/osmformat.pb.go b/osmpbf/osmformat.pb.go new file mode 100644 index 0000000..6ef0862 --- /dev/null +++ b/osmpbf/osmformat.pb.go @@ -0,0 +1,444 @@ +// Code generated by protoc-gen-go. +// source: osmformat.proto +// DO NOT EDIT! + +package osmpbf + +import proto "code.google.com/p/goprotobuf/proto" +import json "encoding/json" +import math "math" + +// Reference proto, json, and math imports to suppress error if they are not otherwise used. +var _ = proto.Marshal +var _ = &json.SyntaxError{} +var _ = math.Inf + +type Relation_MemberType int32 + +const ( + Relation_NODE Relation_MemberType = 0 + Relation_WAY Relation_MemberType = 1 + Relation_RELATION Relation_MemberType = 2 +) + +var Relation_MemberType_name = map[int32]string{ + 0: "NODE", + 1: "WAY", + 2: "RELATION", +} +var Relation_MemberType_value = map[string]int32{ + "NODE": 0, + "WAY": 1, + "RELATION": 2, +} + +func (x Relation_MemberType) Enum() *Relation_MemberType { + p := new(Relation_MemberType) + *p = x + return p +} +func (x Relation_MemberType) String() string { + return proto.EnumName(Relation_MemberType_name, int32(x)) +} +func (x Relation_MemberType) MarshalJSON() ([]byte, error) { + return json.Marshal(x.String()) +} +func (x *Relation_MemberType) UnmarshalJSON(data []byte) error { + value, err := proto.UnmarshalJSONEnum(Relation_MemberType_value, data, "Relation_MemberType") + if err != nil { + return err + } + *x = Relation_MemberType(value) + return nil +} + +type HeaderBlock struct { + Bbox *HeaderBBox `protobuf:"bytes,1,opt,name=bbox" json:"bbox,omitempty"` + RequiredFeatures []string `protobuf:"bytes,4,rep,name=required_features" json:"required_features,omitempty"` + OptionalFeatures []string `protobuf:"bytes,5,rep,name=optional_features" json:"optional_features,omitempty"` + Writingprogram *string `protobuf:"bytes,16,opt,name=writingprogram" json:"writingprogram,omitempty"` + Source *string `protobuf:"bytes,17,opt,name=source" json:"source,omitempty"` + OsmosisReplicationTimestamp *int64 `protobuf:"varint,32,opt,name=osmosis_replication_timestamp" json:"osmosis_replication_timestamp,omitempty"` + OsmosisReplicationSequenceNumber *int64 `protobuf:"varint,33,opt,name=osmosis_replication_sequence_number" json:"osmosis_replication_sequence_number,omitempty"` + OsmosisReplicationBaseUrl *string `protobuf:"bytes,34,opt,name=osmosis_replication_base_url" json:"osmosis_replication_base_url,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *HeaderBlock) Reset() { *this = HeaderBlock{} } +func (this *HeaderBlock) String() string { return proto.CompactTextString(this) } +func (*HeaderBlock) ProtoMessage() {} + +func (this *HeaderBlock) GetBbox() *HeaderBBox { + if this != nil { + return this.Bbox + } + return nil +} + +func (this *HeaderBlock) GetWritingprogram() string { + if this != nil && this.Writingprogram != nil { + return *this.Writingprogram + } + return "" +} + +func (this *HeaderBlock) GetSource() string { + if this != nil && this.Source != nil { + return *this.Source + } + return "" +} + +func (this *HeaderBlock) GetOsmosisReplicationTimestamp() int64 { + if this != nil && this.OsmosisReplicationTimestamp != nil { + return *this.OsmosisReplicationTimestamp + } + return 0 +} + +func (this *HeaderBlock) GetOsmosisReplicationSequenceNumber() int64 { + if this != nil && this.OsmosisReplicationSequenceNumber != nil { + return *this.OsmosisReplicationSequenceNumber + } + return 0 +} + +func (this *HeaderBlock) GetOsmosisReplicationBaseUrl() string { + if this != nil && this.OsmosisReplicationBaseUrl != nil { + return *this.OsmosisReplicationBaseUrl + } + return "" +} + +type HeaderBBox struct { + Left *int64 `protobuf:"zigzag64,1,req,name=left" json:"left,omitempty"` + Right *int64 `protobuf:"zigzag64,2,req,name=right" json:"right,omitempty"` + Top *int64 `protobuf:"zigzag64,3,req,name=top" json:"top,omitempty"` + Bottom *int64 `protobuf:"zigzag64,4,req,name=bottom" json:"bottom,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *HeaderBBox) Reset() { *this = HeaderBBox{} } +func (this *HeaderBBox) String() string { return proto.CompactTextString(this) } +func (*HeaderBBox) ProtoMessage() {} + +func (this *HeaderBBox) GetLeft() int64 { + if this != nil && this.Left != nil { + return *this.Left + } + return 0 +} + +func (this *HeaderBBox) GetRight() int64 { + if this != nil && this.Right != nil { + return *this.Right + } + return 0 +} + +func (this *HeaderBBox) GetTop() int64 { + if this != nil && this.Top != nil { + return *this.Top + } + return 0 +} + +func (this *HeaderBBox) GetBottom() int64 { + if this != nil && this.Bottom != nil { + return *this.Bottom + } + return 0 +} + +type PrimitiveBlock struct { + Stringtable *StringTable `protobuf:"bytes,1,req,name=stringtable" json:"stringtable,omitempty"` + Primitivegroup []*PrimitiveGroup `protobuf:"bytes,2,rep,name=primitivegroup" json:"primitivegroup,omitempty"` + Granularity *int32 `protobuf:"varint,17,opt,name=granularity,def=100" json:"granularity,omitempty"` + LatOffset *int64 `protobuf:"varint,19,opt,name=lat_offset,def=0" json:"lat_offset,omitempty"` + LonOffset *int64 `protobuf:"varint,20,opt,name=lon_offset,def=0" json:"lon_offset,omitempty"` + DateGranularity *int32 `protobuf:"varint,18,opt,name=date_granularity,def=1000" json:"date_granularity,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *PrimitiveBlock) Reset() { *this = PrimitiveBlock{} } +func (this *PrimitiveBlock) String() string { return proto.CompactTextString(this) } +func (*PrimitiveBlock) ProtoMessage() {} + +const Default_PrimitiveBlock_Granularity int32 = 100 +const Default_PrimitiveBlock_LatOffset int64 = 0 +const Default_PrimitiveBlock_LonOffset int64 = 0 +const Default_PrimitiveBlock_DateGranularity int32 = 1000 + +func (this *PrimitiveBlock) GetStringtable() *StringTable { + if this != nil { + return this.Stringtable + } + return nil +} + +func (this *PrimitiveBlock) GetGranularity() int32 { + if this != nil && this.Granularity != nil { + return *this.Granularity + } + return Default_PrimitiveBlock_Granularity +} + +func (this *PrimitiveBlock) GetLatOffset() int64 { + if this != nil && this.LatOffset != nil { + return *this.LatOffset + } + return Default_PrimitiveBlock_LatOffset +} + +func (this *PrimitiveBlock) GetLonOffset() int64 { + if this != nil && this.LonOffset != nil { + return *this.LonOffset + } + return Default_PrimitiveBlock_LonOffset +} + +func (this *PrimitiveBlock) GetDateGranularity() int32 { + if this != nil && this.DateGranularity != nil { + return *this.DateGranularity + } + return Default_PrimitiveBlock_DateGranularity +} + +type PrimitiveGroup struct { + Nodes []*Node `protobuf:"bytes,1,rep,name=nodes" json:"nodes,omitempty"` + Dense *DenseNodes `protobuf:"bytes,2,opt,name=dense" json:"dense,omitempty"` + Ways []*Way `protobuf:"bytes,3,rep,name=ways" json:"ways,omitempty"` + Relations []*Relation `protobuf:"bytes,4,rep,name=relations" json:"relations,omitempty"` + Changesets []*ChangeSet `protobuf:"bytes,5,rep,name=changesets" json:"changesets,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *PrimitiveGroup) Reset() { *this = PrimitiveGroup{} } +func (this *PrimitiveGroup) String() string { return proto.CompactTextString(this) } +func (*PrimitiveGroup) ProtoMessage() {} + +func (this *PrimitiveGroup) GetDense() *DenseNodes { + if this != nil { + return this.Dense + } + return nil +} + +type StringTable struct { + S [][]byte `protobuf:"bytes,1,rep,name=s" json:"s,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *StringTable) Reset() { *this = StringTable{} } +func (this *StringTable) String() string { return proto.CompactTextString(this) } +func (*StringTable) ProtoMessage() {} + +type Info struct { + Version *int32 `protobuf:"varint,1,opt,name=version,def=-1" json:"version,omitempty"` + Timestamp *int64 `protobuf:"varint,2,opt,name=timestamp" json:"timestamp,omitempty"` + Changeset *int64 `protobuf:"varint,3,opt,name=changeset" json:"changeset,omitempty"` + Uid *int32 `protobuf:"varint,4,opt,name=uid" json:"uid,omitempty"` + UserSid *uint32 `protobuf:"varint,5,opt,name=user_sid" json:"user_sid,omitempty"` + Visible *bool `protobuf:"varint,6,opt,name=visible" json:"visible,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *Info) Reset() { *this = Info{} } +func (this *Info) String() string { return proto.CompactTextString(this) } +func (*Info) ProtoMessage() {} + +const Default_Info_Version int32 = -1 + +func (this *Info) GetVersion() int32 { + if this != nil && this.Version != nil { + return *this.Version + } + return Default_Info_Version +} + +func (this *Info) GetTimestamp() int64 { + if this != nil && this.Timestamp != nil { + return *this.Timestamp + } + return 0 +} + +func (this *Info) GetChangeset() int64 { + if this != nil && this.Changeset != nil { + return *this.Changeset + } + return 0 +} + +func (this *Info) GetUid() int32 { + if this != nil && this.Uid != nil { + return *this.Uid + } + return 0 +} + +func (this *Info) GetUserSid() uint32 { + if this != nil && this.UserSid != nil { + return *this.UserSid + } + return 0 +} + +func (this *Info) GetVisible() bool { + if this != nil && this.Visible != nil { + return *this.Visible + } + return false +} + +type DenseInfo struct { + Version []int32 `protobuf:"varint,1,rep,packed,name=version" json:"version,omitempty"` + Timestamp []int64 `protobuf:"zigzag64,2,rep,packed,name=timestamp" json:"timestamp,omitempty"` + Changeset []int64 `protobuf:"zigzag64,3,rep,packed,name=changeset" json:"changeset,omitempty"` + Uid []int32 `protobuf:"zigzag32,4,rep,packed,name=uid" json:"uid,omitempty"` + UserSid []int32 `protobuf:"zigzag32,5,rep,packed,name=user_sid" json:"user_sid,omitempty"` + Visible []bool `protobuf:"varint,6,rep,packed,name=visible" json:"visible,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *DenseInfo) Reset() { *this = DenseInfo{} } +func (this *DenseInfo) String() string { return proto.CompactTextString(this) } +func (*DenseInfo) ProtoMessage() {} + +type ChangeSet struct { + Id *int64 `protobuf:"varint,1,req,name=id" json:"id,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *ChangeSet) Reset() { *this = ChangeSet{} } +func (this *ChangeSet) String() string { return proto.CompactTextString(this) } +func (*ChangeSet) ProtoMessage() {} + +func (this *ChangeSet) GetId() int64 { + if this != nil && this.Id != nil { + return *this.Id + } + return 0 +} + +type Node struct { + Id *int64 `protobuf:"zigzag64,1,req,name=id" json:"id,omitempty"` + Keys []uint32 `protobuf:"varint,2,rep,packed,name=keys" json:"keys,omitempty"` + Vals []uint32 `protobuf:"varint,3,rep,packed,name=vals" json:"vals,omitempty"` + Info *Info `protobuf:"bytes,4,opt,name=info" json:"info,omitempty"` + Lat *int64 `protobuf:"zigzag64,8,req,name=lat" json:"lat,omitempty"` + Lon *int64 `protobuf:"zigzag64,9,req,name=lon" json:"lon,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *Node) Reset() { *this = Node{} } +func (this *Node) String() string { return proto.CompactTextString(this) } +func (*Node) ProtoMessage() {} + +func (this *Node) GetId() int64 { + if this != nil && this.Id != nil { + return *this.Id + } + return 0 +} + +func (this *Node) GetInfo() *Info { + if this != nil { + return this.Info + } + return nil +} + +func (this *Node) GetLat() int64 { + if this != nil && this.Lat != nil { + return *this.Lat + } + return 0 +} + +func (this *Node) GetLon() int64 { + if this != nil && this.Lon != nil { + return *this.Lon + } + return 0 +} + +type DenseNodes struct { + Id []int64 `protobuf:"zigzag64,1,rep,packed,name=id" json:"id,omitempty"` + Denseinfo *DenseInfo `protobuf:"bytes,5,opt,name=denseinfo" json:"denseinfo,omitempty"` + Lat []int64 `protobuf:"zigzag64,8,rep,packed,name=lat" json:"lat,omitempty"` + Lon []int64 `protobuf:"zigzag64,9,rep,packed,name=lon" json:"lon,omitempty"` + KeysVals []int32 `protobuf:"varint,10,rep,packed,name=keys_vals" json:"keys_vals,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *DenseNodes) Reset() { *this = DenseNodes{} } +func (this *DenseNodes) String() string { return proto.CompactTextString(this) } +func (*DenseNodes) ProtoMessage() {} + +func (this *DenseNodes) GetDenseinfo() *DenseInfo { + if this != nil { + return this.Denseinfo + } + return nil +} + +type Way struct { + Id *int64 `protobuf:"varint,1,req,name=id" json:"id,omitempty"` + Keys []uint32 `protobuf:"varint,2,rep,packed,name=keys" json:"keys,omitempty"` + Vals []uint32 `protobuf:"varint,3,rep,packed,name=vals" json:"vals,omitempty"` + Info *Info `protobuf:"bytes,4,opt,name=info" json:"info,omitempty"` + Refs []int64 `protobuf:"zigzag64,8,rep,packed,name=refs" json:"refs,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *Way) Reset() { *this = Way{} } +func (this *Way) String() string { return proto.CompactTextString(this) } +func (*Way) ProtoMessage() {} + +func (this *Way) GetId() int64 { + if this != nil && this.Id != nil { + return *this.Id + } + return 0 +} + +func (this *Way) GetInfo() *Info { + if this != nil { + return this.Info + } + return nil +} + +type Relation struct { + Id *int64 `protobuf:"varint,1,req,name=id" json:"id,omitempty"` + Keys []uint32 `protobuf:"varint,2,rep,packed,name=keys" json:"keys,omitempty"` + Vals []uint32 `protobuf:"varint,3,rep,packed,name=vals" json:"vals,omitempty"` + Info *Info `protobuf:"bytes,4,opt,name=info" json:"info,omitempty"` + RolesSid []int32 `protobuf:"varint,8,rep,packed,name=roles_sid" json:"roles_sid,omitempty"` + Memids []int64 `protobuf:"zigzag64,9,rep,packed,name=memids" json:"memids,omitempty"` + Types []Relation_MemberType `protobuf:"varint,10,rep,packed,name=types,enum=goposm.Relation_MemberType" json:"types,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (this *Relation) Reset() { *this = Relation{} } +func (this *Relation) String() string { return proto.CompactTextString(this) } +func (*Relation) ProtoMessage() {} + +func (this *Relation) GetId() int64 { + if this != nil && this.Id != nil { + return *this.Id + } + return 0 +} + +func (this *Relation) GetInfo() *Info { + if this != nil { + return this.Info + } + return nil +} + +func init() { + proto.RegisterEnum("goposm.Relation_MemberType", Relation_MemberType_name, Relation_MemberType_value) +} diff --git a/osmpbf/osmformat.proto b/osmpbf/osmformat.proto new file mode 100644 index 0000000..bde09f8 --- /dev/null +++ b/osmpbf/osmformat.proto @@ -0,0 +1,260 @@ +/** Copyright (c) 2010 Scott A. Crosby. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . + +*/ + +option optimize_for = LITE_RUNTIME; +option java_package = "crosby.binary"; +package osmpbf; + +/* OSM Binary file format + +This is the master schema file of the OSM binary file format. This +file is designed to support limited random-access and future +extendability. + +A binary OSM file consists of a sequence of FileBlocks (please see +fileformat.proto). The first fileblock contains a serialized instance +of HeaderBlock, followed by a sequence of PrimitiveBlock blocks that +contain the primitives. + +Each primitiveblock is designed to be independently parsable. It +contains a string table storing all strings in that block (keys and +values in tags, roles in relations, usernames, etc.) as well as +metadata containing the precision of coordinates or timestamps in that +block. + +A primitiveblock contains a sequence of primitive groups, each +containing primitives of the same type (nodes, densenodes, ways, +relations). Coordinates are stored in signed 64-bit integers. Lat&lon +are measured in units nanodegrees. The default of +granularity of 100 nanodegrees corresponds to about 1cm on the ground, +and a full lat or lon fits into 32 bits. + +Converting an integer to a lattitude or longitude uses the formula: +$OUT = IN * granularity / 10**9$. Many encoding schemes use delta +coding when representing nodes and relations. + +*/ + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +/* Contains the file header. */ + +message HeaderBlock { + optional HeaderBBox bbox = 1; + /* Additional tags to aid in parsing this dataset */ + repeated string required_features = 4; + repeated string optional_features = 5; + + optional string writingprogram = 16; + optional string source = 17; // From the bbox field. + + /* Tags that allow continuing an Osmosis replication */ + + // replication timestamp, expressed in seconds since the epoch, + // otherwise the same value as in the "timestamp=..." field + // in the state.txt file used by Osmosis + optional int64 osmosis_replication_timestamp = 32; + + // replication sequence number (sequenceNumber in state.txt) + optional int64 osmosis_replication_sequence_number = 33; + + // replication base URL (from Osmosis' configuration.txt file) + optional string osmosis_replication_base_url = 34; +} + + +/** The bounding box field in the OSM header. BBOX, as used in the OSM +header. Units are always in nanodegrees -- they do not obey +granularity rules. */ + +message HeaderBBox { + required sint64 left = 1; + required sint64 right = 2; + required sint64 top = 3; + required sint64 bottom = 4; +} + + +/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// + + +message PrimitiveBlock { + required StringTable stringtable = 1; + repeated PrimitiveGroup primitivegroup = 2; + + // Granularity, units of nanodegrees, used to store coordinates in this block + optional int32 granularity = 17 [default=100]; + // Offset value between the output coordinates coordinates and the granularity grid in unites of nanodegrees. + optional int64 lat_offset = 19 [default=0]; + optional int64 lon_offset = 20 [default=0]; + +// Granularity of dates, normally represented in units of milliseconds since the 1970 epoch. + optional int32 date_granularity = 18 [default=1000]; + + + // Proposed extension: + //optional BBox bbox = XX; +} + +// Group of OSMPrimitives. All primitives in a group must be the same type. +message PrimitiveGroup { + repeated Node nodes = 1; + optional DenseNodes dense = 2; + repeated Way ways = 3; + repeated Relation relations = 4; + repeated ChangeSet changesets = 5; +} + + +/** String table, contains the common strings in each block. + + Note that we reserve index '0' as a delimiter, so the entry at that + index in the table is ALWAYS blank and unused. + + */ +message StringTable { + repeated bytes s = 1; +} + +/* Optional metadata that may be included into each primitive. */ +message Info { + optional int32 version = 1 [default = -1]; + optional int64 timestamp = 2; + optional int64 changeset = 3; + optional int32 uid = 4; + optional uint32 user_sid = 5; // String IDs + + // The visible flag is used to store history information. It indicates that + // the current object version has been created by a delete operation on the + // OSM API. + // When a writer sets this flag, it MUST add a required_features tag with + // value "HistoricalInformation" to the HeaderBlock. + // If this flag is not available for some object it MUST be assumed to be + // true if the file has the required_features tag "HistoricalInformation" + // set. + optional bool visible = 6; +} + +/** Optional metadata that may be included into each primitive. Special dense format used in DenseNodes. */ +message DenseInfo { + repeated int32 version = 1 [packed = true]; + repeated sint64 timestamp = 2 [packed = true]; // DELTA coded + repeated sint64 changeset = 3 [packed = true]; // DELTA coded + repeated sint32 uid = 4 [packed = true]; // DELTA coded + repeated sint32 user_sid = 5 [packed = true]; // String IDs for usernames. DELTA coded + + // The visible flag is used to store history information. It indicates that + // the current object version has been created by a delete operation on the + // OSM API. + // When a writer sets this flag, it MUST add a required_features tag with + // value "HistoricalInformation" to the HeaderBlock. + // If this flag is not available for some object it MUST be assumed to be + // true if the file has the required_features tag "HistoricalInformation" + // set. + repeated bool visible = 6 [packed = true]; +} + + +// THIS IS STUB DESIGN FOR CHANGESETS. NOT USED RIGHT NOW. +// TODO: REMOVE THIS? +message ChangeSet { + required int64 id = 1; +// +// // Parallel arrays. +// repeated uint32 keys = 2 [packed = true]; // String IDs. +// repeated uint32 vals = 3 [packed = true]; // String IDs. +// +// optional Info info = 4; + +// optional int64 created_at = 8; +// optional int64 closetime_delta = 9; +// optional bool open = 10; +// optional HeaderBBox bbox = 11; +} + + +message Node { + required sint64 id = 1; + // Parallel arrays. + repeated uint32 keys = 2 [packed = true]; // String IDs. + repeated uint32 vals = 3 [packed = true]; // String IDs. + + optional Info info = 4; // May be omitted in omitmeta + + required sint64 lat = 8; + required sint64 lon = 9; +} + +/* Used to densly represent a sequence of nodes that do not have any tags. + +We represent these nodes columnwise as five columns: ID's, lats, and +lons, all delta coded. When metadata is not omitted, + +We encode keys & vals for all nodes as a single array of integers +containing key-stringid and val-stringid, using a stringid of 0 as a +delimiter between nodes. + + ( ( )* '0' )* + */ + +message DenseNodes { + repeated sint64 id = 1 [packed = true]; // DELTA coded + + //repeated Info info = 4; + optional DenseInfo denseinfo = 5; + + repeated sint64 lat = 8 [packed = true]; // DELTA coded + repeated sint64 lon = 9 [packed = true]; // DELTA coded + + // Special packing of keys and vals into one array. May be empty if all nodes in this block are tagless. + repeated int32 keys_vals = 10 [packed = true]; +} + + +message Way { + required int64 id = 1; + // Parallel arrays. + repeated uint32 keys = 2 [packed = true]; + repeated uint32 vals = 3 [packed = true]; + + optional Info info = 4; + + repeated sint64 refs = 8 [packed = true]; // DELTA coded +} + +message Relation { + enum MemberType { + NODE = 0; + WAY = 1; + RELATION = 2; + } + required int64 id = 1; + + // Parallel arrays. + repeated uint32 keys = 2 [packed = true]; + repeated uint32 vals = 3 [packed = true]; + + optional Info info = 4; + + // Parallel arrays + repeated int32 roles_sid = 8 [packed = true]; + repeated sint64 memids = 9 [packed = true]; // DELTA encoded + repeated MemberType types = 10 [packed = true]; +} + diff --git a/parser/lowlevel.go b/parser/lowlevel.go index 6f569a8..07e7fe7 100644 --- a/parser/lowlevel.go +++ b/parser/lowlevel.go @@ -5,10 +5,10 @@ import ( "code.google.com/p/goprotobuf/proto" "compress/zlib" structs "encoding/binary" + "goposm/osmpbf" "io" "log" "os" - "osmpbf" ) func ReadPrimitiveBlock(pos BlockPosition) *osmpbf.PrimitiveBlock { diff --git a/parser/pbf.go b/parser/pbf.go index d1410c1..314f767 100644 --- a/parser/pbf.go +++ b/parser/pbf.go @@ -3,9 +3,9 @@ package parser import ( "fmt" "goposm/element" + "goposm/osmpbf" "log" "os" - "osmpbf" ) type PBF struct {