Class: Underpass::QL::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/underpass/ql/query.rb

Overview

High-level entry point for querying the Overpass API.

Glues together Request, Client, Response, QueryAnalyzer, and Matcher to provide a single-call interface.

Examples:

Query with a bounding box

features = Underpass::QL::Query.perform(bbox, 'way["building"="yes"];')

Query with a named area

features = Underpass::QL::Query.perform_in_area('Romania', 'node["place"="city"];')

Class Method Summary collapse

Class Method Details

.perform(bounding_box, query) ⇒ Array<Feature>

Queries the Overpass API within a bounding box.

Parameters:

  • bounding_box (RGeo::Feature::Geometry)

    an RGeo polygon defining the search area

  • query (String, Builder)

    an Overpass QL query string or a Builder instance

Returns:

  • (Array<Feature>)

    the matched features

Raises:

  • (RateLimitError)

    when rate limited after exhausting retries

  • (TimeoutError)

    when the API times out after exhausting retries

  • (ApiError)

    when the API returns an unexpected error



25
26
27
28
29
30
# File 'lib/underpass/ql/query.rb', line 25

def self.perform(bounding_box, query)
  query_string     = resolve_query(query)
  op_bbox          = Underpass::QL::BoundingBox.from_geometry(bounding_box)
  request          = Underpass::QL::Request.new(query_string, op_bbox)
  execute(request, query_string)
end

.perform_in_area(area_name, query) ⇒ Array<Feature>

Queries the Overpass API within a named area (e.g. “Romania”).

Parameters:

  • area_name (String)

    an OSM area name

  • query (String, Builder)

    an Overpass QL query string or a Builder instance

Returns:

  • (Array<Feature>)

    the matched features

Raises:

  • (RateLimitError)

    when rate limited after exhausting retries

  • (TimeoutError)

    when the API times out after exhausting retries

  • (ApiError)

    when the API returns an unexpected error



40
41
42
43
44
# File 'lib/underpass/ql/query.rb', line 40

def self.perform_in_area(area_name, query)
  query_string = resolve_query(query)
  request      = Underpass::QL::Request.new(query_string, nil, area_name: area_name)
  execute(request, query_string)
end