-
Notifications
You must be signed in to change notification settings - Fork 3
/
osm.go
74 lines (61 loc) · 1.44 KB
/
osm.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
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"encoding/xml"
"os"
)
type XMLTag struct {
Key string `xml:"k,attr"`
Value string `xml:"v,attr"`
}
type XMLMember struct {
Type string `xml:"type,attr"`
Ref int `xml:"ref,attr"`
Role string `xml:"role,attr"`
}
type XMLNode struct {
ID int `xml:"id,attr"`
Version int16 `xml:"version,attr"`
Lat float64 `xml:"lat,attr"`
Lon float64 `xml:"lon,attr"`
Tags []*XMLTag `xml:"tag"`
}
type XMLWay struct {
ID int `xml:"id,attr"`
Version int16 `xml:"version,attr"`
Nodes []struct {
Ref int `xml:"ref,attr"`
} `xml:"nd"`
Tags []*XMLTag `xml:"tag"`
}
type XMLRelation struct {
ID int `xml:"id,attr"`
Members []*XMLMember `xml:"member"`
Tags []*XMLTag `xml:"tag"`
}
type XMLBounds struct {
MinLat float64 `xml:"minlat,attr"`
MinLon float64 `xml:"minlon,attr"`
MaxLat float64 `xml:"maxlat,attr"`
MaxLon float64 `xml:"maxlon,attr"`
}
type XMLOSM struct {
XMLName xml.Name `xml:"osm"`
Version float64 `xml:"version,attr"`
Bounds XMLBounds `xml:"bounds"`
Nodes []*XMLNode `xml:"node"`
Ways []*XMLWay `xml:"way"`
Relations []*XMLRelation `xml:"relation"`
}
func loadXML(filename string) (*XMLOSM, error) {
var xmlData *XMLOSM
fin, err := os.Open(filename)
if err != nil {
return nil, err
}
defer fin.Close()
err = xml.NewDecoder(fin).Decode(&xmlData)
if err != nil {
return nil, err
}
return xmlData, nil
}