Skip to content

Commit

Permalink
Updating README and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mvexel committed Apr 6, 2018
1 parent 04feb8b commit f07db0d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,34 @@ api = overpass.API()
response = api.get('node["name"="Salt Lake City"]')
```

Note that you don't have to include any of the output meta statements.
The wrapper will, well, wrap those.

You will get your result as a dictionary, which represents the
`response` will be a dictionary representing the
JSON output you would get [from the Overpass API
directly](https://overpass-api.de/output_formats.html#json). So you
could do this for example:
directly](https://overpass-api.de/output_formats.html#json).

Note that the Overpass query passed to `get()` should not contain any `out` or other meta statements.

Another example:

```python
print [(feature['tags']['name'], feature['id']) for feature in response['elements']]
[(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637), (u'Salt Lake City', 1615721573)]
```

You can specify the format of the response. By default, you will get GeoJSON using the `responseformat` parameter. Alternatives are plain JSON (`json`) and OSM XML (`xml`), as ouput directly by the Overpass API.
You can find more examples in the `examples/` directory of this repository.

### Response formats

You can set the response type of your query using `get()`'s `responseformat` parameter to GeoJSON (`geojson`, the default), plain JSON (`json`), CSV (`csv`), and OSM XML (`xml`).

```python
response = api.get('node["name"="Salt Lake City"]', responseformat="xml")
```

### Parameters


The API object takes a few parameters:

#### endpoint
#### `endpoint`

The default endpoint is `https://overpass-api.de/api/interpreter` but
you can pass in another instance:
Expand All @@ -54,7 +57,7 @@ you can pass in another instance:
api = overpass.API(endpoint=https://overpass.myserver/interpreter)
```

#### timeout
#### `timeout`

The default timeout is 25 seconds, but you can set it to whatever you
want.
Expand All @@ -63,13 +66,13 @@ want.
api = overpass.API(timeout=600)
```

#### debug
#### `debug`

Setting this to `True` will get you debug output.

### Simple queries

In addition to just send your query and parse the result, the wrapper
In addition to just sending your query and parse the result, the wrapper
provides shortcuts for often used map queries. To use them, just pass
them like to normal query to the API.

Expand Down Expand Up @@ -98,7 +101,7 @@ response = api.get(WayQuery)

## Testing

Using `nose`.
Using `pytest`.

`py.test`

Expand All @@ -111,4 +114,4 @@ issue](https://github.com/mvexel/overpass-api-python-wrapper/issues).

### Where did the CLI tool go?

I decided that it does not belong in this repo. If you still want it, get version 0.4.0 or below.
The command line tool was deprecated in version 0.4.0.
10 changes: 2 additions & 8 deletions examples/turn_restriction_relations_as_list.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python3

# Retrieves a list of turn restriction relations in Toronto.

import overpass

api = overpass.API()

# Turn restrictions in Toronto
turn_restrictions_query = "relation[type=restriction](area:3600324211)"

turn_restrictions_list = []
Expand All @@ -15,10 +16,3 @@
verbosity='meta')

print(overpass_response)
# reader = csv.reader(response)
# turn_restrictions_list = list(reader)

for row in overpass_response.split('\n'):
turn_restrictions_list.append([elem for elem in row.split('\t')])

print(turn_restrictions_list)
25 changes: 25 additions & 0 deletions examples/unique_users_for_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python

# Retrieves a list of unique usernames and user IDs for a named area.

import overpass

area_name = "Kanab"

query = """area[name="{}"]->.slc;(node(area.slc);<;);""".format(area_name)

users = {"ids": [], "usernames": []}
api = overpass.API(debug=False)
result = api.Get(
query,
responseformat="csv(::uid,::user)",
verbosity="meta")
del result[0] # header
for row in result:
uid = int(row[0])
username = row[1]
if uid in users["ids"]:
continue
users["ids"].append(uid)
users["usernames"].append(username)
print(users)

0 comments on commit f07db0d

Please sign in to comment.