package module
Version: v0.0.0-...-065e7d4 Latest Latest

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

Go to latest
Published: Oct 22, 2020 License: MIT Imports: 6 Imported by: 0



go-overpass is a Go library for accessing the Overpass API

Documentation: GoDoc



Package go-overpass provides a client for using the Overpass API.


import "github.com/serjvanilla/go-overpass"

Construct a new client, then use Query method on the client to receive result for your OverpassQL queries.

client := overpass.New()

//Retrive relation with all its members, recursively.
result, _ := client.Query("[out:json];relation(1673881);>>;out body;")
//Take a note that you shoud use "[out:json]" in your query for correct work.

Default client uses overpass-api.de endpoint but you can choose another with NewWithSettings method.

client := overpass.NewWithSettings("http://api.openstreetmap.fr/oapi/interpreter/", 1, http.DefaultClient)

You also can use default client directly by calling Query independently.

result, _ := overpass.Query("[out:json];relation(1673881);>>;out body;")

Rate limiting

Library respects servers rate limits and will not perform more than one request simultaneously with default client. With custom client you able to adjust that value.



This section is empty.


View Source
var (
	// ErrHTTPError is returned on HTTP client errors
	ErrHTTPError = errors.New("HTTP error")
	// ErrOverpassError is returned when overpass returns not valid response
	ErrOverpassError = errors.New("Overpass engine error")
View Source
var DefaultClient = New()


This section is empty.


type Client

type Client struct {
	// contains filtered or unexported fields

A Client manages communication with the Overpass API.

func New

func New() Client

New returns Client instance with default overpass-api.de endpoint.

func NewWithSettings

func NewWithSettings(
	apiEndpoint string,
	maxParallel int,
	httpClient *http.Client,
) Client

NewWithSettings returns Client with custom settings.

func (*Client) Query

func (c *Client) Query(query string) (Result, error)

Query send request to OverpassAPI with provided querystring.

type ElementType

type ElementType string

ElementType represents possible types for Overpass response elements.

const (
	ElementTypeNode     ElementType = "node"
	ElementTypeWay      ElementType = "way"
	ElementTypeRelation ElementType = "relation"

Possible values are node, way and relation.

type Meta

type Meta struct {
	ID        int64
	Timestamp *time.Time
	Version   int64
	Changeset int64
	User      string
	UID       int64
	Tags      map[string]string

Meta contains fields common for all OSM types.

type Node

type Node struct {
	Lat float64
	Lon float64

Node represents OSM node type.

type Relation

type Relation struct {
	Members []RelationMember

Relation represents OSM relation type.

type RelationMember

type RelationMember struct {
	Type     ElementType
	Node     *Node
	Way      *Way
	Relation *Relation
	Role     string

RelationMember represents OSM relation member type.

type Result

type Result struct {
	Count     int
	Nodes     map[int64]*Node
	Ways      map[int64]*Way
	Relations map[int64]*Relation

Result returned by Query and contains parsed result of Overpass query.

func Query

func Query(query string) (Result, error)

Query runs query with default client.

type Way

type Way struct {
	Nodes []*Node

Way represents OSM way type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL