Skip to content

Commit afbaa5d

Browse files
committed
improvements on documentation
1 parent c8f96ff commit afbaa5d

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ eggs/
1010
*.egg
1111
pip-log.txt
1212
docs/_build/
13-
Pipfile.lock
13+
Pipfile.lock
14+
venv/

Diff for: README.md

+50-24
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,52 @@ Install it
1313

1414
## Usage
1515

16-
Simplest example:
16+
### `API()` constructor
17+
18+
First, create an API object.
1719

1820
```python
1921
import overpass
2022
api = overpass.API()
23+
```
24+
25+
The API constructor takes several parameters, all optional:
26+
27+
#### `endpoint`
28+
29+
The default endpoint is `https://overpass-api.de/api/interpreter` but
30+
you can pass in another instance:
31+
32+
```python
33+
api = overpass.API(endpoint=https://overpass.myserver/interpreter)
34+
```
35+
36+
#### `timeout`
37+
38+
The default timeout is 25 seconds, but you can set it to whatever you
39+
want.
40+
41+
```python
42+
api = overpass.API(timeout=600)
43+
```
44+
45+
#### `debug`
46+
47+
Setting this to `True` will get you debug output.
48+
49+
### Getting data from Overpass: `get()`
50+
51+
Most users will only ever need to use the `get()` method. There are some convenience query methods for common queries as well, see below.
52+
53+
```python
2154
response = api.get('node["name"="Salt Lake City"]')
2255
```
2356

2457
`response` will be a dictionary representing the
2558
JSON output you would get [from the Overpass API
2659
directly](https://overpass-api.de/output_formats.html#json).
2760

28-
Note that the Overpass query passed to `get()` should not contain any `out` or other meta statements.
61+
**Note that the Overpass query passed to `get()` should not contain any `out` or other meta statements.** See `verbosity` below for how to control the output.
2962

3063
Another example:
3164

@@ -38,41 +71,34 @@ Another example:
3871

3972
You can find more examples in the `examples/` directory of this repository.
4073

41-
### Response formats
74+
The `get()` method takes a few parameters, all optional having sensible defaults.
4275

43-
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`).
76+
#### `verbosity`
4477

45-
```python
46-
response = api.get('node["name"="Salt Lake City"]', responseformat="xml")
47-
```
48-
49-
### Parameters
50-
51-
The API object takes a few parameters:
52-
53-
#### `endpoint`
54-
55-
The default endpoint is `https://overpass-api.de/api/interpreter` but
56-
you can pass in another instance:
78+
You can set the verbosity of the [Overpass query `out` directive](https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#out) using the same keywords Overpass does. In order of increased verbosity: `ids`, `skel`, `body`, `tags`, `meta`. As is the case with the Overpass API itself, `body` is the default.
5779

5880
```python
59-
api = overpass.API(endpoint=https://overpass.myserver/interpreter)
81+
>>> import overpass
82+
>>> api = overpass.API()
83+
>>> data = api.get('way(42.819,-73.881,42.820,-73.880);(._;>;)', verbosity='geom')
84+
>>> [f for f in data.features if f.geometry['type'] == "LineString"]
6085
```
6186

62-
#### `timeout`
87+
(from [a question on GIS Stackexchange](https://gis.stackexchange.com/questions/294152/getting-all-information-about-ways-from-python-overpass-library/294358#294358))
6388

64-
The default timeout is 25 seconds, but you can set it to whatever you
65-
want.
89+
#### `responseformat`
90+
91+
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`).
6692

6793
```python
68-
api = overpass.API(timeout=600)
94+
response = api.get('node["name"="Salt Lake City"]', responseformat="xml")
6995
```
7096

71-
#### `debug`
97+
#### `build`
7298

73-
Setting this to `True` will get you debug output.
99+
We will construct a valid Overpass QL query from the parameters you set by default. This means you don't have to include 'meta' statements like `[out:json]`, `[timeout:60]`, `[out body]`, etcetera. You just supply the meat of the query, the part that actually tells Overpass what to query for. If for whatever reason you want to override this and supply a full, valid Overpass QL query, you can set `build` to `False` to make the API not do any pre-processing.
74100

75-
### Simple queries
101+
### Pre-cooked Queries: `MapQuery`, `WayQuery`
76102

77103
In addition to just sending your query and parse the result, `overpass`
78104
provides shortcuts for often used map queries. To use them, just pass

0 commit comments

Comments
 (0)