github.com/omniscale/go-osm@v0.3.1/element.go (about)

     1  package osm
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  )
     7  
     8  // A Tags is a collection of key=values, describing the OSM element.
     9  type Tags map[string]string
    10  
    11  func (t *Tags) String() string {
    12  	return fmt.Sprintf("%v", (map[string]string)(*t))
    13  }
    14  
    15  // An Element contains information for nodes, ways and relations.
    16  type Element struct {
    17  	ID       int64
    18  	Tags     Tags
    19  	Metadata *Metadata
    20  }
    21  
    22  // A Matadata contains the optional metadata for each element.
    23  type Metadata struct {
    24  	UserID    int32
    25  	UserName  string
    26  	Version   int32
    27  	Timestamp time.Time
    28  	Changeset int64
    29  }
    30  
    31  // A Node contains lat/long coordinates.
    32  type Node struct {
    33  	Element
    34  	Lat  float64
    35  	Long float64
    36  }
    37  
    38  // A Way references one or more nodes by IDs.
    39  type Way struct {
    40  	Element
    41  	// Refs specifies an ordered list of all node IDs that define this way.
    42  	Refs []int64
    43  	// Nodes specifies an ordered list of the actual nodes. Nodes can be empty
    44  	// if the information is not available (e.g. during parsing).
    45  	Nodes []Node
    46  }
    47  
    48  // IsClosed returns whether the first and last nodes are the same.
    49  func (w *Way) IsClosed() bool {
    50  	return len(w.Refs) >= 4 && w.Refs[0] == w.Refs[len(w.Refs)-1]
    51  }
    52  
    53  type MemberType int
    54  
    55  const (
    56  	NodeMember     MemberType = 0
    57  	WayMember                 = 1
    58  	RelationMember            = 2
    59  )
    60  
    61  // A Relation is a collection of multiple members.
    62  type Relation struct {
    63  	Element
    64  	Members []Member
    65  }
    66  
    67  // A Member contains information about a single relation member.
    68  type Member struct {
    69  	// ID specifies the OpenStreetMap ID of the member. Note that nodes, ways
    70  	// and relations each have their own range of IDs and the IDs are only uniq
    71  	// within their type.
    72  	ID int64
    73  	// Type defines if the member is a Node, Way or Relation.
    74  	Type MemberType
    75  	// Role of the member. Strings like "inner", "outer", "stop", "platform", etc.
    76  	// Interpretation of the role depends on the relation type.
    77  	Role string
    78  	// Way points to the actual Way, if Type is Way.
    79  	// Can be nil if the information is not available (e.g. during parsing).
    80  	Way *Way
    81  	// Node points to the actual Node, if Type is NodeMember.
    82  	// Can be nil if the information is not available (e.g. during parsing).
    83  	Node *Node
    84  	// Element points to the base information valid for all member types.
    85  	// Can be nil if the information is not available (e.g. during parsing).
    86  	Element *Element
    87  }