Closed pe-perry closed 6 years ago
That is confusing, you're right.
Will address in next release unless you beat me to it with a PR ✊
Would you propose to detect the format from the raw query? In that case we'd need to assume that the query always starts with [out:...]
-- or employ a regex to detect the [out:...]
statement. What do you think?
I prefer the former option, users are required to write a complete and valid overpass QL query if they set build=False
. What do you think?
Makes sense. We would then ignore outputformat
altogether (or even throw an exception when it is used in combination with build=False
) and just return the raw response body -- whatever that is. This basically would bypass any of the logic we use to parse the output. Sounds good?
It's one option, or should we keep the content_type checking part and return appropriate Python object?
if build is False
,
content_type == text/csv
: return str or list of lists (like what you did)content_type == "text/xml" or content_type == "application/xml"
: return str or tree object (in xml, lxml etc)content_type == "application/json"
: return dictI have pushed a branch, see if it is fine. :)
It looks like the bug re-appear again.
q = '[out:json];rel(336);out;'
data1 = api.get(q, build=False)
data2 = api._get_from_overpass(q).json()
Output:
# >>> print(data1)
# {
# "features": [],
# "type": "FeatureCollection"
# }
# >>> print(data2)
# {
# 'generator': 'Overpass API 0.7.55.5 2ca3f387',
# 'version': 0.6,
# 'osm3s': {
# 'copyright': 'The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.',
# 'timestamp_osm_base': '2018-12-22T13:51:02Z'
# },
# 'elements': [
# {
# 'type': 'relation',
# 'members': [
# {
# 'ref': 43759879,
# 'type': 'way',
# 'role': 'inner'
# },
# {
# 'ref': 30663172,
# 'type': 'way',
# 'role': 'outer'
# }
# ],
# 'id': 336,
# 'tags': {
# 'type': 'multipolygon',
# 'water': 'lake',
# 'name': 'Trollsvannet',
# 'natural': 'water'
# }
# }
# ]
# }
It is expected the following codes should produce the same output, but it turns out they didn't.
Code 1
Output:
Code 2
Output:
The reason should be the default value of
responseformat
(geojson). Although my query said I want a json, the.get()
method still convert it to geojson (default responseformat). To obtain the desired output, I have to addresponseformat='json'
.This looks redundant. Not sure if it is what you desired.