Files
sunnypilot/selfdrive/mapd/lib/osm.py
T
Jason Wen bf659453aa move-fast: mapd, Speed Limit Control, Vision & Map Turn Speed Control (#111)
* move-fast: Hands on wheel monitoring: Implementation according to r079r4e regulation

* move-fast: VisionTurnController Implementation & UI prerequisites

* move-fast: LiveMapData: Implementation & UI prerequisites

* add dependencies

* move-fast: SpeedLimitControl: Implementation & UI prerequisites

* move-fast: TurnSpeedController: Implementation & UI prerequisites

* move-fast: Debug: Tap on Ui to capture snapshot of debug data & UI prerequisites

* Debug UI: Toggle to display debug UI elements & UI prerequisites
2023-02-13 11:38:11 -05:00

38 lines
1.2 KiB
Python

import overpy
import numpy as np
from selfdrive.mapd.lib.geo import R
def create_way(way_id, node_ids, from_way):
"""
Creates and OSM Way with the given `way_id` and list of `node_ids`, copying attributes and tags from `from_way`
"""
return overpy.Way(way_id, node_ids=node_ids, attributes={}, result=from_way._result,
tags=from_way.tags)
class OSM():
def __init__(self):
self.api = overpy.Overpass()
# self.api = overpy.Overpass(url='http://3.65.170.21/api/interpreter')
def fetch_road_ways_around_location(self, lat, lon, radius):
# Calculate the bounding box coordinates for the bbox containing the circle around location.
bbox_angle = np.degrees(radius / R)
# fetch all ways and nodes on this ways in bbox
bbox_str = f'{str(lat - bbox_angle)},{str(lon - bbox_angle)},{str(lat + bbox_angle)},{str(lon + bbox_angle)}'
q = """
way(""" + bbox_str + """)
[highway]
[highway!~"^(footway|path|corridor|bridleway|steps|cycleway|construction|bus_guideway|escape|service|track)$"];
(._;>;);
out;
"""
try:
ways = self.api.query(q).ways
except Exception as e:
print(f'Exception while querying OSM:\n{e}')
ways = []
return ways