[英]export gpx file with python?
我想從https://routing.openstreetmap.de導出(下載)一個 gpx 文件,當你請求方向 url 是這樣的: https://routing.openstreetmap.de/?z=17¢er=51.515199%2C-0.092772 &loc=51.514739%2C-0.089800&loc=51.516214%2C-0.096656&hl=en&alt=0&srv=1
使用 python 我想在將新的 loc=lat-lon&loc=lat-lon 插入到 url 后導出 gpx 文件。在檢查站點后,這個跨度 class 可以下載。
請伙計們。 至少一個提示
編輯這部分是在回答后添加的
並且對於 json 請求,我使用此代碼僅獲得兩分:
import requests
import json
lat_start = 36.5924
lon_start = 2.9898
lat_dist = 36.6429
lon_dist = 2.9929
url = 'https://routing.openstreetmap.de/routed-car/route/v1/driving/'+ str(lat_start)+','+str(lon_start)+';'+str(lat_dist)+','+str(lon_dist)+'?overview=false&alternatives=true&steps=true'
#url = 'https://routing.openstreetmap.de/routed-car/route/v1/driving/-0.0898,51.514739;-0.096656,51.516214?overview=false&alternatives=true&steps=true'
response = requests.get(url)
data = response.json()
print('DATA ___________________________________________________')
print(data)
mrks = []
for elements in data['routes']:
#print('ROUTES___________________________________________________')
#print(elements)
for legs in elements['legs']:
#print('legs___________________________________________________')
#print(legs)
for steps in legs['steps']:
#print('steps___________________________________________________')
#print(steps)
for intersections in steps['intersections']:
#print('intersections___________________________________________________')
#print(intersections)
for location in intersections['location']:
#print(location)
mrks.append(location)
#print(mrks)
twin = []
for i in range(0, len(mrks),2):
twin.append(str(mrks[i])+'___'+str(mrks[i+1]))
print('points ___________________________________________________')
for points in twin:
print(points)
它似乎使用JavaScript
從 API 獲取數據作為 JSON 並在 memory(帶有gpx
數據的blob
)中創建數據,當您單擊它時,它會直接從 memory 發送數據( blob
) - 所以沒有 886026588 當我使用click()
時,它會詢問文件夾,這需要手動單擊。
似乎獲得JSON
比gpx
更簡單
而url
到JSON
數據也用-0.0898,51.514739;-0.096656,51.516214
編輯:鏈接到 web 頁面使用經緯度lat,lon
但鏈接到 JSON 需要lon,lat
import requests
start_lon = -0.0898 # can be also as text
start_lat = 51.514739 # can be also as text
end_lon = -0.096656 # can be also as text
end_lat = 51.516214 # can be also as text
data = f"{start_lon},{start_lat};{end_lon},{end_lat}"
transport = 'bike' # 'car', 'foot'
url = f'https://routing.openstreetmap.de/routed-{transport}/route/v1/driving/{data}'
payload = {
'overview': 'false', # can't be True/False
'alternatives': 'true', # can't be True/False
'steps': 'true', # can't be True/False
}
response = requests.get(url, params=payload)
print(response.url)
#print(response.text)
print('---')
data = response.json()
for point in data['waypoints']:
print('name:', point['name'])
print('distance:', point['distance'])
print('location:', point['location'])
print('---')
結果:
url: https://routing.openstreetmap.de/routed-bike/route/v1/driving/-0.0898,51.514739;-0.096656,51.516214?overview=false&alternatives=true&steps=true
---
name: Princes Street
distance: 4.955845
location: [-0.089734, 51.514722]
---
name: Gresham Street
distance: 8.8597
location: [-0.096605, 51.516287]
---
編輯:
路由和 python 模塊的一些文檔PyrouteLib , SimpleOsmRouter
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.