overpass

package module
v0.0.0-...-5860637 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2022 License: MIT Imports: 6 Imported by: 3

README

go-overpass

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

Documentation: GoDoc

Documentation

Overview

Package overpass provides a client for using the Overpass API.

Usage:

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()

//Retrieve relation with all its members, recursively.
result, _ := client.Query("[out:json];relation(1673881);>>;out body;")
//Take a note that you should 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 are able to adjust that value.

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = New()

Functions

This section is empty.

Types

type Box

type Box struct {
	Min, Max Point
}

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 HTTPClient,
) 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 HTTPClient

type HTTPClient interface {
	PostForm(url string, data url.Values) (*http.Response, error)
}

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 {
	Meta
	Lat float64
	Lon float64
}

Node represents OSM node type.

type Point

type Point struct {
	Lat, Lon float64
}

type Relation

type Relation struct {
	Meta
	Members []RelationMember
	Bounds  *Box
}

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 {
	Timestamp time.Time
	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 ServerError

type ServerError struct {
	StatusCode int
	Body       []byte
}

func (*ServerError) Error

func (e *ServerError) Error() string

type Way

type Way struct {
	Meta
	Nodes    []*Node
	Bounds   *Box
	Geometry []Point
}

Way represents OSM way type.

Jump to

Keyboard shortcuts

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