2013-01-28 10:55:34 +04:00
|
|
|
package element
|
|
|
|
|
2013-05-15 11:49:38 +04:00
|
|
|
import (
|
|
|
|
"goposm/geom/geos"
|
|
|
|
)
|
|
|
|
|
2013-01-28 10:55:34 +04:00
|
|
|
type Tags map[string]string
|
|
|
|
|
|
|
|
type OSMElem struct {
|
2013-02-12 22:45:49 +04:00
|
|
|
Id int64
|
2013-01-28 10:55:34 +04:00
|
|
|
Tags Tags
|
2013-05-15 11:49:38 +04:00
|
|
|
Geom *Geometry
|
2013-01-28 10:55:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
type Node struct {
|
2013-04-03 00:07:27 +04:00
|
|
|
OSMElem
|
2013-01-28 10:55:34 +04:00
|
|
|
Lat float64
|
|
|
|
Long float64
|
|
|
|
}
|
|
|
|
|
|
|
|
type Way struct {
|
2013-04-03 00:07:27 +04:00
|
|
|
OSMElem
|
2013-04-24 00:30:41 +04:00
|
|
|
Refs []int64
|
|
|
|
Nodes []Node
|
2013-05-15 11:49:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
type Geometry struct {
|
|
|
|
Geom *geos.Geom
|
|
|
|
Wkb []byte
|
2013-01-28 10:55:34 +04:00
|
|
|
}
|
|
|
|
|
2013-05-13 17:19:39 +04:00
|
|
|
func (w *Way) IsClosed() bool {
|
|
|
|
return len(w.Refs) >= 4 && w.Refs[0] == w.Refs[len(w.Refs)-1]
|
|
|
|
}
|
|
|
|
|
2013-01-28 10:55:34 +04:00
|
|
|
type MemberType int
|
|
|
|
|
|
|
|
const (
|
2013-04-03 00:07:27 +04:00
|
|
|
NODE MemberType = 0
|
|
|
|
WAY = 1
|
|
|
|
RELATION = 2
|
2013-01-28 10:55:34 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
type Member struct {
|
2013-02-12 22:45:49 +04:00
|
|
|
Id int64
|
2013-01-28 10:55:34 +04:00
|
|
|
Type MemberType
|
|
|
|
Role string
|
2013-05-16 14:17:21 +04:00
|
|
|
Way *Way
|
2013-01-28 10:55:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
type Relation struct {
|
2013-04-03 00:07:27 +04:00
|
|
|
OSMElem
|
2013-01-28 10:55:34 +04:00
|
|
|
Members []Member
|
|
|
|
}
|
2013-04-03 00:07:27 +04:00
|
|
|
|
|
|
|
func (elem *OSMElem) TagsFromArray(arr []string) {
|
|
|
|
result := make(Tags)
|
|
|
|
for i := 0; i < len(arr); i += 2 {
|
|
|
|
result[arr[i]] = arr[i+1]
|
|
|
|
}
|
|
|
|
elem.Tags = result
|
|
|
|
}
|
|
|
|
|
|
|
|
func (elem *OSMElem) TagsAsArray() []string {
|
|
|
|
result := make([]string, 0, 2*len(elem.Tags))
|
|
|
|
for key, val := range elem.Tags {
|
|
|
|
result = append(result, key, val)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|