Skip to content

Commit f07db0d

Browse files
committed
Updating README and examples
1 parent 04feb8b commit f07db0d

File tree

3 files changed

+44
-22
lines changed

3 files changed

+44
-22
lines changed

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,34 @@ api = overpass.API()
2121
response = api.get('node["name"="Salt Lake City"]')
2222
```
2323

24-
Note that you don't have to include any of the output meta statements.
25-
The wrapper will, well, wrap those.
26-
27-
You will get your result as a dictionary, which represents the
24+
`response` will be a dictionary representing the
2825
JSON output you would get [from the Overpass API
29-
directly](https://overpass-api.de/output_formats.html#json). So you
30-
could do this for example:
26+
directly](https://overpass-api.de/output_formats.html#json).
27+
28+
Note that the Overpass query passed to `get()` should not contain any `out` or other meta statements.
29+
30+
Another example:
3131

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

37-
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.
37+
You can find more examples in the `examples/` directory of this repository.
38+
39+
### Response formats
40+
41+
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`).
3842

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

4347
### Parameters
4448

45-
4649
The API object takes a few parameters:
4750

48-
#### endpoint
51+
#### `endpoint`
4952

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

57-
#### timeout
60+
#### `timeout`
5861

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

66-
#### debug
69+
#### `debug`
6770

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

7073
### Simple queries
7174

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

@@ -98,7 +101,7 @@ response = api.get(WayQuery)
98101

99102
## Testing
100103

101-
Using `nose`.
104+
Using `pytest`.
102105

103106
`py.test`
104107

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

112115
### Where did the CLI tool go?
113116

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

3+
# Retrieves a list of turn restriction relations in Toronto.
4+
35
import overpass
46

57
api = overpass.API()
68

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

1011
turn_restrictions_list = []
@@ -15,10 +16,3 @@
1516
verbosity='meta')
1617

1718
print(overpass_response)
18-
# reader = csv.reader(response)
19-
# turn_restrictions_list = list(reader)
20-
21-
for row in overpass_response.split('\n'):
22-
turn_restrictions_list.append([elem for elem in row.split('\t')])
23-
24-
print(turn_restrictions_list)

examples/unique_users_for_area.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
3+
# Retrieves a list of unique usernames and user IDs for a named area.
4+
5+
import overpass
6+
7+
area_name = "Kanab"
8+
9+
query = """area[name="{}"]->.slc;(node(area.slc);<;);""".format(area_name)
10+
11+
users = {"ids": [], "usernames": []}
12+
api = overpass.API(debug=False)
13+
result = api.Get(
14+
query,
15+
responseformat="csv(::uid,::user)",
16+
verbosity="meta")
17+
del result[0] # header
18+
for row in result:
19+
uid = int(row[0])
20+
username = row[1]
21+
if uid in users["ids"]:
22+
continue
23+
users["ids"].append(uid)
24+
users["usernames"].append(username)
25+
print(users)

0 commit comments

Comments
 (0)