Hi there! I want to draw a lot of cars moving around on a map. I have the osm data parsed and put into a graph using GraphServer. What I'd like is a function to do is this (in C style pseudocode):
So basically, I've travelled so many meters along this street, now where am I in lat/long? Obviously this is isn't hard when the map is a grid, but it does seem VERY tricky to me for more complicated road maps. Any ideas of where to begin or other projects that I can leverage? EDIT: A bit more explanation...GraphServer (as mentioned in the comments), just gives me nodes and edges. But the nodes map directly back to the osm nodes and the edges map directly to "ways". So maybe my question is better phrased as...I'm travelling along a way at velocity v, in s seconds, where am I? |

Go through each segment of the street, calculating distance of the line between each pair of nodes (see useful formulas). Consider storing this data for the duration of your program. Go through each segment of the street, subtracting the length of each segment of street from your total, until the remaining distance is less than the length of a street segment, which means you've found the segment of street you're currently in. Calculate your position within that segment of street using the remaining distance, by linearly interpolating between its start and end nodes.
answered
OJW |

I think this boils down to a (relatively!) straightforward navigational problem. You're at point A with Lat and Long known. and you travel on a course of, say 315T (degrees true) for 10 seconds at a speed of 40KPH, then 320T for 5 seconds at 35KPH etc. etc. (roads are not always straight). So it's either a) a matter of calculating each intermediate position from the previous known position and the vector from there to this position, or b) continuing to "plot" each different course change from the original known position until you want another Lat/Long when you'll do your spherical trigonometry calculation to determine the new position. If you are using the vehicles' odometers as one of your inputs you'll have take into account the gradient of the road, i.e. the gain/loss in height between each intermediate point as, for example, you will not end up in the same Lat/Long if you head due east (090T) for 10 KM on the level as you would be doing the same up or down a gradient of, say 1 in 5. When doing your calcs you'll need to consider what level of accuracy you want. And also "mapping" to and from the projection of the OSM map data to whatever is needed for the trig. calcs. The earth is not a true sphere (oblate spheroid) but I doubt this will really affect your calculations at the granularity you indicate you'll be working at. I suggest taking a look at some navigational works, particularly marine navigation - although they don't have the gradient problem to worry about. Possibly also some stuff on GPS calculations may help.
answered
vagabond |

I don't know GraphServer, but from a quick googling, it seems GraphServer only deals in nodes and edges, not in real geographical data - so the graph simply does not contain the information you need. Maybe you could explain how you use GraphServer, what information you put into it, and what it does for you?

I edited the question :)