Extract graph
[1]:
# Import libraries
import numpy as np
import pandas as pd
from pytrack.graph import graph, distance
from pytrack.analytics import visualization
[2]:
df = pd.read_excel("dataset.xlsx")
df
[2]:
| datetime | latitude | longitude | |
|---|---|---|---|
| 0 | 23-04-21 16:46:19:583000 | 43.759650 | 11.291561 |
| 1 | 23-04-21 16:46:36:570000 | 43.759645 | 11.291544 |
| 2 | 23-04-21 16:46:52:647000 | 43.759671 | 11.291162 |
| 3 | 23-04-21 16:47:37:568000 | 43.759677 | 11.291148 |
| 4 | 23-04-21 16:47:49:639000 | 43.759691 | 11.290932 |
| ... | ... | ... | ... |
| 94 | 23-04-21 17:12:37:573000 | 43.779596 | 11.254733 |
| 95 | 23-04-21 17:12:51:592000 | 43.779583 | 11.254295 |
| 96 | 23-04-21 17:13:05:572000 | 43.779206 | 11.253978 |
| 97 | 23-04-21 17:13:20:592000 | 43.779205 | 11.253974 |
| 98 | 23-04-21 17:13:36:590000 | 43.778464 | 11.253364 |
99 rows × 3 columns
[3]:
latitude = df["latitude"].to_list()
longitude = df["longitude"].to_list()
points = [(lat, lon) for lat, lon in zip(latitude, longitude)]
[4]:
# Create BBOX
north, east = np.max(np.array([*points]), 0)
south, west = np.min(np.array([*points]), 0)
# Extract road network graph
G = graph.graph_from_bbox(*distance.enlarge_bbox(north, south, west, east, 500), simplify=True, network_type='drive')
Downloaded 1,773.29kB
[5]:
# Show extracted graph
maps = visualization.Map(location=(np.mean(latitude), np.mean(longitude)))
maps.add_graph(G, plot_nodes=True)
maps
[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook