以知车辆在A路上向B方向行使,在路口转进C路,朝D方向驶去。。如何使用openstreetmap自动判断车辆是左转或者右转?
我的解题思路是通过 OSM API获得道路类型便签,通过道路类型标签来判断是否左转或右转
参考部分代码示例
from OSMPythonTools.nominatim import Nominatim
from OSMPythonTools.api import Api
nominatim = Nominatim()
api = Api()
def judge(lat, lon):
if not (-90 <= lat < 90 and -180 <= lat < 180):
return "input error"
result = nominatim.query(lat,lon, reverse=True, zoom=17)
location=result.toJSON()[0]
osm_type = location["osm_type"]
osm_id = location["osm_id"]
query = api.query('{}/{}'.format(osm_type, osm_id))
tags= query.tags()
if 'highway' in tags:
highway=tags['highway']
print(highway)
if highway=="motorway":
road_class = "自専道"
elif highway=="trunk" or highway=="primary":
road_class = "幹線道路"
else:
road_class = "市街地"
else:
road_class = "unclear"
return road_class
// test:
// lat: 纬度 lon:经度
lat=[42.28362183930613,42.325545, 42.290213]
lon=[-83.787700,-83.651853,-83.769023]
for la, lo in zip(lat,lon):
judge(lat=la, lon=lo)