Exemple #1
0
// implements the osm.Parser interface
func (p *DotOSM) Parse() (o *osm.OSM, err error) {
	// FIXME - parse "<bbox "...
	o = osm.NewOSM()
	p.data = o
	var i item.Item
	var line string
	var isEOF bool
	for {
		line, err = p.nextLine()
		if err == io.EOF {
			isEOF = true
		} else if err != nil {
			return
		}
		if line != "" {
			i, err = p.parseItem(line)
			if err != nil {
				break
			}
			switch i.Type() {
			case item.TypeNode:
				o.Nodes[i.(*node.Node).Id_] = i.(*node.Node)
			case item.TypeWay:
				o.Ways[i.(*way.Way).Id_] = i.(*way.Way)
			case item.TypeRelation:
				o.Relations[i.(*relation.Relation).Id_] = i.(*relation.Relation)
			default:
			}
		}
		if isEOF {
			break
		}
	}
	return
}
Exemple #2
0
func NewMember(role string, i item.Item) *Member {
	switch i.Type() {
	case item.TypeNode:
		return &Member{Type_: i.Type(), Role: role, Ref: i, Id_: i.(*node.Node).Id()}
	case item.TypeWay:
		return &Member{Type_: i.Type(), Role: role, Ref: i, Id_: i.(*way.Way).Id()}
	case item.TypeRelation:
		return &Member{Type_: i.Type(), Role: role, Ref: i, Id_: i.(*Relation).Id()}
	default:
		panic("invalid member type")
	}
}