I want to calculate the driving direction of a vehicle (e.g. a car) that had an accident on the road.
The data (from police reports) I have is either an address (street, number, zipcode, city) or a geolocation (longitude, latitude). Thereby I have the 'driving direction' as a variable which contains either the value positive or negative. Positive is that the streetnumbers going upwards if the vehicle continued driving. Negative is that the streetnumbers going down.
How can I determine the driving direction (N°, E°) from this data?
I found already a method to change street addresses to geolocation, so that should be no problem and how to get the driving direction (N°,E°) from two locations.
I think I might need a second geolocation (e.g. location of next or previous address), but then there is the problem that roads turn so I need another solution like finding a point right in front of the given geolocation on that same road or a tool that can give me the direction of the road at that specific location.
The purpose is to get to know the influence of sun glare on traffic accidents, so this might save some lives if I can research this topic.
Driving direction can be calculated by calculating the bearing between a point earlier on the same road (e.g. 50m before the accidents) and the accident itself. Formula is (in Python):
def calculateBearing(lat1,lon1,lat2,lon2):
bearing = toDeg(math.atan2(math.sin(toRad(lon2-lon1))*math.cos(toRad(lat2)), \
math.cos(toRad(lat1))*math.sin(toRad(lat2))-
math.sin(toRad(lat1))*math.cos(toRad(lat2)) \
*math.cos(toRad(lon2-lon1))))
#North = 0°, East=90°, South = (-)180°, West=-90°
if float(bearing) < 0:
bearing = 360-abs(bearing)
#e.g. if bearing was -90, it is now 270
#e.g. if bearing was -179, it is now 181
return bearing
and has values from 0° (North) to 359° in clock-wise direction.