Simple driving trip simulator for OpenStreetMap graphs
Project description
tripsim
Driving trip simulator for building a series of coordinates that can be used for testing telematics systems.
:warning: This is quite a simplified implementation that should not be used for anything beyond simple load testing or distance calculations.
Getting Started
Currenlty, only python versions 3.9+ are supported.
pip install tripsim
Simulating a Trip
Here we will simulate driving and plotting the points taken from one random point to another in a city.
from tripsim import simulate_trip
# other imports for this example
import matplotlib.pyplot as plt
from shapely.geometry import LineString
import osmnx as ox
def main():
# Get the graph of the city of Cork
graph = ox.graph_from_place('Cork City, Ireland', network_type='drive')
# the simulated trip will return a list of points
# each point has a latitude and longitude, along with a timestamp (in seconds)
trip = simulate_trip(graph)
# adjust your styling accordingly
_, ax = ox.plot_graph(
graph, dpi=180,
node_color='green',
node_size=1,
node_alpha=0.1,
node_edgecolor='white',
node_zorder=5,
edge_color='white',
edge_linewidth=2,
edge_alpha=0.1,
show=False,
close=False
)
# the points are a dataclass with a few convenience methods
coords = [
(point.get_lat(), point.get_lon())
for point in trip
]
# here we are setting the list of coords as a LineString
# for easy plotting
coords_graph_line = LineString(coords)
x, y = coords_graph_line.xy
ax.plot(x, y, '-o', color='red',
markersize=3, alpha=0.7, zorder=1)
plt.show()
if __name__ == '__main__':
main()
The created trip should look something like this when plotted.
Handling Points
A trip is just a list of Point
instances, which represent a point on the earth's surface. The Point
dataclass gives you a few convenience methods.
from tripsim import Point
import time
# create a point
point = Point(
lat=-33.8670522,
lon=151.1957362
)
# x = longitude
# y = latitude
assert point.lat == -33.8670522
assert point.lat == point.y
assert point.lon == 151.1957362
assert point.lon == point.x
assert point.xy == (151.1957362, -33.8670522)
# you can add timestamps to Points to replicate
# collecting GPS data on an interval
point.set_timestamp(time.time())
# you can create new Points relative to this one
# new point 1km north
point_2 = point.next_point(
distance=1,
bearing=0
)
# inequality works on points lat/lon
assert point != point_2
assert point.distance_to(point_2) == 1.0
assert point.bearing_to(point_2) == 0.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tripsim-0.1.5.tar.gz
.
File metadata
- Download URL: tripsim-0.1.5.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04df499c4bd41ec22bb4589744e44235957e4acce01f780359347fb8d865e46a |
|
MD5 | d2e9028b1cb781149035d5fccdf2268d |
|
BLAKE2b-256 | 5d79c4357947562bb83bdbc48b96256234bfad4003b6bd189f8fe1be180817c7 |
File details
Details for the file tripsim-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: tripsim-0.1.5-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88de647dd7eb3a6833c339578cace358806e81f14960a51e88b2cc0205866888 |
|
MD5 | 19b0e47ff5df4a2625fda65ad847ac09 |
|
BLAKE2b-256 | d3cf4c685ecad5216121dee6660695ef2f4074affee95bea47d1dbf3ced0b134 |