Categorygithub.com/oflebbe/osm
modulepackage
0.1.5
Repository: https://github.com/oflebbe/osm.git
Documentation: pkg.go.dev

# README

osm Build Status Go Report Card Godoc Reference

This package is a general purpose library for reading, writing and working with OpenStreetMap data in Go (golang). It has the ability to read OSM XML and PBF data formats available at planet.osm.org or via the v0.6 API.

Made available by the package are the following types:

  • Node
  • Way
  • Relation
  • Changeset
  • Note
  • User

And the following “container” types:

List of sub-package utilities

  • annotate - adds lon/lat, version, changeset and orientation data to way and relation members
  • osmapi - supports all the v0.6 read/data endpoints
  • osmgeojson - OSM to GeoJSON conversion compatible with osmtogeojson
  • osmpbf - stream processing of *.osm.pbf files
  • osmxml - stream processing of *.osm xml files.
  • replication - fetch replication state and change files

Concepts

This package refers to the core OSM data types as Objects. The Node, Way, Relation, Changeset, Note and User types implement the osm.Object interface and can be referenced using the osm.ObjectID type. As a result it is possible to have a slice of []osm.Object that contains nodes, changesets and users.

Individual versions of the core OSM Map Data types are referred to as Elements and the set of versions for a give Node, Way or Relation is referred to as a Feature. For example, an osm.ElementID could refer to "Node with id 10 and version 3" and the osm.FeatureID would refer to "all versions of node with id 10." Put another way, features represent a road and how it's changed over time and an element is a specific version of that feature.

A number of helper methods are provided for dealing with features and elements. The idea is to make it easy to work with a Way and its member nodes, for example.

Scanning large data files

For small data it is possible to use the encoding/xml package in the Go standard libray to marshal/unmarshal the data. This is typically done using the osm.OSM or osm.Change "container" structs.

For large data the package defines the Scanner interface implemented in both the osmxml and osmpbf sub-packages.

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

This interface is designed to mimic the bufio.Scanner interface found in the Go standard library.

Example usage:

f, err := os.Open("./delaware-latest.osm.pbf")
if err != nil {
	panic(err)
}
defer f.Close()

scanner := osmpbf.New(context.Background(), f, 3)
defer scanner.Close()

for scanner.Scan() {
	o := scanner.Object()
	// do something
}

scanErr := scanner.Err()
if scanErr != nil {
	panic(scanErr)
}

Note: Scanners are not safe for parallel use. One should feed the objects into a channel and have workers read from that.

# Packages

No description provided by the author
Package osmapi provides an interface to the OSM v0.6 API.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

NewBoundsFromTile creates a bound given an online map tile index.
ParseElementID takes a string and tries to determine the element id from it.
ParseFeatureID takes a string and tries to determine the feature id from it.
ParseObjectID takes a string and tries to determine the object id from it.
UnmarshalChange will unmarshal the data into a Change object.
UnmarshalChangeset will unmarshal the data into an OSM object.
UnmarshalNodes will unmarshal the data into a list of nodes.
UnmarshalOSM will unmarshal the data into an OSM object.
UnmarshalRelations will unmarshal the data into a list of relations.
UnmarshalWays will unmarshal the data into a list of ways.

# Constants

The different types of diff actions.
The different types of diff actions.
The different types of diff actions.
These values should be returned if the osm data is actual osm data to give some information about the source and license.
These values should be returned if the osm data is actual osm data to give some information about the source and license.
These values should be returned if the osm data is actual osm data to give some information about the source and license.
Constants for the different object types.
Constants for the different object types.
Constants for the different object types.
Constants for the different object types.
Constants for the different object types.
Constants for the different object types.
Constants for the different object types.

# Variables

CommitInfoStart is the start time when we know committed at information.
ErrScannerClosed is returned by scanner.Err() if the scanner is closed and there are no other io or xml errors to report.
A note can be open or closed.
The set of comment actions.
The set of comment actions.
The set of comment actions.
A note can be open or closed.
UninterestingTags are boring tags.

# Structs

Action is a explicit create, modify or delete action with old and new data if applicable.
Bounds are the bounds of osm data as defined in the xml file.
Change is the structure of a changeset to be uploaded or downloaded from the osm api server.
A Changeset is a set of metadata around a set of osm changes.
ChangesetComment is a specific comment in a changeset discussion.
ChangesetDiscussion is a conversation about a changeset.
Date is an object to decode the date format used in the osm notes xml api.
Diff represents a difference of osm data with old and new data.
A HistoryDatasource wraps maps to implement the HistoryDataSource interface.
Member is a member of a relation.
Node is an osm point and allows for marshalling to/from osm xml.
Note is information for other mappers dropped at a map location.
NoteComment is a comment on a note.
OSM represents the core osm data designed to parse http://wiki.openstreetmap.org/wiki/OSM_XML.
Relation is an collection of nodes, ways and other relations with some defining attributes.
Tag is a key+value item attached to osm nodes, ways and relations.
An Update is a change to children of a way or relation.
UpdateIndexOutOfRangeError is return when appling an update to an object and the update index is out of range.
A User is a registered OSM user.
Way is an osm way, ie collection of nodes.
WayNode is a short node used as part of ways and relations in the osm xml.

# Interfaces

An Element represents a Node, Way or Relation.
A HistoryDatasourcer defines an interface to osm history data.
An Object represents a Node, Way, Relation, Changeset, Note or User only.
A Scanner reads osm data from planet dump files.

# Type aliases

Actions is a set of diff actions.
ActionType is a strong type for the different diff actions.
ChangesetID is the primary key for an osm changeset.
Changesets is a collection with some helper functions attached.
ElementID is a unique key for an osm element.
ElementIDs is a list of element ids with helper functions on top.
Elements is a collection of the Element type.
A FeatureID is an identifier for a feature in OSM.
FeatureIDs is a slice of FeatureIDs with some helpers on top.
Members represents an ordered list of relation members.
NodeID corresponds the primary key of a node.
Nodes is a list of nodes with helper functions on top.
NoteCommentAction are actions that a note comment took.
NoteID is the unique identifier for an osm note.
Notes is a collection of notes with some helpers attached.
NoteStatus is the status of the note.
ObjectID encodes the type and ref of an osm object, e.g.
ObjectIDs is a slice of ObjectIDs with some helpers on top.
Objects is a set of objects with some helpers.
RelationID is the primary key of a relation.
Relations is a list of relations with some helper functions attached.
Tags is a collection of Tag objects with some helper functions.
Type is the type of different osm objects.
Updates are collections of updates.
UserID is the primary key for a user.
Users is a collection of users with some helpers attached.
WayID is the primary key of a way.
WayNodes represents a collection of way nodes.
Ways is a list of osm ways with some helper functions attached.