forked from paulmach/osm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode_tag.go
63 lines (51 loc) · 1.07 KB
/
decode_tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package osmpbf
import "github.com/paulmach/osm"
func extractTags(stringTable []string, keyIDs, valueIDs []uint32) osm.Tags {
if len(keyIDs) == 0 {
return nil
}
tags := make(osm.Tags, 0, len(keyIDs))
for index, keyID := range keyIDs {
tags = append(tags, osm.Tag{
Key: stringTable[keyID],
Value: stringTable[valueIDs[index]],
})
}
return tags
}
type tagUnpacker struct {
stringTable []string
keysVals []int32
index int
}
// Next creates the tags from the stringtable and array of IDs.
// Used in DenseNodes encoding.
func (tu *tagUnpacker) Next() osm.Tags {
index := tu.index
for index < len(tu.keysVals) {
if tu.keysVals[index] == 0 {
break
}
index += 2
}
count := index - tu.index
if count == 0 {
tu.index++
return nil
}
tags := make(osm.Tags, 0, count/2)
for tu.index < len(tu.keysVals) {
keyID := tu.keysVals[tu.index]
tu.index++
if keyID == 0 {
break
}
valID := tu.keysVals[tu.index]
tu.index++
tags = append(tags, osm.Tag{
Key: tu.stringTable[keyID],
Value: tu.stringTable[valID],
})
}
return tags
}