NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

2
1

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):

Coordinates getCurrentPoint(street,distance_traveled_along_street){
     return current_position_in_lat_long;
}

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?

asked 19 Apr '12, 01:50

Rex's gravatar image

Rex
31114
accept rate: 0%

edited 19 Apr '12, 16:58

stephan75's gravatar image

stephan75
12.6k556210

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?

(19 Apr '12, 15:35) sleske

I edited the question :)

(19 Apr '12, 16:46) Rex

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.

permanent link

answered 19 Apr '12, 17:49

vagabond's gravatar image

vagabond
1954510
accept rate: 0%

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.

permanent link

answered 20 Apr '12, 18:15

OJW's gravatar image

OJW
1518815
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×710
×22
×1

question asked: 19 Apr '12, 01:50

question was seen: 4,677 times

last updated: 20 Apr '12, 18:15

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum