You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
response = api.Get('node["name"="Salt Lake City"]')
22
23
```
23
24
24
-
Note that you don't have to include any of the output meta statements.
25
-
The wrapper will, well, wrap those.
25
+
The API constructor takes several parameters, all optional:
26
26
27
-
You will get your result as a dictionary, which represents the
28
-
JSON output you would get [from the Overpass API
29
-
directly](http://overpass-api.de/output_formats.html#json>). So you
30
-
could do this for example:
27
+
#### `endpoint`
28
+
29
+
The default endpoint is `https://overpass-api.de/api/interpreter` but
30
+
you can pass in another instance:
31
31
32
32
```python
33
-
print [(feature['tags']['name'], feature['id']) for feature in response['elements']]
34
-
[(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637), (u'Salt Lake City', 1615721573)]
33
+
api = overpass.API(endpoint="https://overpass.myserver/interpreter")
35
34
```
36
35
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.
36
+
#### `timeout`
37
+
38
+
The default timeout is 25 seconds, but you can set it to whatever you
39
+
want.
38
40
39
41
```python
40
-
response=api.Get('node["name"="Salt Lake City"]', responseformat="xml")
42
+
api=overpass.API(timeout=600)
41
43
```
42
44
43
-
###Parameters
45
+
#### `debug`
44
46
47
+
Setting this to `True` will get you debug output.
45
48
46
-
The API object takes a few parameters:
49
+
### Getting data from Overpass: `get()`
47
50
48
-
#### endpoint
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.
49
52
50
-
The default endpoint is `http://overpass-api.de/api/interpreter` but
51
-
you can pass in another instance:
53
+
```python
54
+
response = api.get('node["name"="Salt Lake City"]')
**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.
62
+
63
+
Another example:
52
64
53
65
```python
54
-
api = overpass.API(endpoint=http://overpass.myserver/interpreter)
66
+
>>>print [(
67
+
... feature['properties']['name'],
68
+
... feature['id']) for feature in response["features"]]
69
+
[(u'Salt Lake City', 150935219), (u'Salt Lake City', 585370637)]
55
70
```
56
71
57
-
#### timeout
72
+
You can find more examples in the `examples/` directory of this repository.
58
73
59
-
The default timeout is 25 seconds, but you can set it to whatever you
60
-
want.
74
+
The `get()` method takes a few parameters, all optional having sensible defaults.
75
+
76
+
#### `verbosity`
77
+
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.
61
79
62
80
```python
63
-
api = overpass.API(timeout=600)
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"]
64
85
```
65
86
66
-
#### debug
87
+
(from [a question on GIS Stackexchange](https://gis.stackexchange.com/questions/294152/getting-all-information-about-ways-from-python-overpass-library/294358#294358))
67
88
68
-
Setting this to `True` will get you debug output.
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`).
92
+
93
+
```python
94
+
response = api.get('node["name"="Salt Lake City"]', responseformat="xml")
95
+
```
96
+
97
+
#### `build`
98
+
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.
69
100
70
-
### Simple queries
101
+
### Pre-cooked Queries: `MapQuery`, `WayQuery`
71
102
72
-
In addition to just send your query and parse the result, the wrapper
103
+
In addition to just sending your query and parse the result, `overpass`
73
104
provides shortcuts for often used map queries. To use them, just pass
0 commit comments