osm: github.com/paulmach/osm Index | Files | Directories

package osm

import "github.com/paulmach/osm"

Index

Package Files

bounds.go change.go changeset.go datasource.go diff.go element.go feature.go json.go marshal.go node.go note.go object.go osm.go polygon.go relation.go tag.go update.go user.go way.go

Constants

const (
    Copyright   = "OpenStreetMap and contributors"
    Attribution = "http://www.openstreetmap.org/copyright"
    License     = "http://opendatacommons.org/licenses/odbl/1-0/"
)

These values should be returned if the osm data is actual osm data to give some information about the source and license.

Variables

var CommitInfoStart = time.Date(2012, 9, 12, 9, 30, 3, 0, time.UTC)

CommitInfoStart is the start time when we know committed at information. Any update.Timestamp >= this date is a committed at time. Anything before this date is the element timestamp.

var (
    // ErrScannerClosed is returned by scanner.Err() if the scanner is closed
    // and there are no other io or xml errors to report.
    ErrScannerClosed = errors.New("osm: scanner closed by user")
)
var UninterestingTags = map[string]bool{
    "source":            true,
    "source_ref":        true,
    "source:ref":        true,
    "history":           true,
    "attribution":       true,
    "created_by":        true,
    "tiger:county":      true,
    "tiger:tlid":        true,
    "tiger:upload_uuid": true,
}

UninterestingTags are boring tags. If an element only has these tags it does not usually need to be displayed. For example, if a node with just these tags is part of a way, it probably does not need its own icon along the way.

type Action Uses

type Action struct {
    Type ActionType `xml:"type,attr"`
    *OSM `xml:",omitempty"`
    Old  *OSM `xml:"old,omitempty"`
    New  *OSM `xml:"new,omitempty"`
}

Action is a explicit create, modify or delete action with old and new data if applicable. Different properties of this struct will be populated depending on the action.

Create: da.OSM will contain the new element
Modify: da.Old and da.New will contain the old and new elements.
Delete: da.Old and da.New will contain the old and new elements.

func (Action) MarshalXML Uses

func (a Action) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML converts a diff action to xml creating the proper structures.

func (*Action) UnmarshalXML Uses

func (a *Action) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML converts xml into a diff action.

type ActionType Uses

type ActionType string

ActionType is a strong type for the different diff actions.

const (
    ActionCreate ActionType = "create"
    ActionModify ActionType = "modify"
    ActionDelete ActionType = "delete"
)

The different types of diff actions.

type Actions Uses

type Actions []Action

Actions is a set of diff actions.

type Bounds Uses

type Bounds struct {
    MinLat float64 `xml:"minlat,attr"`
    MaxLat float64 `xml:"maxlat,attr"`
    MinLon float64 `xml:"minlon,attr"`
    MaxLon float64 `xml:"maxlon,attr"`
}

Bounds are the bounds of osm data as defined in the xml file.

func NewBoundsFromTile Uses

func NewBoundsFromTile(t maptile.Tile) (*Bounds, error)

NewBoundsFromTile creates a bound given an online map tile index.

func (*Bounds) ContainsNode Uses

func (b *Bounds) ContainsNode(n *Node) bool

ContainsNode returns true if the node is within the bound. Uses inclusive intervals, ie. returns true if on the boundary.

type Change Uses

type Change struct {
    Version   float64 `xml:"version,attr,omitempty"`
    Generator string  `xml:"generator,attr,omitempty"`

    // to indicate the origin of the data
    Copyright   string `xml:"copyright,attr,omitempty"`
    Attribution string `xml:"attribution,attr,omitempty"`
    License     string `xml:"license,attr,omitempty"`

    Create *OSM `xml:"create"`
    Modify *OSM `xml:"modify"`
    Delete *OSM `xml:"delete"`
}

Change is the structure of a changeset to be uploaded or downloaded from the server. See: http://wiki.openstreetmap.org/wiki/OsmChange

func UnmarshalChange Uses

func UnmarshalChange(data []byte) (*Change, error)

UnmarshalChange will unmarshal the data into a Change object.

func (*Change) AppendCreate Uses

func (c *Change) AppendCreate(o Object)

AppendCreate will append the object to the Create OSM object.

func (*Change) AppendDelete Uses

func (c *Change) AppendDelete(o Object)

AppendDelete will append the object to the Delete OSM object.

func (*Change) AppendModify Uses

func (c *Change) AppendModify(o Object)

AppendModify will append the object to the Modify OSM object.

func (*Change) HistoryDatasource Uses

func (c *Change) HistoryDatasource() *HistoryDatasource

HistoryDatasource converts the change object a datasource accessible by the feature id. All the creates, modifies and deletes will be added in that order.

func (*Change) Marshal Uses

func (c *Change) Marshal() ([]byte, error)

Marshal encodes the osm change data using protocol buffers.

func (Change) MarshalXML Uses

func (c Change) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaller method to allow for the correct wrapper/start element case and attr data.

type Changeset Uses

type Changeset struct {
    XMLName       xmlNameJSONTypeCS    `xml:"changeset" json:"type"`
    ID            ChangesetID          `xml:"id,attr" json:"id"`
    User          string               `xml:"user,attr" json:"user,omitempty"`
    UserID        UserID               `xml:"uid,attr" json:"uid,omitempty"`
    CreatedAt     time.Time            `xml:"created_at,attr" json:"created_at"`
    ClosedAt      time.Time            `xml:"closed_at,attr" json:"closed_at"`
    Open          bool                 `xml:"open,attr" json:"open"`
    ChangesCount  int                  `xml:"num_changes,attr,omitempty" json:"num_changes,omitempty"`
    MinLat        float64              `xml:"min_lat,attr" json:"min_lat,omitempty"`
    MaxLat        float64              `xml:"max_lat,attr" json:"max_lat,omitempty"`
    MinLon        float64              `xml:"min_lon,attr" json:"min_lon,omitempty"`
    MaxLon        float64              `xml:"max_lon,attr" json:"max_lon,omitempty"`
    CommentsCount int                  `xml:"comments_count,attr,omitempty" json:"comments_count,omitempty"`
    Tags          Tags                 `xml:"tag" json:"tags,omitempty"`
    Discussion    *ChangesetDiscussion `xml:"discussion,omitempty" json:"discussion,omitempty"`

    Change *Change `xml:"-" json:"change,omitempty"`
}

A Changeset is a set of metadata around a set of osm changes.

func UnmarshalChangeset Uses

func UnmarshalChangeset(data []byte) (*Changeset, error)

UnmarshalChangeset will unmarshal the data into a OSM object.

func (*Changeset) Bot Uses

func (c *Changeset) Bot() bool

Bot is a helper and returns true if the bot tag is a yes.

func (*Changeset) Bounds Uses

func (c *Changeset) Bounds() *Bounds

Bounds returns the bounds of the changeset as a bounds object.

func (*Changeset) Comment Uses

func (c *Changeset) Comment() string

Comment is a helper and returns the changeset comment from the tag.

func (*Changeset) CreatedBy Uses

func (c *Changeset) CreatedBy() string

CreatedBy is a helper and returns the changeset created by from the tag.

func (*Changeset) Host Uses

func (c *Changeset) Host() string

Host is a helper and returns the changeset host from the tag.

func (*Changeset) ImageryUsed Uses

func (c *Changeset) ImageryUsed() string

ImageryUsed is a helper and returns imagery used for the changeset from the tag.

func (*Changeset) Locale Uses

func (c *Changeset) Locale() string

Locale is a helper and returns the changeset locale from the tag.

func (*Changeset) Marshal Uses

func (c *Changeset) Marshal() ([]byte, error)

Marshal encodes the changeset data using protocol buffers. Does not encode the changeset discussion.

func (*Changeset) ObjectID Uses

func (c *Changeset) ObjectID() ObjectID

ObjectID returns the object id of the changeset.

func (*Changeset) Source Uses

func (c *Changeset) Source() string

Source is a helper and returns source for the changeset from the tag.

type ChangesetComment Uses

type ChangesetComment struct {
    User      string    `xml:"user,attr" json:"user"`
    UserID    UserID    `xml:"uid,attr" json:"uid"`
    Timestamp time.Time `xml:"date,attr" json:"date"`
    Text      string    `xml:"text" json:"text"`
}

ChangesetComment is a specific comment in a changeset discussion.

type ChangesetDiscussion Uses

type ChangesetDiscussion struct {
    Comments []*ChangesetComment `xml:"comment" json:"comments"`
}

ChangesetDiscussion is a conversation about a changeset.

func (ChangesetDiscussion) MarshalXML Uses

func (csd ChangesetDiscussion) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaller method to exclude this whole element if the comments are empty.

type ChangesetID Uses

type ChangesetID int64

ChangesetID is the primary key for a osm changeset.

func (ChangesetID) ObjectID Uses

func (id ChangesetID) ObjectID() ObjectID

ObjectID is a helper returning the object id for this relation id.

type Changesets Uses

type Changesets []*Changeset

Changesets is a collection with some helper functions attached.

func (Changesets) IDs Uses

func (cs Changesets) IDs() []ChangesetID

IDs returns the ids of the changesets in the slice.

type Date Uses

type Date struct {
    time.Time
}

Date is an object to decode the date format used in the osm notes xml api. The format is '2006-01-02 15:04:05 MST'.

func (Date) MarshalJSON Uses

func (d Date) MarshalJSON() ([]byte, error)

MarshalJSON will return null if the date is empty.

func (Date) MarshalXML Uses

func (d Date) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML is meant to encode the time.Time into the osm note date formation of '2006-01-02 15:04:05 MST'.

func (*Date) UnmarshalXML Uses

func (d *Date) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error

UnmarshalXML is meant to decode the osm note date formation of '2006-01-02 15:04:05 MST' into a time.Time object.

type Diff Uses

type Diff struct {
    XMLName    xml.Name   `xml:"osm"`
    Actions    Actions    `xml:"action"`
    Changesets Changesets `xml:"changeset"`
}

Diff represents a difference of osm data with old and new data.

type Element Uses

type Element interface {
    Object

    ElementID() ElementID
    FeatureID() FeatureID
    TagMap() map[string]string
}

An Element represents a Node, Way or Relation.

type ElementID Uses

type ElementID int64

ElementID is a unique key for an osm element. It contains the type, id and version information.

func ParseElementID Uses

func ParseElementID(s string) (ElementID, error)

ParseElementID takes a string and tries to determine the element id from it. The string must be formatted as "type/id:version", the same as the result of the String method.

func (ElementID) FeatureID Uses

func (id ElementID) FeatureID() FeatureID

FeatureID returns the feature id for the element id. i.e removing the version.

func (ElementID) NodeID Uses

func (id ElementID) NodeID() NodeID

NodeID returns the id of this feature as a node id. The function will panic if this feature is not of NodeType.

func (ElementID) ObjectID Uses

func (id ElementID) ObjectID() ObjectID

ObjectID is a helper to convert the id to an object id.

func (ElementID) Ref Uses

func (id ElementID) Ref() int64

Ref return the ID reference for the element. Not unique without the type.

func (ElementID) RelationID Uses

func (id ElementID) RelationID() RelationID

RelationID returns the id of this feature as a relation id. The function will panic if this feature is not of RelationType.

func (ElementID) String Uses

func (id ElementID) String() string

String returns "type/ref:version" for the element.

func (ElementID) Type Uses

func (id ElementID) Type() Type

Type returns the Type for the element.

func (ElementID) Version Uses

func (id ElementID) Version() int

Version returns the version of the element.

func (ElementID) WayID Uses

func (id ElementID) WayID() WayID

WayID returns the id of this feature as a way id. The function will panic if this feature is not of WayType.

type ElementIDs Uses

type ElementIDs []ElementID

ElementIDs is a list of element ids with helper functions on top.

func (ElementIDs) Counts Uses

func (ids ElementIDs) Counts() (nodes, ways, relations int)

Counts returns the number of each type of element in the set of ids.

func (ElementIDs) Sort Uses

func (ids ElementIDs) Sort()

Sort will order the ids by type, node, way, relation, changeset, and then id.

type Elements Uses

type Elements []Element

Elements is a collection of the Element type.

func (Elements) ElementIDs Uses

func (es Elements) ElementIDs() ElementIDs

ElementIDs returns a slice of the element ids of the elements.

func (Elements) FeatureIDs Uses

func (es Elements) FeatureIDs() FeatureIDs

FeatureIDs returns a slice of the feature ids of the elements.

func (Elements) Sort Uses

func (es Elements) Sort()

Sort will order the elements by type, node, way, relation, changeset, then id and lastly the version.

type FeatureID Uses

type FeatureID int64

A FeatureID is a identifier for a feature in OSM. It is meant to represent all the versions of a given element.

func ParseFeatureID Uses

func ParseFeatureID(s string) (FeatureID, error)

ParseFeatureID takes a string and tries to determine the feature id from it. The string must be formatted at "type/id", the same as the result of the String method.

func (FeatureID) ElementID Uses

func (id FeatureID) ElementID(v int) ElementID

ElementID is a helper to convert the id to an element id.

func (FeatureID) NodeID Uses

func (id FeatureID) NodeID() NodeID

NodeID returns the id of this feature as a node id. The function will panic if this feature is not of NodeType.

func (FeatureID) ObjectID Uses

func (id FeatureID) ObjectID(v int) ObjectID

ObjectID is a helper to convert the id to an object id.

func (FeatureID) Ref Uses

func (id FeatureID) Ref() int64

Ref return the ID reference for the feature. Not unique without the type.

func (FeatureID) RelationID Uses

func (id FeatureID) RelationID() RelationID

RelationID returns the id of this feature as a relation id. The function will panic if this feature is not of RelationType.

func (FeatureID) String Uses

func (id FeatureID) String() string

String returns "type/ref" for the feature.

func (FeatureID) Type Uses

func (id FeatureID) Type() Type

Type returns the Type of the feature. Returns empty string for invalid type.

func (FeatureID) WayID Uses

func (id FeatureID) WayID() WayID

WayID returns the id of this feature as a way id. The function will panic if this feature is not of WayType.

type FeatureIDs Uses

type FeatureIDs []FeatureID

FeatureIDs is a slice of FeatureIDs with some helpers on top.

func (FeatureIDs) Counts Uses

func (ids FeatureIDs) Counts() (nodes, ways, relations int)

Counts returns the number of each type of feature in the set of ids.

func (FeatureIDs) Sort Uses

func (ids FeatureIDs) Sort()

Sort will order the ids by type, node, way, relation, changeset, and then id.

type HistoryDatasource Uses

type HistoryDatasource struct {
    Nodes     map[NodeID]Nodes
    Ways      map[WayID]Ways
    Relations map[RelationID]Relations
}

A HistoryDatasource wraps maps to implement the HistoryDataSource interface.

func (*HistoryDatasource) NodeHistory Uses

func (ds *HistoryDatasource) NodeHistory(ctx context.Context, id NodeID) (Nodes, error)

NodeHistory returns the history for the given id from the map.

func (*HistoryDatasource) NotFound Uses

func (ds *HistoryDatasource) NotFound(err error) bool

NotFound returns true if the error returned is a not found error.

func (*HistoryDatasource) RelationHistory Uses

func (ds *HistoryDatasource) RelationHistory(ctx context.Context, id RelationID) (Relations, error)

RelationHistory returns the history for the given id from the map.

func (*HistoryDatasource) WayHistory Uses

func (ds *HistoryDatasource) WayHistory(ctx context.Context, id WayID) (Ways, error)

WayHistory returns the history for the given id from the map.

type HistoryDatasourcer Uses

type HistoryDatasourcer interface {
    NodeHistory(context.Context, NodeID) (Nodes, error)
    WayHistory(context.Context, WayID) (Ways, error)
    RelationHistory(context.Context, RelationID) (Relations, error)
    NotFound(error) bool
}

A HistoryDatasourcer defines an interface to osm history data.

type Member Uses

type Member struct {
    Type Type   `xml:"type,attr" json:"type"`
    Ref  int64  `xml:"ref,attr" json:"ref"`
    Role string `xml:"role,attr" json:"role"`

    Version     int         `xml:"version,attr,omitempty" json:"version,omitempty"`
    ChangesetID ChangesetID `xml:"changeset,attr,omitempty" json:"changeset,omitempty"`
    // Node location if Type == Node
    // Closest vertex to centroid if Type == Way
    // Empty/invalid if Type == Relation
    Lat float64 `xml:"lat,attr,omitempty" json:"lat,omitempty"`
    Lon float64 `xml:"lon,attr,omitempty" json:"lon,omitempty"`

    // Orientation is the direction of the way around a ring of a multipolygon.
    // Only valid for multipolygon or boundary relations.
    Orientation orb.Orientation `xml:"orienation,attr,omitempty" json:"orienation,omitempty"`
}

Member is a member of a relation.

func (Member) ElementID Uses

func (m Member) ElementID() ElementID

ElementID returns the element id of the member.

func (Member) FeatureID Uses

func (m Member) FeatureID() FeatureID

FeatureID returns the feature id of the member.

func (Member) Point Uses

func (m Member) Point() orb.Point

Point returns the orb.Point location for the member. Will be (0, 0) if the relation is not annotated. For way members this location is annotated as the "surface point".

type Members Uses

type Members []Member

Members represents an ordered list of relation members.

func (Members) ElementIDs Uses

func (ms Members) ElementIDs() ElementIDs

ElementIDs returns the a list of element ids for the members.

func (Members) FeatureIDs Uses

func (ms Members) FeatureIDs() FeatureIDs

FeatureIDs returns the a list of feature ids for the members.

func (Members) MarshalJSON Uses

func (ms Members) MarshalJSON() ([]byte, error)

MarshalJSON allows the members to be marshalled as defined by the overpass osmjson. This function is a wrapper to marshal null as [].

type Node Uses

type Node struct {
    XMLName     xmlNameJSONTypeNode `xml:"node" json:"type"`
    ID          NodeID              `xml:"id,attr" json:"id"`
    Lat         float64             `xml:"lat,attr" json:"lat"`
    Lon         float64             `xml:"lon,attr" json:"lon"`
    User        string              `xml:"user,attr" json:"user,omitempty"`
    UserID      UserID              `xml:"uid,attr" json:"uid,omitempty"`
    Visible     bool                `xml:"visible,attr" json:"visible"`
    Version     int                 `xml:"version,attr" json:"version,omitempty"`
    ChangesetID ChangesetID         `xml:"changeset,attr" json:"changeset,omitempty"`
    Timestamp   time.Time           `xml:"timestamp,attr" json:"timestamp"`
    Tags        Tags                `xml:"tag" json:"tags,omitempty"`

    // Committed, is the estimated time this object was committed
    // and made visible in the central OSM database.
    Committed *time.Time `xml:"committed,attr,omitempty" json:"committed,omitempty"`
}

Node is an osm point and allows for marshalling to/from osm xml.

func (*Node) CommittedAt Uses

func (n *Node) CommittedAt() time.Time

CommittedAt returns the best estimate on when this element became was written/committed into the database.

func (*Node) ElementID Uses

func (n *Node) ElementID() ElementID

ElementID returns the element id of the node.

func (*Node) FeatureID Uses

func (n *Node) FeatureID() FeatureID

FeatureID returns the feature id of the node.

func (*Node) ObjectID Uses

func (n *Node) ObjectID() ObjectID

ObjectID returns the object id of the node.

func (*Node) Point Uses

func (n *Node) Point() orb.Point

Point returns the orb.Point location for the node. Will be (0, 0) for "deleted" nodes.

func (*Node) TagMap Uses

func (n *Node) TagMap() map[string]string

TagMap returns the element tags as a key/value map.

type NodeID Uses

type NodeID int64

NodeID corresponds the primary key of a node. The node id + version uniquely identify a node.

func (NodeID) ElementID Uses

func (id NodeID) ElementID(v int) ElementID

ElementID is a helper to convert the id to an element id.

func (NodeID) FeatureID Uses

func (id NodeID) FeatureID() FeatureID

FeatureID is a helper returning the feature id for this node id.

func (NodeID) ObjectID Uses

func (id NodeID) ObjectID(v int) ObjectID

ObjectID is a helper returning the object id for this node id.

type Nodes Uses

type Nodes []*Node

Nodes is a list of nodes with helper functions on top.

func UnmarshalNodes Uses

func UnmarshalNodes(data []byte) (Nodes, error)

UnmarshalNodes will unmarshal the data into a list of nodes.

func (Nodes) ElementIDs Uses

func (ns Nodes) ElementIDs() ElementIDs

ElementIDs returns the element ids for all the nodes.

func (Nodes) FeatureIDs Uses

func (ns Nodes) FeatureIDs() FeatureIDs

FeatureIDs returns the feature ids for all the nodes.

func (Nodes) IDs Uses

func (ns Nodes) IDs() []NodeID

IDs returns the ids for all the ways.

func (Nodes) Marshal Uses

func (ns Nodes) Marshal() ([]byte, error)

Marshal encodes the nodes using protocol buffers.

func (Nodes) SortByIDVersion Uses

func (ns Nodes) SortByIDVersion()

SortByIDVersion will sort the set of nodes first by id and then version in ascending order.

type Note Uses

type Note struct {
    XMLName     xmlNameJSONTypeNote `xml:"note" json:"type"`
    ID          NoteID              `xml:"id" json:"id"`
    Lat         float64             `xml:"lat,attr" json:"lat"`
    Lon         float64             `xml:"lon,attr" json:"lon"`
    URL         string              `xml:"url" json:"url,omitempty"`
    CommentURL  string              `xml:"comment_url" json:"comment_url,omitempty"`
    CloseURL    string              `xml:"close_url" json:"close_url,omitempty"`
    ReopenURL   string              `xml:"reopen_url" json:"reopen_url,omitempty"`
    DateCreated Date                `xml:"date_created" json:"date_created"`
    DateClosed  Date                `xml:"date_closed" json:"date_closed,omitempty"`
    Status      NoteStatus          `xml:"status" json:"status,omitempty"`
    Comments    []*NoteComment      `xml:"comments>comment" json:"comments"`
}

Note is information for other mappers dropped at a map location.

func (*Note) ObjectID Uses

func (n *Note) ObjectID() ObjectID

ObjectID returns the object id of the note.

type NoteComment Uses

type NoteComment struct {
    XMLName xml.Name          `xml:"comment" json:"-"`
    Date    Date              `xml:"date" json:"date"`
    UserID  UserID            `xml:"uid" json:"uid,omitempty"`
    User    string            `xml:"user" json:"user,omitempty"`
    UserURL string            `xml:"user_url" json:"user_url,omitempty"`
    Action  NoteCommentAction `xml:"action" json:"action"`
    Text    string            `xml:"text" json:"text"`
    HTML    string            `xml:"html" json:"html"`
}

NoteComment is a comment on a note.

type NoteCommentAction Uses

type NoteCommentAction string

NoteCommentAction are actions that a note comment took.

var (
    NoteCommentOpened  NoteCommentAction = "opened"
    NoteCommentComment NoteCommentAction = "commented"
    NoteCommentClosed  NoteCommentAction = "closed"
)

The set of comment actions.

type NoteID Uses

type NoteID int64

NoteID is the unique identifier for a osm note.

func (NoteID) ObjectID Uses

func (id NoteID) ObjectID() ObjectID

ObjectID is a helper returning the object id for this note id.

type NoteStatus Uses

type NoteStatus string

NoteStatus is the status of the note.

var (
    NoteOpen   NoteStatus = "open"
    NoteClosed NoteStatus = "closed"
)

A note can be open or closed.

type Notes Uses

type Notes []*Note

Notes is a collection of notes with some helpers attached.

type OSM Uses

type OSM struct {
    Version   float64 `xml:"version,attr,omitempty"`
    Generator string  `xml:"generator,attr,omitempty"`

    // These three attributes are returned by the osm api.
    // The Copyright, Attribution and License constants contain
    // suggested values that match those returned by the official api.
    Copyright   string `xml:"copyright,attr,omitempty"`
    Attribution string `xml:"attribution,attr,omitempty"`
    License     string `xml:"license,attr,omitempty"`

    Bounds    *Bounds   `xml:"bounds,omitempty"`
    Nodes     Nodes     `xml:"node"`
    Ways      Ways      `xml:"way"`
    Relations Relations `xml:"relation"`

    // Changesets will typically not be included with actual data,
    // but all this stuff is technically all under the osm xml
    Changesets Changesets `xml:"changeset"`
    Notes      Notes      `xml:"note"`
    Users      Users      `xml:"user"`
}

OSM represents the core osm data designed to parse http://wiki.openstreetmap.org/wiki/OSM_XML

func UnmarshalOSM Uses

func UnmarshalOSM(data []byte) (*OSM, error)

UnmarshalOSM will unmarshal the data into a OSM object.

func (*OSM) Append Uses

func (o *OSM) Append(obj Object)

Append will add the given object to the OSM object.

func (*OSM) ElementIDs Uses

func (o *OSM) ElementIDs() ElementIDs

ElementIDs returns the slice of element ids for all the nodes, ways and relations.

func (*OSM) Elements Uses

func (o *OSM) Elements() Elements

Elements returns all the nodes, ways and relations as a single slice of Elements.

func (*OSM) FeatureIDs Uses

func (o *OSM) FeatureIDs() FeatureIDs

FeatureIDs returns the slice of feature ids for all the nodes, ways and relations.

func (*OSM) HistoryDatasource Uses

func (o *OSM) HistoryDatasource() *HistoryDatasource

HistoryDatasource converts the osm object a datasource accessible by the feature id.

func (*OSM) Marshal Uses

func (o *OSM) Marshal() ([]byte, error)

Marshal encodes the osm data using protocol buffers. Will only save the elements: nodes, ways and relations.

func (OSM) MarshalJSON Uses

func (o OSM) MarshalJSON() ([]byte, error)

MarshalJSON allows the tags to be marshalled as an object as defined by the overpass osmjson. http://overpass-api.de/output_formats.html#json

func (OSM) MarshalXML Uses

func (o OSM) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaller method to allow for the correct wrapper/start element case and attr data.

func (*OSM) Objects Uses

func (o *OSM) Objects() Objects

Objects returns an array of objects containing any nodes, ways, relations, changesets, notes and users.

type Object Uses

type Object interface {
    ObjectID() ObjectID
    // contains filtered or unexported methods
}

An Object represents a Node, Way, Relation, Changeset, Note or User only.

type ObjectID Uses

type ObjectID int64

ObjectID encodes the type and ref of an osm object, e.g. nodes, ways, relations, changesets, notes and users.

func ParseObjectID Uses

func ParseObjectID(s string) (ObjectID, error)

ParseObjectID takes a string and tries to determine the object id from it. The string must be formatted as "type/id:version", the same as the result of the String method.

func (ObjectID) Ref Uses

func (id ObjectID) Ref() int64

Ref return the ID reference for the object. Not unique without the type.

func (ObjectID) String Uses

func (id ObjectID) String() string

String returns "type/ref:version" for the object.

func (ObjectID) Type Uses

func (id ObjectID) Type() Type

Type returns the Type of the object.

func (ObjectID) Version Uses

func (id ObjectID) Version() int

Version returns the version of the object. Will return 0 if the object doesn't have versions like users, notes and changesets.

type ObjectIDs Uses

type ObjectIDs []ObjectID

ObjectIDs is a slice of ObjectIDs with some helpers on top.

type Objects Uses

type Objects []Object

Objects is a set of objects with some helpers

func (Objects) ObjectIDs Uses

func (os Objects) ObjectIDs() ObjectIDs

ObjectIDs returns a slice of the object ids of the osm objects.

type Relation Uses

type Relation struct {
    XMLName     xmlNameJSONTypeRel `xml:"relation" json:"type"`
    ID          RelationID         `xml:"id,attr" json:"id"`
    User        string             `xml:"user,attr" json:"user,omitempty"`
    UserID      UserID             `xml:"uid,attr" json:"uid,omitempty"`
    Visible     bool               `xml:"visible,attr" json:"visible"`
    Version     int                `xml:"version,attr" json:"version,omitempty"`
    ChangesetID ChangesetID        `xml:"changeset,attr" json:"changeset,omitempty"`
    Timestamp   time.Time          `xml:"timestamp,attr" json:"timestamp,omitempty"`

    Tags    Tags    `xml:"tag" json:"tags,omitempty"`
    Members Members `xml:"member" json:"members"`

    // Committed, is the estimated time this object was committed
    // and made visible in the central OSM database.
    Committed *time.Time `xml:"committed,attr,omitempty" json:"committed,omitempty"`

    // Updates are changes the members of this relation independent
    // of an update to the relation itself. The OSM api allows a child
    // to be updatedwithout any changes to the parent.
    Updates Updates `xml:"update,omitempty" json:"updates,omitempty"`

    // Bounds are included by overpass, and maybe others
    Bounds *Bounds `xml:"bounds,omitempty" json:"bounds,omitempty"`
}

Relation is an collection of nodes, ways and other relations with some defining attributes.

func (*Relation) ApplyUpdatesUpTo Uses

func (r *Relation) ApplyUpdatesUpTo(t time.Time) error

ApplyUpdatesUpTo will apply the updates to this object upto and including the given time.

func (*Relation) CommittedAt Uses

func (r *Relation) CommittedAt() time.Time

CommittedAt returns the best estimate on when this element became was written/committed into the database.

func (*Relation) ElementID Uses

func (r *Relation) ElementID() ElementID

ElementID returns the element id of the relation.

func (*Relation) FeatureID Uses

func (r *Relation) FeatureID() FeatureID

FeatureID returns the feature id of the relation.

func (*Relation) ObjectID Uses

func (r *Relation) ObjectID() ObjectID

ObjectID returns the object id of the relation.

func (*Relation) Polygon Uses

func (r *Relation) Polygon() bool

Polygon returns true if the relation is of type multipolygon or boundary.

func (*Relation) TagMap Uses

func (r *Relation) TagMap() map[string]string

TagMap returns the element tags as a key/value map.

type RelationID Uses

type RelationID int64

RelationID is the primary key of a relation. A relation is uniquely identifiable by the id + version.

func (RelationID) ElementID Uses

func (id RelationID) ElementID(v int) ElementID

ElementID is a helper to convert the id to an element id.

func (RelationID) FeatureID Uses

func (id RelationID) FeatureID() FeatureID

FeatureID is a helper returning the feature id for this relation id.

func (RelationID) ObjectID Uses

func (id RelationID) ObjectID(v int) ObjectID

ObjectID is a helper returning the object id for this relation id.

type Relations Uses

type Relations []*Relation

Relations is a list of relations with some helper functions attached.

func UnmarshalRelations Uses

func UnmarshalRelations(data []byte) (Relations, error)

UnmarshalRelations will unmarshal the data into a list of relations.

func (Relations) ElementIDs Uses

func (rs Relations) ElementIDs() ElementIDs

ElementIDs returns the element ids for all the relations.

func (Relations) FeatureIDs Uses

func (rs Relations) FeatureIDs() FeatureIDs

FeatureIDs returns the feature ids for all the relations.

func (Relations) IDs Uses

func (rs Relations) IDs() []RelationID

IDs returns the ids for all the relations.

func (Relations) Marshal Uses

func (rs Relations) Marshal() ([]byte, error)

Marshal encodes the relations using protocol buffers.

func (Relations) SortByIDVersion Uses

func (rs Relations) SortByIDVersion()

SortByIDVersion will sort the set of relations first by id and then version in ascending order.

type Scanner Uses

type Scanner interface {
    Scan() bool
    Object() Object
    Err() error
    Close() error
}

Scanner allows osm data from dump files to be read. It is based on the bufio.Scanner, common usage. Scanners are not safe for parallel use. One should feed the objects into their own channel and have workers read from that.

s := scanner.New(r)
defer s.Close()

for s.Next() {
	o := s.Object()
	// do something
}

if s.Err() != nil {
	// scanner did no complete fully
}

type Tag Uses

type Tag struct {
    Key   string `xml:"k,attr"`
    Value string `xml:"v,attr"`
}

Tag is a key+value item attached to osm nodes, ways and relations.

type Tags Uses

type Tags []Tag

Tags is a collection of Tag objects with some helper functions.

func (Tags) AnyInteresting Uses

func (ts Tags) AnyInteresting() bool

AnyInteresting will return true if there is at last one interesting tag.

func (Tags) Find Uses

func (ts Tags) Find(k string) string

Find will return the value for the key. Will return an empty string if not found.

func (Tags) Map Uses

func (ts Tags) Map() map[string]string

Map returns the tags as a key/value map.

func (Tags) MarshalJSON Uses

func (ts Tags) MarshalJSON() ([]byte, error)

MarshalJSON allows the tags to be marshalled as a key/value object, as defined by the overpass osmjson.

func (Tags) SortByKeyValue Uses

func (ts Tags) SortByKeyValue()

SortByKeyValue will do an inplace sort of the tags.

func (*Tags) UnmarshalJSON Uses

func (ts *Tags) UnmarshalJSON(data []byte) error

UnmarshalJSON allows the tags to be unmarshalled from a key/value object, as defined by the overpass osmjson.

type Type Uses

type Type string

Type is the type of different osm objects. ie. node, way, relation, changeset, note, user.

const (
    TypeNode      Type = "node"
    TypeWay       Type = "way"
    TypeRelation  Type = "relation"
    TypeChangeset Type = "changeset"
    TypeNote      Type = "note"
    TypeUser      Type = "user"
)

Constants for the different object types.

func (Type) FeatureID Uses

func (t Type) FeatureID(ref int64) (FeatureID, error)

FeatureID returns a feature id from the given type.

type Update Uses

type Update struct {
    Index   int `xml:"index,attr" json:"index"`
    Version int `xml:"version,attr" json:"version"`

    // Timestamp is the committed at time if time > CommitInfoStart or the
    // element timestamp if before that date.
    Timestamp time.Time `xml:"timestamp,attr" json:"timestamp"`

    ChangesetID ChangesetID `xml:"changeset,attr,omitempty" json:"changeset,omitempty"`
    Lat         float64     `xml:"lat,attr,omitempty" json:"lat,omitempty"`
    Lon         float64     `xml:"lon,attr,omitempty" json:"lon,omitempty"`
    Reverse     bool        `xml:"reverse,attr,omitempty" json:"reverse,omitempty"`
}

An Update is a change to children of a way or relation. The child type, id, ref and/or role are the same as the child at the given index. Lat/Lng are only updated for ways.

type UpdateIndexOutOfRangeError Uses

type UpdateIndexOutOfRangeError struct {
    Index int
}

UpdateIndexOutOfRangeError is return when appling an update to an object and the update index is out of range.

func (*UpdateIndexOutOfRangeError) Error Uses

func (e *UpdateIndexOutOfRangeError) Error() string

Error returns a string representation of the error.

type Updates Uses

type Updates []Update

Updates are collections of updates.

func (Updates) SortByIndex Uses

func (us Updates) SortByIndex()

SortByIndex will sort the updates by index in ascending order.

func (Updates) SortByTimestamp Uses

func (us Updates) SortByTimestamp()

SortByTimestamp will sort the updates by timestamp in ascending order.

func (Updates) UpTo Uses

func (us Updates) UpTo(t time.Time) Updates

UpTo will return the subset of updates taking place upto and on the given time.

type User Uses

type User struct {
    XMLName     xmlNameJSONTypeUser `xml:"user" json:"type"`
    ID          UserID              `xml:"id,attr" json:"id"`
    Name        string              `xml:"display_name,attr" json:"name"`
    Description string              `xml:"description" json:"description,omitempty"`
    Img         struct {
        Href string `xml:"href,attr" json:"href"`
    }   `xml:"img" json:"img"`
    Changesets struct {
        Count int `xml:"count,attr" json:"count"`
    }   `xml:"changesets" json:"changesets"`
    Traces struct {
        Count int `xml:"count,attr" json:"count"`
    }   `xml:"traces" json:"traces"`
    Home struct {
        Lat  float64 `xml:"lat,attr" json:"lat"`
        Lon  float64 `xml:"lon,attr" json:"lon"`
        Zoom int     `xml:"zoom,attr" json:"zoom"`
    }   `xml:"home" json:"home"`
    Languages []string `xml:"languages>lang" json:"languages"`
    Blocks    struct {
        Received struct {
            Count  int `xml:"count,attr" json:"count"`
            Active int `xml:"active,attr" json:"active"`
        } `xml:"received" json:"received"`
    }   `xml:"blocks" json:"blocks"`
    Messages struct {
        Received struct {
            Count  int `xml:"count,attr" json:"count"`
            Unread int `xml:"unread,attr" json:"unread"`
        }   `xml:"received" json:"received"`
        Sent struct {
            Count int `xml:"count,attr" json:"count"`
        }   `xml:"sent" json:"sent"`
    }   `xml:"messages" json:"messages"`
    CreatedAt time.Time `xml:"account_created,attr" json:"created_at"`
}

A User is a registered OSM user.

func (*User) ObjectID Uses

func (u *User) ObjectID() ObjectID

ObjectID returns the object id of the user.

type UserID Uses

type UserID int64

UserID is the primary key for a user. This is unique the display name may change.

func (UserID) ObjectID Uses

func (id UserID) ObjectID() ObjectID

ObjectID is a helper returning the object id for this user id.

type Users Uses

type Users []*User

Users is a collection of users with some helpers attached.

type Way Uses

type Way struct {
    XMLName     xmlNameJSONTypeWay `xml:"way" json:"type"`
    ID          WayID              `xml:"id,attr" json:"id"`
    User        string             `xml:"user,attr" json:"user,omitempty"`
    UserID      UserID             `xml:"uid,attr" json:"uid,omitempty"`
    Visible     bool               `xml:"visible,attr" json:"visible"`
    Version     int                `xml:"version,attr" json:"version,omitempty"`
    ChangesetID ChangesetID        `xml:"changeset,attr" json:"changeset,omitempty"`
    Timestamp   time.Time          `xml:"timestamp,attr" json:"timestamp"`
    Nodes       WayNodes           `xml:"nd" json:"nodes"`
    Tags        Tags               `xml:"tag" json:"tags,omitempty"`

    // Committed, is the estimated time this object was committed
    // and made visible in the central OSM database.
    Committed *time.Time `xml:"committed,attr,omitempty" json:"committed,omitempty"`

    // Updates are changes the nodes of this way independent
    // of an update to the way itself. The OSM api allows a child
    // to be updated without any changes to the parent.
    Updates Updates `xml:"update,omitempty" json:"updates,omitempty"`

    // Bounds are included by overpass, and maybe others
    Bounds *Bounds `xml:"bounds,omitempty" json:"bounds,omitempty"`
}

Way is an osm way, ie collection of nodes.

func (*Way) ApplyUpdatesUpTo Uses

func (w *Way) ApplyUpdatesUpTo(t time.Time) error

ApplyUpdatesUpTo will apply the updates to this object upto and including the given time.

func (*Way) CommittedAt Uses

func (w *Way) CommittedAt() time.Time

CommittedAt returns the best estimate on when this element became was written/committed into the database.

func (*Way) ElementID Uses

func (w *Way) ElementID() ElementID

ElementID returns the element id of the way.

func (*Way) FeatureID Uses

func (w *Way) FeatureID() FeatureID

FeatureID returns the feature id of the way.

func (*Way) LineString Uses

func (w *Way) LineString() orb.LineString

LineString will convert the annotated nodes into a LineString datatype.

func (*Way) LineStringAt Uses

func (w *Way) LineStringAt(t time.Time) orb.LineString

LineStringAt will return the LineString from the annotated points at the given time. It will apply to the updates upto and including the give time.

func (*Way) ObjectID Uses

func (w *Way) ObjectID() ObjectID

ObjectID returns the object id of the way.

func (*Way) Polygon Uses

func (w *Way) Polygon() bool

Polygon returns true if the way should be considered a closed polygon area. OpenStreetMap doesn't have an intrinsic area data type. The algorithm used here considers a set of heuristics to determine what is most likely an area. The heuristics can be found here, https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features and are used by osmtogeojson and overpass turbo.

func (*Way) TagMap Uses

func (w *Way) TagMap() map[string]string

TagMap returns the element tags as a key/value map.

type WayID Uses

type WayID int64

WayID is the primary key of a way. A way is uniquely identifiable by the id + version.

func (WayID) ElementID Uses

func (id WayID) ElementID(v int) ElementID

ElementID is a helper to convert the id to an element id.

func (WayID) FeatureID Uses

func (id WayID) FeatureID() FeatureID

FeatureID is a helper returning the feature id for this way id.

func (WayID) ObjectID Uses

func (id WayID) ObjectID(v int) ObjectID

ObjectID is a helper returning the object id for this way id.

type WayNode Uses

type WayNode struct {
    ID  NodeID `xml:"ref,attr"`

    // These attributes are populated for concrete versions of ways.
    Version     int         `xml:"version,attr,omitempty"`
    ChangesetID ChangesetID `xml:"changeset,attr,omitempty"`
    Lat         float64     `xml:"lat,attr,omitempty"`
    Lon         float64     `xml:"lon,attr,omitempty"`
}

WayNode is a short node used as part of ways and relations in the osm xml.

func (WayNode) ElementID Uses

func (wn WayNode) ElementID() ElementID

ElementID returns the element id of the way node.

func (WayNode) FeatureID Uses

func (wn WayNode) FeatureID() FeatureID

FeatureID returns the feature id of the way node.

func (WayNode) Point Uses

func (wn WayNode) Point() orb.Point

Point returns the orb.Point location for the way node. Will be (0, 0) if the way is not annotated.

type WayNodes Uses

type WayNodes []WayNode

WayNodes represents a collection of way nodes.

func (WayNodes) Bound Uses

func (wn WayNodes) Bound() orb.Bound

Bound computes the orb.Bound for the given way nodes.

func (WayNodes) Bounds Uses

func (wn WayNodes) Bounds() *Bounds

Bounds computes the bounds for the given way nodes.

func (WayNodes) ElementIDs Uses

func (wn WayNodes) ElementIDs() ElementIDs

ElementIDs returns a list of element ids for the way nodes.

func (WayNodes) FeatureIDs Uses

func (wn WayNodes) FeatureIDs() FeatureIDs

FeatureIDs returns a list of feature ids for the way nodes.

func (WayNodes) MarshalJSON Uses

func (wn WayNodes) MarshalJSON() ([]byte, error)

MarshalJSON allows the waynodes to be marshalled as an array of ids, as defined by the overpass osmjson.

func (WayNodes) NodeIDs Uses

func (wn WayNodes) NodeIDs() []NodeID

NodeIDs returns a list of node ids for the way nodes.

func (*WayNodes) UnmarshalJSON Uses

func (wn *WayNodes) UnmarshalJSON(data []byte) error

UnmarshalJSON allows the tags to be unmarshalled from an array of ids, as defined by the overpass osmjson.

type Ways Uses

type Ways []*Way

Ways is a list of osm ways with some helper functions attached.

func UnmarshalWays Uses

func UnmarshalWays(data []byte) (Ways, error)

UnmarshalWays will unmarshal the data into a list of ways.

func (Ways) ElementIDs Uses

func (ws Ways) ElementIDs() ElementIDs

ElementIDs returns the element ids for all the ways.

func (Ways) FeatureIDs Uses

func (ws Ways) FeatureIDs() FeatureIDs

FeatureIDs returns the feature ids for all the ways.

func (Ways) IDs Uses

func (ws Ways) IDs() []WayID

IDs returns the ids for all the ways.

func (Ways) Marshal Uses

func (ws Ways) Marshal() ([]byte, error)

Marshal encodes the ways using protocol buffers.

func (Ways) SortByIDVersion Uses

func (ws Ways) SortByIDVersion()

SortByIDVersion will sort the set of ways first by id and then version in ascending order.

Directories

PathSynopsis
annotate
annotate/internal/core
annotate/sharedPackage shared is used by annotate and the internal core.
internal/mputil
internal/osmpbPackage osmpb is a generated protocol buffer package.
osmapiPackage osmapi provides an interface to the OSM v0.6 API.
osmgeojson
osmpbf
osmpbf/internal/osmpbfPackage osmpbf is a generated protocol buffer package.
osmtest
osmxml
replication

Package osm imports 15 packages (graph) and is imported by 20 packages. Updated 2018-12-20. Refresh now. Tools for package owners.