在 python 中使用 OverpassAPI 生成的 JSON 中提取参数 "maxspeed"
Extract parameter "maxspeed" from JSON generated with OverpassAPI in python
这是我的 JSON:
{
"version": 0.6,
"generator": "Overpass API 0.7.56.1004 6cd3eaec",
"osm3s": {
"timestamp_osm_base": "2020-05-01T10:56:02Z",
"copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
},
"elements": [
{
"type": "way",
"id": 196511254,
"nodes": [
247532020,
3433695944,
7274513850,
247527633
],
"tags": {
"access": "no",
"access:conditional": "delivery @ (05:00-13:00)",
"bicycle": "yes",
"foot": "yes",
"highway": "residential",
"maxspeed": "30",
"maxspeed:zone": "yes",
"name": "De Keyserlei",
"note": "access = no according to traffic sign",
"psv": "yes",
"surface": "asphalt",
"wikidata": "Q2207937",
"wikipedia": "nl:De Keyserlei"
}
}
]
}
我设法编写代码,获取参数 "elements" 然后我可以打印它。但在 "elements" 中还有 "tags",然后是 "maxspeed"
def get_speed_limit():
radius = 1
lat = 51.217473152637275
lon = 4.418572667839149
result = """https://overpass-api.de/api/interpreter?data=[out:json][timeout:25];way(around:"""+str(radius)+""","""+str(lat)+""","""+str(lon)+""")[maxspeed];out;"""
response = ox.requests.get(result)
data = response.json()
elements = data["elements"]
print(elements)
我的问题是如何提取更深层的参数:"maxspeed"?
data["elements"][0]["tags"]["maxspeed"]
(如果 data["elements"]
中的项目多于一个,您需要遍历它们)
这是我的 JSON:
{
"version": 0.6,
"generator": "Overpass API 0.7.56.1004 6cd3eaec",
"osm3s": {
"timestamp_osm_base": "2020-05-01T10:56:02Z",
"copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
},
"elements": [
{
"type": "way",
"id": 196511254,
"nodes": [
247532020,
3433695944,
7274513850,
247527633
],
"tags": {
"access": "no",
"access:conditional": "delivery @ (05:00-13:00)",
"bicycle": "yes",
"foot": "yes",
"highway": "residential",
"maxspeed": "30",
"maxspeed:zone": "yes",
"name": "De Keyserlei",
"note": "access = no according to traffic sign",
"psv": "yes",
"surface": "asphalt",
"wikidata": "Q2207937",
"wikipedia": "nl:De Keyserlei"
}
}
]
}
我设法编写代码,获取参数 "elements" 然后我可以打印它。但在 "elements" 中还有 "tags",然后是 "maxspeed"
def get_speed_limit():
radius = 1
lat = 51.217473152637275
lon = 4.418572667839149
result = """https://overpass-api.de/api/interpreter?data=[out:json][timeout:25];way(around:"""+str(radius)+""","""+str(lat)+""","""+str(lon)+""")[maxspeed];out;"""
response = ox.requests.get(result)
data = response.json()
elements = data["elements"]
print(elements)
我的问题是如何提取更深层的参数:"maxspeed"?
data["elements"][0]["tags"]["maxspeed"]
(如果 data["elements"]
中的项目多于一个,您需要遍历它们)