This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def generate_triples(hex_list: list[int]) -> list[(int,int,int)]: | |
| triples = [] | |
| if len(hex_list) > 2: | |
| for i in range(len(hex_list) - 2): | |
| t0, t1, t2 = hex_list[i:i + 3] | |
| triples.append((t0, t1, t2)) | |
| return triples |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from valhalla import Actor, get_config | |
| config = get_config(tile_extract='./valhalla/custom_files/valhalla_tiles.tar', | |
| verbose=True) | |
| actor = Actor(config) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pip install pyvalhalla |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| docker run -it --rm --name valhalla_gis-ops -p 8002:8002 \ | |
| -v $PWD/valhalla/custom_files:/custom_files \ | |
| -e tile_urls=http://download.geofabrik.de/north-america/us/michigan-latest.osm.pbf \ | |
| -e serve_tiles=True -e build_admins=True \ | |
| docker.pkg.github.com/gis-ops/docker-valhalla/valhalla:3.3.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| docker login docker.pkg.github.com | |
| docker pull docker.pkg.github.com/gis-ops/docker-valhalla/valhalla:3.3.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def insert_geometry(traj_id: int, | |
| geometry: str) -> None: | |
| db = TrajDb() | |
| sql = "insert into traj_match (traj_id, geometry) values (?, ?)" | |
| db.execute_sql(sql, [traj_id, geometry]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def main(): | |
| tiles = './valhalla/custom_files/valhalla_tiles.tar' | |
| config = get_config(tile_extract=tiles, verbose=True) | |
| max_traj_id = get_max_traj_id() | |
| max_match = get_max_match() | |
| for traj_id in range(max_match + 1, max_traj_id + 1): | |
| actor = Actor(config) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def load_trajectory_points(traj_id): | |
| db = EVedDb() | |
| sql = f""" | |
| select distinct | |
| s.latitude as lat | |
| , s.longitude as lon | |
| , min(s.time_stamp) / 1000 as time | |
| from signal s | |
| inner join trajectory t on s.vehicle_id = t.vehicle_id and s.trip_id = t.trip_id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def map_match(actor: Actor, | |
| df: pd.DataFrame) -> str: | |
| param = { | |
| "use_timestamps": True, | |
| "shortest": True, | |
| "shape_match": "walk_or_snap", | |
| "shape": df.to_dict(orient='records'), | |
| "costing": "auto", | |
| "format": "osrm", | |
| "directions_options": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_matching_links(self, exclude_self=True): | |
| df = load_matching_links(self.traj_id) | |
| if exclude_self: | |
| df = df[df["traj_id"] != self.traj_id] | |
| links = np.unique(df["link_id"].values) | |
| return links |