osmapi

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 10 Imported by: 8

README

osm/osmapi Godoc Reference

Package osmapi provides an interface to the OSM v0.6 API.

Usage:

node, err := osmapi.Node(ctx, 1010)

This call issues a request to api.openstreetmap.org/api/0.6/node/1010 and returns a parsed osm.Node object with all the methods attached.

List of functions

func Map(context.Context, bounds *osm.Bounds) (*osm.OSM, error)

func Node(context.Context, osm.NodeID) (*osm.Node, error)
func Nodes(context.Context, []osm.NodeID) (osm.Nodes, error)
func NodeVersion(context.Context, osm.NodeID, v int) (*osm.Node, error)
func NodeHistory(context.Context, osm.NodeID) (osm.Nodes, error)

func NodeWays(context.Context, osm.NodeID) (osm.Ways, error)
func NodeRelations(context.Context, osm.NodeID) (osm.Relations, error)

func Way(context.Context, osm.WayID) (*osm.Way, error)
func Ways(context.Context, []osm.WayID) (osm.Ways, error)
func WayFull(context.Context, osm.WayID) (*osm.OSM, error)
func WayVersion(context.Context, osm.WayID, v int) (*osm.Way, error)
func WayHistory(context.Context, osm.WayID) (osm.Ways, error)

func WayRelations(context.Context, osm.WayID) (osm.Relations, error)

func Relation(context.Context, osm.RelationID) (*osm.Relation, error)
func Relations(context.Context, []osm.RelationID) (osm.Relations, error)
func RelationFull(context.Context, osm.RelationID) (*osm.OSM, error)
func RelationVersion(context.Context, osm.RelationID, v int) (*osm.Relation, error)
func RelationHistory(context.Context, osm.RelationID) (osm.Relations, error)

func RelationRelations(context.Context, osm.RelationID) (osm.Relations, error)

func Changeset(context.Context, osm.ChangesetID) (*osm.Changeset, error)
func ChangesetWithDiscussion(context.Context, osm.ChangesetID) (*osm.Changeset, error)
func ChangesetDownload(context.Context, osm.ChangesetID) (*osm.Change, error)

func Note(ctx context.Context, id osm.NoteID) (*osm.Note, error) {
func Notes(ctx context.Context, bounds *osm.Bounds, opts ...NotesOption) (osm.Notes, error)
func NotesSearch(ctx context.Context, query string, opts ...NotesOption) (osm.Notes, error)

func User(ctx context.Context, id osm.UserID) (*osm.User, error)

See the godoc reference for more details.

Rate limiting

This package can make sure of x/time/rate.Limiter to throttle requests to the official api. Example usage:

// 10 qps
osmapi.DefaultDatasource.Limiter = rate.NewLimiter(10, 1)

Documentation

Overview

Package osmapi provides an interface to the OSM v0.6 API.

Index

Constants

View Source
const BaseURL = "http://api.openstreetmap.org/api/0.6"

BaseURL defines the api host. This can be change to hit a dev server, for example, http://api06.dev.openstreetmap.org/api/0.6

Variables

View Source
var DefaultDatasource = &Datasource{
	BaseURL: BaseURL,
	Client: &http.Client{
		Timeout: 6 * time.Minute,
	},
}

DefaultDatasource is the Datasource used by package level convenience functions.

Functions

func Changeset

func Changeset(ctx context.Context, id osm.ChangesetID) (*osm.Changeset, error)

Changeset returns a given changeset from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func ChangesetDownload

func ChangesetDownload(ctx context.Context, id osm.ChangesetID) (*osm.Change, error)

ChangesetDownload returns the full osmchange for the changeset using the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func ChangesetWithDiscussion

func ChangesetWithDiscussion(ctx context.Context, id osm.ChangesetID) (*osm.Changeset, error)

ChangesetWithDiscussion returns a changeset and its discussion from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func Map

func Map(ctx context.Context, bounds *osm.Bounds, opts ...FeatureOption) (*osm.OSM, error)

Map returns the latest elements in the given bounding box. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func Node

func Node(ctx context.Context, id osm.NodeID, opts ...FeatureOption) (*osm.Node, error)

Node returns the latest version of the node from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func NodeHistory

func NodeHistory(ctx context.Context, id osm.NodeID) (osm.Nodes, error)

NodeHistory returns all the versions of the node from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func NodeRelations

func NodeRelations(ctx context.Context, id osm.NodeID, opts ...FeatureOption) (osm.Relations, error)

NodeRelations returns all relations a node is part of. There is no error if the element does not exist. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func NodeVersion

func NodeVersion(ctx context.Context, id osm.NodeID, v int) (*osm.Node, error)

NodeVersion returns the specific version of the node from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func NodeWays

func NodeWays(ctx context.Context, id osm.NodeID, opts ...FeatureOption) (osm.Ways, error)

NodeWays returns all ways a node is part of. There is no error if the element does not exist. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func Nodes

func Nodes(ctx context.Context, ids []osm.NodeID, opts ...FeatureOption) (osm.Nodes, error)

Nodes returns the latest version of the nodes from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func Note

func Note(ctx context.Context, id osm.NoteID) (*osm.Note, error)

Note returns the note from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func Notes

func Notes(ctx context.Context, bounds *osm.Bounds, opts ...NotesOption) (osm.Notes, error)

Notes returns the notes in a bounding box. Can provide options to limit the results or change what it means to be "closed". See the options or osm api v0.6 docs for details. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func NotesSearch

func NotesSearch(ctx context.Context, query string, opts ...NotesOption) (osm.Notes, error)

NotesSearch returns the notes in a bounding box whose text matches the query. Can provide options to limit the results or change what it means to be "closed". See the options or osm api v0.6 docs for details. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func Relation

func Relation(ctx context.Context, id osm.RelationID, opts ...FeatureOption) (*osm.Relation, error)

Relation returns the latest version of the relation from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func RelationFull

func RelationFull(ctx context.Context, id osm.RelationID, opts ...FeatureOption) (*osm.OSM, error)

RelationFull returns the relation and its nodes for the latest version the relation. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func RelationHistory

func RelationHistory(ctx context.Context, id osm.RelationID) (osm.Relations, error)

RelationHistory returns all the versions of the relation from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func RelationRelations

func RelationRelations(ctx context.Context, id osm.RelationID, opts ...FeatureOption) (osm.Relations, error)

RelationRelations returns all relations a relation is part of. There is no error if the element does not exist. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func RelationVersion

func RelationVersion(ctx context.Context, id osm.RelationID, v int) (*osm.Relation, error)

RelationVersion returns the specific version of the relation from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func Relations

func Relations(ctx context.Context, ids []osm.RelationID, opts ...FeatureOption) (osm.Relations, error)

Relations returns the latest version of the relations from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func User

func User(ctx context.Context, id osm.UserID) (*osm.User, error)

User returns the user from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func Way

func Way(ctx context.Context, id osm.WayID, opts ...FeatureOption) (*osm.Way, error)

Way returns the latest version of the way from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func WayFull

func WayFull(ctx context.Context, id osm.WayID, opts ...FeatureOption) (*osm.OSM, error)

WayFull returns the way and its nodes for the latest version the way. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func WayHistory

func WayHistory(ctx context.Context, id osm.WayID) (osm.Ways, error)

WayHistory returns all the versions of the way from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func WayRelations

func WayRelations(ctx context.Context, id osm.WayID, opts ...FeatureOption) (osm.Relations, error)

WayRelations returns all relations a way is part of. There is no error if the element does not exist. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func WayVersion

func WayVersion(ctx context.Context, id osm.WayID, v int) (*osm.Way, error)

WayVersion returns the specific version of the way from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

func Ways

func Ways(ctx context.Context, ids []osm.WayID, opts ...FeatureOption) (osm.Ways, error)

Ways returns the latest version of the ways from the osm rest api. Delegates to the DefaultDatasource and uses its http.Client to make the request.

Types

type Datasource

type Datasource struct {
	// If Limiter is non-nil. The datasource will wait/block until the request
	// is allowed by the rate limiter. To be a good citizen, it is recommended
	// to use this when making may concurrent requests against the prod osm api.
	// See the RateLimiter docs for more information.
	Limiter RateLimiter

	BaseURL string
	Client  *http.Client
}

Datasource defines context about the http client to use to make requests.

func NewDatasource

func NewDatasource(client *http.Client) *Datasource

NewDatasource creates a Datasource using the given client.

func (*Datasource) Changeset

func (ds *Datasource) Changeset(ctx context.Context, id osm.ChangesetID) (*osm.Changeset, error)

Changeset returns a given changeset from the osm rest api.

func (*Datasource) ChangesetDownload

func (ds *Datasource) ChangesetDownload(ctx context.Context, id osm.ChangesetID) (*osm.Change, error)

ChangesetDownload returns the full osmchange for the changeset using the osm rest api.

func (*Datasource) ChangesetWithDiscussion

func (ds *Datasource) ChangesetWithDiscussion(ctx context.Context, id osm.ChangesetID) (*osm.Changeset, error)

ChangesetWithDiscussion returns a changeset and its discussion from the osm rest api.

func (*Datasource) Map

func (ds *Datasource) Map(ctx context.Context, bounds *osm.Bounds, opts ...FeatureOption) (*osm.OSM, error)

Map returns the latest elements in the given bounding box.

func (*Datasource) Node

func (ds *Datasource) Node(ctx context.Context, id osm.NodeID, opts ...FeatureOption) (*osm.Node, error)

Node returns the latest version of the node from the osm rest api.

func (*Datasource) NodeHistory

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

NodeHistory returns all the versions of the node from the osm rest api.

func (*Datasource) NodeRelations

func (ds *Datasource) NodeRelations(ctx context.Context, id osm.NodeID, opts ...FeatureOption) (osm.Relations, error)

NodeRelations returns all relations a node is part of. There is no error if the element does not exist.

func (*Datasource) NodeVersion

func (ds *Datasource) NodeVersion(ctx context.Context, id osm.NodeID, v int) (*osm.Node, error)

NodeVersion returns the specific version of the node from the osm rest api.

func (*Datasource) NodeWays

func (ds *Datasource) NodeWays(ctx context.Context, id osm.NodeID, opts ...FeatureOption) (osm.Ways, error)

NodeWays returns all ways a node is part of. There is no error if the element does not exist.

func (*Datasource) Nodes

func (ds *Datasource) Nodes(ctx context.Context, ids []osm.NodeID, opts ...FeatureOption) (osm.Nodes, error)

Nodes returns the latest version of the nodes from the osm rest api. Will return 404 if any node is missing.

func (*Datasource) NotFound

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

NotFound error will return true if the result is not found.

func (*Datasource) Note

func (ds *Datasource) Note(ctx context.Context, id osm.NoteID) (*osm.Note, error)

Note returns the note from the osm rest api.

func (*Datasource) Notes

func (ds *Datasource) Notes(ctx context.Context, bounds *osm.Bounds, opts ...NotesOption) (osm.Notes, error)

Notes returns the notes in a bounding box. Can provide options to limit the results or change what it means to be "closed". See the options or osm api v0.6 docs for details.

func (*Datasource) NotesSearch

func (ds *Datasource) NotesSearch(ctx context.Context, query string, opts ...NotesOption) (osm.Notes, error)

NotesSearch returns the notes whose text matches the query. Can provide options to limit the results or change what it means to be "closed". See the options or osm api v0.6 docs for details.

func (*Datasource) Relation

func (ds *Datasource) Relation(ctx context.Context, id osm.RelationID, opts ...FeatureOption) (*osm.Relation, error)

Relation returns the latest version of the relation from the osm rest api.

func (*Datasource) RelationFull

func (ds *Datasource) RelationFull(ctx context.Context, id osm.RelationID, opts ...FeatureOption) (*osm.OSM, error)

RelationFull returns the relation and its nodes for the latest version the relation.

func (*Datasource) RelationHistory

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

RelationHistory returns all the versions of the relation from the osm rest api.

func (*Datasource) RelationRelations

func (ds *Datasource) RelationRelations(ctx context.Context, id osm.RelationID, opts ...FeatureOption) (osm.Relations, error)

RelationRelations returns all relations a relation is part of. There is no error if the element does not exist.

func (*Datasource) RelationVersion

func (ds *Datasource) RelationVersion(ctx context.Context, id osm.RelationID, v int) (*osm.Relation, error)

RelationVersion returns the specific version of the relation from the osm rest api.

func (*Datasource) Relations

func (ds *Datasource) Relations(ctx context.Context, ids []osm.RelationID, opts ...FeatureOption) (osm.Relations, error)

Relations returns the latest version of the relations from the osm rest api. Will return 404 if any node is missing.

func (*Datasource) User

func (ds *Datasource) User(ctx context.Context, id osm.UserID) (*osm.User, error)

User returns the user from the osm rest api.

func (*Datasource) Way

func (ds *Datasource) Way(ctx context.Context, id osm.WayID, opts ...FeatureOption) (*osm.Way, error)

Way returns the latest version of the way from the osm rest api.

func (*Datasource) WayFull

func (ds *Datasource) WayFull(ctx context.Context, id osm.WayID, opts ...FeatureOption) (*osm.OSM, error)

WayFull returns the way and its nodes for the latest version the way.

func (*Datasource) WayHistory

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

WayHistory returns all the versions of the way from the osm rest api.

func (*Datasource) WayRelations

func (ds *Datasource) WayRelations(ctx context.Context, id osm.WayID, opts ...FeatureOption) (osm.Relations, error)

WayRelations returns all relations a way is part of. There is no error if the element does not exist.

func (*Datasource) WayVersion

func (ds *Datasource) WayVersion(ctx context.Context, id osm.WayID, v int) (*osm.Way, error)

WayVersion returns the specific version of the way from the osm rest api.

func (*Datasource) Ways

func (ds *Datasource) Ways(ctx context.Context, ids []osm.WayID, opts ...FeatureOption) (osm.Ways, error)

Ways returns the latest version of the ways from the osm rest api. Will return 404 if any way is missing.

type FeatureOption

type FeatureOption interface {
	// contains filtered or unexported methods
}

FeatureOption can be used when fetching a feature or a set of different features.

func At

func At(t time.Time) FeatureOption

At adds an `at=2006-01-02T15:04:05Z` parameter to the request. The osm.fyi supports requesting features and maps as they were at the given time.

type ForbiddenError

type ForbiddenError struct {
	URL string
}

ForbiddenError means 403 from the api. Returned whenever the version of the element is not available (due to redaction).

func (*ForbiddenError) Error

func (e *ForbiddenError) Error() string

Error returns an error message with the url causing the problem.

type GoneError

type GoneError struct {
	URL string
}

GoneError is returned for deleted elements that get 410 from the api.

func (*GoneError) Error

func (e *GoneError) Error() string

Error returns an error message with the url causing the problem.

type NotFoundError

type NotFoundError struct {
	URL string
}

NotFoundError means 404 from the api.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

Error returns an error message with the url causing the problem.

type NotesOption

type NotesOption interface {
	// contains filtered or unexported methods
}

NotesOption defines a valid option for the osmapi.Notes by bounding box api.

func Limit

func Limit(num int) NotesOption

Limit indicates the number of results to return valid values [1,10000]. Default is 100.

func MaxDaysClosed

func MaxDaysClosed(num int) NotesOption

MaxDaysClosed specifies the number of days a note needs to be closed to no longer be returned. 0 will return only open notes, -1 will return all notes. Default is 7.

type RateLimiter

type RateLimiter interface {
	Wait(context.Context) error
}

A RateLimiter is something that can wait until its next allowed request. This interface is met by `golang.org/x/time/rate.Limiter` and is meant to be used with it. For example:

// 10 qps
osmapi.DefaultDatasource.Limiter = rate.NewLimiter(10, 1)

type RequestURITooLongError

type RequestURITooLongError struct {
	URL string
}

RequestURITooLongError is returned when requesting too many ids in a multi id request, ie. Nodes, Ways, Relations functions.

func (*RequestURITooLongError) Error

func (e *RequestURITooLongError) Error() string

Error returns an error message with the url causing the problem.

type UnexpectedStatusCodeError

type UnexpectedStatusCodeError struct {
	Code int
	URL  string
}

UnexpectedStatusCodeError is return for a non 200 or 404 status code.

func (*UnexpectedStatusCodeError) Error

func (e *UnexpectedStatusCodeError) Error() string

Error returns an error message with some information.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL