renamed Way.Nodes to Way.Refs
parent
3e2484db26
commit
dfd4c41a0c
|
@ -89,7 +89,7 @@ func UnmarshalNode(data []byte) (node *element.Node, err error) {
|
|||
func MarshalWay(way *element.Way) ([]byte, error) {
|
||||
pbfWay := &model.Way{}
|
||||
pbfWay.Id = &way.Id
|
||||
pbfWay.Nodes = way.Nodes
|
||||
pbfWay.Refs = way.Refs
|
||||
pbfWay.Tags = way.TagsAsArray()
|
||||
return proto.Marshal(pbfWay)
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ func UnmarshalWay(data []byte) (way *element.Way, err error) {
|
|||
|
||||
way = &element.Way{}
|
||||
way.Id = *pbfWay.Id
|
||||
way.Nodes = pbfWay.Nodes
|
||||
way.Refs = pbfWay.Refs
|
||||
way.TagsFromArray(pbfWay.Tags)
|
||||
return way, nil
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ func TestMarshalWay(t *testing.T) {
|
|||
way.Tags = make(element.Tags)
|
||||
way.Tags["name"] = "test"
|
||||
way.Tags["highway"] = "trunk"
|
||||
way.Nodes = append(way.Nodes, 1, 2, 3, 4)
|
||||
way.Refs = append(way.Refs, 1, 2, 3, 4)
|
||||
|
||||
data, _ := MarshalWay(way)
|
||||
way, _ = UnmarshalWay(data)
|
||||
|
@ -68,7 +68,7 @@ func TestMarshalWay(t *testing.T) {
|
|||
t.Error("tags len does not match")
|
||||
}
|
||||
|
||||
if !compareNodes(way.Nodes, []int64{1, 2, 3, 4}) {
|
||||
if !compareNodes(way.Refs, []int64{1, 2, 3, 4}) {
|
||||
t.Error("nodes do not match")
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,10 @@ func TestCreateCache(t *testing.T) {
|
|||
cache_dir, _ := ioutil.TempDir("", "goposm_test")
|
||||
defer os.RemoveAll(cache_dir)
|
||||
|
||||
cache := NewCache(cache_dir)
|
||||
cache, err := NewCoordsCache(cache_dir)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
defer cache.Close()
|
||||
|
||||
if stat, err := os.Stat(cache_dir); err != nil || !stat.IsDir() {
|
||||
|
@ -23,16 +26,22 @@ func TestReadWriteCoord(t *testing.T) {
|
|||
cache_dir, _ := ioutil.TempDir("", "goposm_test")
|
||||
defer os.RemoveAll(cache_dir)
|
||||
|
||||
cache := NewCache(cache_dir)
|
||||
cache, err := NewCoordsCache(cache_dir)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
node := &element.Node{}
|
||||
node.Id = 1
|
||||
cache.PutCoord(node)
|
||||
cache.Close()
|
||||
|
||||
cache = NewCache(cache_dir)
|
||||
cache, err = NewCoordsCache(cache_dir)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
defer cache.Close()
|
||||
|
||||
data := cache.GetCoord(1)
|
||||
data, _ := cache.GetCoord(1)
|
||||
|
||||
if data.Id != 1 {
|
||||
t.Errorf("unexpected result of GetNode(1): %v", data)
|
||||
|
@ -43,7 +52,10 @@ func TestReadWriteNode(t *testing.T) {
|
|||
cache_dir, _ := ioutil.TempDir("", "goposm_test")
|
||||
defer os.RemoveAll(cache_dir)
|
||||
|
||||
cache := NewCache(cache_dir)
|
||||
cache, err := NewNodesCache(cache_dir)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
node := &element.Node{
|
||||
OSMElem: element.OSMElem{
|
||||
Id: 1234,
|
||||
|
@ -52,15 +64,18 @@ func TestReadWriteNode(t *testing.T) {
|
|||
cache.PutNode(node)
|
||||
cache.Close()
|
||||
|
||||
cache = NewCache(cache_dir)
|
||||
cache, err = NewNodesCache(cache_dir)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
defer cache.Close()
|
||||
|
||||
data := cache.GetNode(1234)
|
||||
data, err := cache.GetNode(1234)
|
||||
if data.Id != 1234 || data.Tags["foo"] != "bar" {
|
||||
t.Errorf("unexpected result of GetNode: %v", data)
|
||||
}
|
||||
|
||||
data = cache.GetNode(99)
|
||||
data, err = cache.GetNode(99)
|
||||
if data != nil {
|
||||
t.Error("missing node not nil")
|
||||
}
|
||||
|
@ -71,27 +86,33 @@ func TestReadWriteWay(t *testing.T) {
|
|||
cache_dir, _ := ioutil.TempDir("", "goposm_test")
|
||||
defer os.RemoveAll(cache_dir)
|
||||
|
||||
cache := NewCache(cache_dir)
|
||||
cache, err := NewWaysCache(cache_dir)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
way := &element.Way{
|
||||
OSMElem: element.OSMElem{
|
||||
Id: 1234,
|
||||
Tags: element.Tags{"foo": "bar"}},
|
||||
Nodes: []int64{942374923, 23948234},
|
||||
Refs: []int64{942374923, 23948234},
|
||||
}
|
||||
cache.PutWay(way)
|
||||
cache.Close()
|
||||
|
||||
cache = NewCache(cache_dir)
|
||||
cache, err = NewWaysCache(cache_dir)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
defer cache.Close()
|
||||
|
||||
data := cache.GetWay(1234)
|
||||
data, _ := cache.GetWay(1234)
|
||||
|
||||
if data.Id != 1234 || data.Tags["foo"] != "bar" {
|
||||
t.Errorf("unexpected result of GetWay: %#v", data)
|
||||
}
|
||||
if len(data.Nodes) != 2 ||
|
||||
data.Nodes[0] != 942374923 ||
|
||||
data.Nodes[1] != 23948234 {
|
||||
if len(data.Refs) != 2 ||
|
||||
data.Refs[0] != 942374923 ||
|
||||
data.Refs[1] != 23948234 {
|
||||
t.Errorf("unexpected result of GetWay: %#v", data)
|
||||
}
|
||||
}
|
||||
|
@ -100,10 +121,13 @@ func TestReadMissingWay(t *testing.T) {
|
|||
cache_dir, _ := ioutil.TempDir("", "goposm_test")
|
||||
defer os.RemoveAll(cache_dir)
|
||||
|
||||
cache := NewCache(cache_dir)
|
||||
cache, err := NewWaysCache(cache_dir)
|
||||
if err != nil {
|
||||
t.Fatal()
|
||||
}
|
||||
defer cache.Close()
|
||||
|
||||
data := cache.GetWay(1234)
|
||||
data, _ := cache.GetWay(1234)
|
||||
|
||||
if data != nil {
|
||||
t.Errorf("missing way did not return nil")
|
||||
|
@ -115,13 +139,16 @@ func BenchmarkWriteWay(b *testing.B) {
|
|||
cache_dir, _ := ioutil.TempDir("", "goposm_test")
|
||||
defer os.RemoveAll(cache_dir)
|
||||
|
||||
cache := NewCache(cache_dir)
|
||||
cache, err := NewWaysCache(cache_dir)
|
||||
if err != nil {
|
||||
b.Fatal()
|
||||
}
|
||||
defer cache.Close()
|
||||
|
||||
b.StartTimer()
|
||||
way := &element.Way{
|
||||
OSMElem: element.OSMElem{Tags: element.Tags{"foo": "bar"}},
|
||||
Nodes: []int64{942374923, 23948234},
|
||||
Refs: []int64{942374923, 23948234},
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
way.Id = int64(i)
|
||||
|
@ -134,7 +161,10 @@ func BenchmarkReadWay(b *testing.B) {
|
|||
cache_dir, _ := ioutil.TempDir("", "goposm_test")
|
||||
defer os.RemoveAll(cache_dir)
|
||||
|
||||
cache := NewCache(cache_dir)
|
||||
cache, err := NewWaysCache(cache_dir)
|
||||
if err != nil {
|
||||
b.Fatal()
|
||||
}
|
||||
defer cache.Close()
|
||||
|
||||
way := &element.Way{}
|
||||
|
@ -145,7 +175,7 @@ func BenchmarkReadWay(b *testing.B) {
|
|||
|
||||
b.StartTimer()
|
||||
for i := int64(0); i < int64(b.N); i++ {
|
||||
if cache.GetWay(i).Id != i {
|
||||
if coord, err := cache.GetWay(i); err != nil || coord.Id != i {
|
||||
b.Fail()
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +187,10 @@ func BenchmarkWriteCoord(b *testing.B) {
|
|||
cache_dir, _ := ioutil.TempDir("", "goposm_test")
|
||||
defer os.RemoveAll(cache_dir)
|
||||
|
||||
cache := NewCache(cache_dir)
|
||||
cache, err := NewCoordsCache(cache_dir)
|
||||
if err != nil {
|
||||
b.Fatal()
|
||||
}
|
||||
defer cache.Close()
|
||||
|
||||
b.StartTimer()
|
||||
|
@ -173,7 +206,10 @@ func BenchmarkReadCoord(b *testing.B) {
|
|||
cache_dir, _ := ioutil.TempDir("", "goposm_test")
|
||||
defer os.RemoveAll(cache_dir)
|
||||
|
||||
cache := NewCache(cache_dir)
|
||||
cache, err := NewCoordsCache(cache_dir)
|
||||
if err != nil {
|
||||
b.Fatal()
|
||||
}
|
||||
defer cache.Close()
|
||||
|
||||
node := &element.Node{}
|
||||
|
@ -184,7 +220,7 @@ func BenchmarkReadCoord(b *testing.B) {
|
|||
|
||||
b.StartTimer()
|
||||
for i := int64(0); i < int64(b.N); i++ {
|
||||
if cache.GetCoord(i).Id != i {
|
||||
if coord, err := cache.GetCoord(i); err == nil || coord.Id != i {
|
||||
b.Fail()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@ type Node struct {
|
|||
|
||||
type Way struct {
|
||||
OSMElem
|
||||
Nodes []int64
|
||||
Refs []int64
|
||||
Nodes []Node
|
||||
}
|
||||
|
||||
type MemberType int
|
||||
|
|
|
@ -53,7 +53,6 @@ func TestPolygonNotClosed(t *testing.T) {
|
|||
if err == nil {
|
||||
t.Fatal("no error")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkLineString(b *testing.B) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by protoc-gen-go.
|
||||
// source: model.proto
|
||||
// source: model/model.proto
|
||||
// DO NOT EDIT!
|
||||
|
||||
package model
|
||||
|
@ -60,49 +60,70 @@ type Node struct {
|
|||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (this *Node) Reset() { *this = Node{} }
|
||||
func (this *Node) String() string { return proto.CompactTextString(this) }
|
||||
func (*Node) ProtoMessage() {}
|
||||
func (m *Node) Reset() { *m = Node{} }
|
||||
func (m *Node) String() string { return proto.CompactTextString(m) }
|
||||
func (*Node) ProtoMessage() {}
|
||||
|
||||
func (this *Node) GetId() int64 {
|
||||
if this != nil && this.Id != nil {
|
||||
return *this.Id
|
||||
func (m *Node) GetId() int64 {
|
||||
if m != nil && m.Id != nil {
|
||||
return *m.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (this *Node) GetLong() uint32 {
|
||||
if this != nil && this.Long != nil {
|
||||
return *this.Long
|
||||
func (m *Node) GetLong() uint32 {
|
||||
if m != nil && m.Long != nil {
|
||||
return *m.Long
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (this *Node) GetLat() uint32 {
|
||||
if this != nil && this.Lat != nil {
|
||||
return *this.Lat
|
||||
func (m *Node) GetLat() uint32 {
|
||||
if m != nil && m.Lat != nil {
|
||||
return *m.Lat
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Node) GetTags() []string {
|
||||
if m != nil {
|
||||
return m.Tags
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Way struct {
|
||||
Id *int64 `protobuf:"varint,1,req,name=id" json:"id,omitempty"`
|
||||
Tags []string `protobuf:"bytes,2,rep,name=tags" json:"tags,omitempty"`
|
||||
Nodes []int64 `protobuf:"varint,3,rep,packed,name=nodes" json:"nodes,omitempty"`
|
||||
Refs []int64 `protobuf:"varint,3,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 (m *Way) Reset() { *m = Way{} }
|
||||
func (m *Way) String() string { return proto.CompactTextString(m) }
|
||||
func (*Way) ProtoMessage() {}
|
||||
|
||||
func (this *Way) GetId() int64 {
|
||||
if this != nil && this.Id != nil {
|
||||
return *this.Id
|
||||
func (m *Way) GetId() int64 {
|
||||
if m != nil && m.Id != nil {
|
||||
return *m.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Way) GetTags() []string {
|
||||
if m != nil {
|
||||
return m.Tags
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Way) GetRefs() []int64 {
|
||||
if m != nil {
|
||||
return m.Refs
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Relation struct {
|
||||
Id *int64 `protobuf:"varint,1,req,name=id" json:"id,omitempty"`
|
||||
Tags []string `protobuf:"bytes,2,rep,name=tags" json:"tags,omitempty"`
|
||||
|
@ -110,17 +131,31 @@ type Relation struct {
|
|||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (this *Relation) Reset() { *this = Relation{} }
|
||||
func (this *Relation) String() string { return proto.CompactTextString(this) }
|
||||
func (*Relation) ProtoMessage() {}
|
||||
func (m *Relation) Reset() { *m = Relation{} }
|
||||
func (m *Relation) String() string { return proto.CompactTextString(m) }
|
||||
func (*Relation) ProtoMessage() {}
|
||||
|
||||
func (this *Relation) GetId() int64 {
|
||||
if this != nil && this.Id != nil {
|
||||
return *this.Id
|
||||
func (m *Relation) GetId() int64 {
|
||||
if m != nil && m.Id != nil {
|
||||
return *m.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Relation) GetTags() []string {
|
||||
if m != nil {
|
||||
return m.Tags
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Relation) GetMembers() []*RelationMember {
|
||||
if m != nil {
|
||||
return m.Members
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type RelationMember struct {
|
||||
MemberIds *int64 `protobuf:"varint,1,req,name=member_ids" json:"member_ids,omitempty"`
|
||||
MemberTypes *RelationMember_MemberType `protobuf:"varint,2,req,name=member_types,enum=model.RelationMember_MemberType" json:"member_types,omitempty"`
|
||||
|
@ -128,27 +163,27 @@ type RelationMember struct {
|
|||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (this *RelationMember) Reset() { *this = RelationMember{} }
|
||||
func (this *RelationMember) String() string { return proto.CompactTextString(this) }
|
||||
func (*RelationMember) ProtoMessage() {}
|
||||
func (m *RelationMember) Reset() { *m = RelationMember{} }
|
||||
func (m *RelationMember) String() string { return proto.CompactTextString(m) }
|
||||
func (*RelationMember) ProtoMessage() {}
|
||||
|
||||
func (this *RelationMember) GetMemberIds() int64 {
|
||||
if this != nil && this.MemberIds != nil {
|
||||
return *this.MemberIds
|
||||
func (m *RelationMember) GetMemberIds() int64 {
|
||||
if m != nil && m.MemberIds != nil {
|
||||
return *m.MemberIds
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (this *RelationMember) GetMemberTypes() RelationMember_MemberType {
|
||||
if this != nil && this.MemberTypes != nil {
|
||||
return *this.MemberTypes
|
||||
func (m *RelationMember) GetMemberTypes() RelationMember_MemberType {
|
||||
if m != nil && m.MemberTypes != nil {
|
||||
return *m.MemberTypes
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (this *RelationMember) GetMemberRoles() string {
|
||||
if this != nil && this.MemberRoles != nil {
|
||||
return *this.MemberRoles
|
||||
func (m *RelationMember) GetMemberRoles() string {
|
||||
if m != nil && m.MemberRoles != nil {
|
||||
return *m.MemberRoles
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ message Way {
|
|||
required int64 id = 1;
|
||||
|
||||
repeated string tags = 2;
|
||||
repeated int64 nodes = 3 [packed = true];
|
||||
repeated int64 refs = 3 [packed = true];
|
||||
}
|
||||
|
||||
message Relation {
|
||||
|
@ -30,4 +30,4 @@ message RelationMember {
|
|||
}
|
||||
required MemberType member_types = 2;
|
||||
required string member_roles = 3;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ func ReadWays(
|
|||
id := *ways[i].Id
|
||||
result[i].Id = id
|
||||
result[i].Tags = ParseTags(stringtable, ways[i].Keys, ways[i].Vals)
|
||||
result[i].Nodes = ParseDeltaRefs(ways[i].Refs)
|
||||
result[i].Refs = ParseDeltaRefs(ways[i].Refs)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue