Пример #1
0
func (x *DotOSM) parseRelation(id int64) (members []*relation.Member, t *tags.Tags) {
	t = tags.New()
	line, _ := x.nextLine()
	for line != "</relation>" {
		prefix, _, m := x.parseLine(line)
		switch prefix {
		case "<member":
			ref := str2int64(m["ref"])

			member := &relation.Member{Type_: item.ItemTypeFromString(m["type"]), Role: m["role"], Id_: ref}
			switch member.Type() {
			case item.TypeNode:
				member.Ref = x.data.GetNode(ref)
			case item.TypeWay:
				member.Ref = x.data.GetWay(ref)
			case item.TypeRelation:
				member.Ref = x.data.GetRelation(ref)
			}
			if member.Ref == nil {
				log.Printf("WARNING: Missing %s id #%d in relation #%d\n", member.Type(), ref, id)
			}
			members = append(members, member)

		case "<tag":
			t.Add(m["k"], decodeXML(m["v"]))
		default:
			panic("unknown element " + prefix)
		}
		line, _ = x.nextLine()
	}
	return members, t
}
Пример #2
0
func New(p *point.Point) *Node {
	return &Node{
		Position_:  p,
		Id_:        newNodeId(),
		Tags_:      tags.New(),
		Timestamp_: time.Now(),
		Version_:   0,
		Changeset_: 0,
		Visible_:   true,
		User_:      user.New(0, ""),
		modified:   true,
		deleted:    false,
	}
}
Пример #3
0
func NewRelation(m *Member) *Relation {
	return &Relation{
		Members_:   []*Member{m},
		Id_:        newRelationId(),
		Tags_:      tags.New(),
		Timestamp_: time.Now(),
		Version_:   0,
		Changeset_: 0,
		Visible_:   true,
		User_:      &user.User{Id: 0, Name: ""},
		modified:   true,
		deleted:    false,
	}
}
Пример #4
0
func (x *DotOSM) parseTags(s string) *tags.Tags {
	line, _ := x.nextLine()
	eot := "</" + s + ">"
	t := tags.New()
	for line != eot {
		prefix, _, m := x.parseLine(line)
		if prefix != "<tag" {
			panic("Non Tag element found: " + prefix)
		}
		t.Add(m["k"], decodeXML(m["v"]))
		line, _ = x.nextLine()
	}
	return t
}
Пример #5
0
func (w *Way) Clone() (nw *Way, err error) {
	nd := []*node.Node{}
	for _, n := range w.Nodes_ {
		nd = append(nd, n)
	}
	t := tags.New()
	for key := range map[string]string(*w.Tags_) {
		t.Add(key, w.Tags_.Get(key))
	}
	nw, err = New(nd)
	if err != nil {
		nw.Tags_ = t
	}
	return
}
Пример #6
0
// returns a new way, the node slice must have at least two nodes
func New(nl []*node.Node) (w *Way, err error) {
	if len(nl) < 2 {
		return nil, errors.New("Too few nodes for way")
	}
	return &Way{
		Nodes_:     nl,
		Id_:        newWayId(),
		Tags_:      tags.New(),
		Timestamp_: time.Now(),
		Version_:   0,
		Changeset_: 0,
		Visible_:   true,
		User_:      &user.User{Id: 0, Name: ""},
		modified:   true,
		deleted:    false,
	}, nil
}
Пример #7
0
func (x *DotOSM) parseWay(id int64) (t *tags.Tags, n []*node.Node, err error) {
	t = tags.New()
	line, _ := x.nextLine()
	for line != "</way>" {
		prefix, _, m := x.parseLine(line)
		switch prefix {
		case "<nd":
			ref := str2int64(m["ref"])
			nd := x.data.GetNode(ref)
			if nd == nil {
				err = errors.New(fmt.Sprintf("missing node %d in way %d\n", ref, id))
				return
			}
			n = append(n, nd)
		case "<tag":
			t.Add(m["k"], decodeXML(m["v"]))
		default:
			panic("unknown element " + prefix)
		}
		line, _ = x.nextLine()
	}

	return
}