Documentation
¶
Overview ¶
Package overpass provides a client for using the Overpass API.
Usage:
import "github.com/MeKo-Christian/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 ¶
- Variables
- type BoundingBox
- type Box
- type CacheConfig
- type Category
- type Client
- func (c *Client) CacheSize() int
- func (c *Client) ClearCache()
- func (c *Client) Close()
- func (c *Client) Query(query string) (Result, error)
- func (c *Client) QueryContext(ctx context.Context, query string) (Result, error)
- func (c *Client) QueryWithBuilder(ctx context.Context, builder *QueryBuilder) (Result, error)
- func (c *Client) SetCacheConfig(config CacheConfig)
- func (c *Client) SetRetryConfig(config RetryConfig)
- type ElementType
- type HTTPClient
- type Meta
- func (m *Meta) GetCategory() Category
- func (m *Meta) GetName() string
- func (m *Meta) GetSubcategory() string
- func (m *Meta) GetTag(key, defaultValue string) string
- func (m *Meta) HasTag(key string) bool
- func (m *Meta) IsAmenity() bool
- func (m *Meta) IsBuilding() bool
- func (m *Meta) IsEducation() bool
- func (m *Meta) IsFoodRelated() bool
- func (m *Meta) IsHealthcare() bool
- func (m *Meta) IsNatural() bool
- func (m *Meta) IsRailway() bool
- func (m *Meta) IsRoad() bool
- func (m *Meta) IsTransportation() bool
- func (m *Meta) IsWater() bool
- func (m *Meta) MatchesFilter(key, value string) bool
- type Node
- type Point
- type QueryBuilder
- func FindAmenity(south, west, north, east float64, amenityType string) *QueryBuilder
- func FindByTag(south, west, north, east float64, key, value string) *QueryBuilder
- func FindHighways(south, west, north, east float64, highwayType string) *QueryBuilder
- func FindRestaurants(south, west, north, east float64) *QueryBuilder
- func NewQueryBuilder() *QueryBuilder
- func (qb *QueryBuilder) BBox(south, west, north, east float64) *QueryBuilder
- func (qb *QueryBuilder) Build() string
- func (qb *QueryBuilder) Node() *QueryBuilder
- func (qb *QueryBuilder) Output(mode string) *QueryBuilder
- func (qb *QueryBuilder) OutputBody() *QueryBuilder
- func (qb *QueryBuilder) OutputCenter() *QueryBuilder
- func (qb *QueryBuilder) OutputGeom() *QueryBuilder
- func (qb *QueryBuilder) OutputMeta() *QueryBuilder
- func (qb *QueryBuilder) Relation() *QueryBuilder
- func (qb *QueryBuilder) String() string
- func (qb *QueryBuilder) Tag(key, value string) *QueryBuilder
- func (qb *QueryBuilder) TagExists(key string) *QueryBuilder
- func (qb *QueryBuilder) TagNot(key, value string) *QueryBuilder
- func (qb *QueryBuilder) TagRegex(key, pattern string) *QueryBuilder
- func (qb *QueryBuilder) Timeout(seconds int) *QueryBuilder
- func (qb *QueryBuilder) Way() *QueryBuilder
- type Relation
- type RelationMember
- type Result
- type RetryConfig
- type ServerError
- type TagFilter
- type Way
Constants ¶
This section is empty.
Variables ¶
var DefaultClient = New()
Functions ¶
This section is empty.
Types ¶
type BoundingBox ¶
type BoundingBox struct {
South, West, North, East float64
}
BoundingBox represents geographic bounds (south, west, north, east).
type CacheConfig ¶
type CacheConfig struct {
Enabled bool // Enable/disable caching (default: false)
TTL time.Duration // Time-to-live for cache entries (default: 5 minutes)
MaxEntries int // Maximum cache entries (0 = unlimited, default: 1000)
}
CacheConfig holds cache behavior configuration.
func DefaultCacheConfig ¶
func DefaultCacheConfig() CacheConfig
DefaultCacheConfig returns sensible defaults (DISABLED by default).
type Category ¶
type Category string
Category represents high-level OSM feature category.
const ( CategoryTransportation Category = "transportation" CategoryAmenity Category = "amenity" CategoryNatural Category = "natural" CategoryWater Category = "water" CategoryBuilding Category = "building" CategoryLeisure Category = "leisure" CategoryLanduse Category = "landuse" CategoryBoundary Category = "boundary" CategoryPlace Category = "place" CategoryShop Category = "shop" CategoryTourism Category = "tourism" CategoryUnknown Category = "unknown" )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client manages communication with the Overpass API.
func NewWithRetry ¶
func NewWithRetry( apiEndpoint string, maxParallel int, httpClient HTTPClient, retryConfig RetryConfig, ) Client
NewWithRetry returns Client with custom retry configuration.
func NewWithSettings ¶
func NewWithSettings( apiEndpoint string, maxParallel int, httpClient HTTPClient, ) Client
NewWithSettings returns Client with custom settings.
func (*Client) Close ¶
func (c *Client) Close()
Close stops the cache cleanup routine and releases resources.
func (*Client) Query ¶
Query is deprecated: use QueryContext instead. It sends request to OverpassAPI with context.Background().
func (*Client) QueryContext ¶
QueryContext sends request to OverpassAPI with provided querystring and context for cancellation/timeout.
func (*Client) QueryWithBuilder ¶
QueryWithBuilder executes query from builder (convenience method).
func (*Client) SetCacheConfig ¶
func (c *Client) SetCacheConfig(config CacheConfig)
SetCacheConfig updates the cache configuration for the client.
func (*Client) SetRetryConfig ¶
func (c *Client) SetRetryConfig(config RetryConfig)
SetRetryConfig updates the retry configuration for the client.
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 ¶
HTTPClient interface for making HTTP requests with context support.
type Meta ¶
type Meta struct {
ID int64 `json:"id"`
Timestamp *time.Time `json:"timestamp,omitempty"`
Version int64 `json:"version,omitempty"`
Changeset int64 `json:"changeset,omitempty"`
User string `json:"user,omitempty"`
UID int64 `json:"uid,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
}
Meta contains fields common for all OSM types.
func (*Meta) GetCategory ¶
GetCategory returns high-level category based on OSM tags.
func (*Meta) GetSubcategory ¶
GetSubcategory returns detailed subcategory (tag value).
func (*Meta) IsBuilding ¶
IsBuilding checks if element is a building.
func (*Meta) IsEducation ¶
IsEducation checks if amenity is education-related.
func (*Meta) IsFoodRelated ¶
IsFoodRelated checks if amenity is food/drink related.
func (*Meta) IsHealthcare ¶
IsHealthcare checks if amenity is healthcare-related.
func (*Meta) IsTransportation ¶
IsTransportation checks if element is transportation-related.
func (*Meta) MatchesFilter ¶
MatchesFilter checks if element matches tag filter.
type QueryBuilder ¶
type QueryBuilder struct {
// contains filtered or unexported fields
}
QueryBuilder provides fluent API for building Overpass QL queries.
func FindAmenity ¶
func FindAmenity(south, west, north, east float64, amenityType string) *QueryBuilder
FindAmenity creates query for amenity type in bounding box.
func FindByTag ¶
func FindByTag(south, west, north, east float64, key, value string) *QueryBuilder
FindByTag creates query for elements with specific tag in bounding box.
func FindHighways ¶
func FindHighways(south, west, north, east float64, highwayType string) *QueryBuilder
FindHighways creates query for highways in bounding box.
func FindRestaurants ¶
func FindRestaurants(south, west, north, east float64) *QueryBuilder
FindRestaurants creates query for restaurants in bounding box.
func NewQueryBuilder ¶
func NewQueryBuilder() *QueryBuilder
NewQueryBuilder creates new query builder with [out:json] default.
func (*QueryBuilder) BBox ¶
func (qb *QueryBuilder) BBox(south, west, north, east float64) *QueryBuilder
BBox sets bounding box constraint.
func (*QueryBuilder) Build ¶
func (qb *QueryBuilder) Build() string
Build constructs the Overpass QL query string.
func (*QueryBuilder) Node ¶
func (qb *QueryBuilder) Node() *QueryBuilder
Node adds node element type to query.
func (*QueryBuilder) Output ¶
func (qb *QueryBuilder) Output(mode string) *QueryBuilder
Output sets output mode (body, skel, ids, tags, meta, center, geom, bb).
func (*QueryBuilder) OutputBody ¶
func (qb *QueryBuilder) OutputBody() *QueryBuilder
OutputBody outputs all information (default).
func (*QueryBuilder) OutputCenter ¶
func (qb *QueryBuilder) OutputCenter() *QueryBuilder
OutputCenter outputs center point only.
func (*QueryBuilder) OutputGeom ¶
func (qb *QueryBuilder) OutputGeom() *QueryBuilder
OutputGeom outputs with geometry (for ways/relations).
func (*QueryBuilder) OutputMeta ¶
func (qb *QueryBuilder) OutputMeta() *QueryBuilder
OutputMeta outputs with metadata.
func (*QueryBuilder) Relation ¶
func (qb *QueryBuilder) Relation() *QueryBuilder
Relation adds relation element type to query.
func (*QueryBuilder) String ¶
func (qb *QueryBuilder) String() string
String implements Stringer interface.
func (*QueryBuilder) Tag ¶
func (qb *QueryBuilder) Tag(key, value string) *QueryBuilder
Tag adds exact tag match filter.
func (*QueryBuilder) TagExists ¶
func (qb *QueryBuilder) TagExists(key string) *QueryBuilder
TagExists adds filter for tag existence (any value).
func (*QueryBuilder) TagNot ¶
func (qb *QueryBuilder) TagNot(key, value string) *QueryBuilder
TagNot adds negative tag match filter.
func (*QueryBuilder) TagRegex ¶
func (qb *QueryBuilder) TagRegex(key, pattern string) *QueryBuilder
TagRegex adds regex tag value filter.
func (*QueryBuilder) Timeout ¶
func (qb *QueryBuilder) Timeout(seconds int) *QueryBuilder
Timeout sets query timeout in seconds.
func (*QueryBuilder) Way ¶
func (qb *QueryBuilder) Way() *QueryBuilder
Way adds way element type to query.
type Relation ¶
type Relation struct {
Meta
Members []RelationMember `json:"members,omitempty"`
Bounds *Box `json:"bounds,omitempty"`
}
Relation represents OSM relation type.
type RelationMember ¶
type RelationMember struct {
Type ElementType `json:"type"`
Node *Node `json:"node,omitempty"`
Way *Way `json:"way,omitempty"`
Relation *Relation `json:"relation,omitempty"`
Role string `json:"role,omitempty"`
}
RelationMember represents OSM relation member type.
type Result ¶
type Result struct {
Timestamp time.Time `json:"timestamp"`
Count int `json:"count"`
Nodes map[int64]*Node `json:"nodes,omitempty"`
Ways map[int64]*Way `json:"ways,omitempty"`
Relations map[int64]*Relation `json:"relations,omitempty"`
}
Result returned by Query and contains parsed result of Overpass query.
func Query ¶
Query is deprecated: use QueryContext instead. It runs query with default client using context.Background().
func QueryContext ¶
QueryContext runs query with context using default client.
func QueryWithBuilder ¶
func QueryWithBuilder(ctx context.Context, builder *QueryBuilder) (Result, error)
QueryWithBuilder executes query from builder using DefaultClient.
type RetryConfig ¶
type RetryConfig struct {
MaxRetries int // Maximum retry attempts (default: 3)
InitialBackoff time.Duration // Initial backoff duration (default: 1s)
MaxBackoff time.Duration // Maximum backoff duration (default: 30s)
BackoffMultiplier float64 // Backoff multiplier (default: 2.0)
Jitter bool // Add randomization to prevent thundering herd (default: true)
}
RetryConfig holds retry behavior configuration.
func DefaultRetryConfig ¶
func DefaultRetryConfig() RetryConfig
DefaultRetryConfig returns sensible defaults.
type ServerError ¶
func (*ServerError) Error ¶
func (e *ServerError) Error() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
example
|
|
|
area_query
command
|
|
|
basic
command
|
|
|
custom_client
command
|
|
|
ways_and_relations
command
|
|