a2wd | code & design

Single post

Visual Basic Coding

Converting journey times to nodes in a traffic model

I had a large data set of points from a GPS device (Garmin Nuvi) which needed matching up to nodes in a traffic model. Unfortunately the points on the GPS neither occur at exact node coordinates nor do they always even fall along the actual path of the road (GPS can be accurate to only ~8m)

To sort this out, I used Pythagoras’ theorem on equirectangular projections (I had initially hoped to use the more accurate spherical law of cosines, but excel introduced a rounding error, even when specifying variables as doubles

The code I came up with was as such:

x = (lon2-lon1) * Math.cos((lat1+lat2)/2);

y = (lat2-lat1);

d = Math.sqrt(x*x + y*y) * R;

With lat/lon 1 being the GPS point and lat/lon 2 being the node in our model, I could pinpoint the distance to the nearest node from this and then find the closest GPS point to each node, marking that up as the relevant datapoint and using the marked datapoints to calculate journey times along the route

02 Jul 2013distance / haversine / visual basic

  • Recent Posts

  • Archives