Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

brsntus/overpex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overpex

Build Status Hex.pm Coverage Status

Simple wrapper for Overpass API.

Installation

Add overpex to your list of dependencies in mix.exs:

def deps do
  [{:overpex, "~> 0.3.1"}]
end

Documentation can be found at https://hexdocs.pm/overpex.

Config

Set the URL for Overpass API in config/config.exs:

config :overpex,
  url: "http://overpass-api.de/api/interpreter"

The default URL is http://overpass-api.de/api/interpreter.

You can also set a timeout in miliseconds:

config :overpex,
  timeout: 10000 # timeout of 10 seconds

The default timeout is 5000 (5 seconds).

Usage

Query for nodes with name Gielgen without the body:

iex> Overpex.query(~s(node["name"="Gielgen"];out skel;))
{:ok,
 %Overpex.Response{nodes: [%Overpex.Node{id: 371597317, lat: 50.7412721,
    lon: 7.192712, tags: []},
   %Overpex.Node{id: 373373733, lat: 50.7290803, lon: 7.2176116, tags: []},
   %Overpex.Node{id: 507464799, lat: 50.739397, lon: 7.1959361, tags: []},
   (...)],
  relations: [], ways: []}}

Query for nodes with name Gielgen with the body:

iex> Overpex.query(~s(node["name"="Gielgen"];out body;))
{:ok,
 %Overpex.Response{nodes: [%Overpex.Node{id: 371597317, lat: 50.7412721,
    lon: 7.192712,
    tags: [%Overpex.Tag{key: "is_in",
      value: "Bonn,Regierungsbezirk Köln,Nordrhein-Westfalen,Bundesrepublik Deutschland,Europe"},
     %Overpex.Tag{key: "name", value: "Gielgen"},
     %Overpex.Tag{key: "place", value: "suburb"}]},
   %Overpex.Node{id: 373373733, lat: 50.7290803, lon: 7.2176116,
    tags: [%Overpex.Tag{key: "name", value: "Gielgen"},
     %Overpex.Tag{key: "shop", value: "bakery"},
     %Overpex.Tag{key: "wheelchair", value: "yes"}]},
   (...)],
  relations: [], ways: []}}

Overpex.Query/1 will automatically parse the response for you. In case you want to get the HTTP response and do the parse yourself, use Overpex.API.query/1:

iex> Overpex.API.query(~s(node["name"="Gielgen"];out skel;))
{:ok, {:xml, "(...)"}}
  
iex> Overpex.API.query(~s([out:json];node["name"="Gielgen"];out skel;))
{:ok, {:json, "(...)"}}

Credits

Inspired by https://github.com/CodeforChemnitz/elixir-overpass

License

The MIT License (MIT)