PDA

View Full Version : Check out if GPS pos is on a Route

kristijan
11-14-2005, 08:52 AM
Hello there!

First thank you for this great forum, i searched through it but couldn't find exactly what i am looking for.

I have a problem, i don't exactly know how to solve.
I have a route going from A to B.
I get an GPS coordinate.
How do i check if the GPS position is on the Route between A and B ?

Thank you for any suggestions !

Wilfried
11-15-2005, 01:33 PM
Hi,

The only way to know this is to draw a polygon around the route. The poligon has to be wider than the route because there could be traffic deviations.

kristijan
11-17-2005, 01:54 AM
this sounds very difficult. I think i don't quite understand, how do i draw the polygon ? Am i able to move along the route, which is calculatet and displayed in Mappoint. Do i draw the polygon then in mappoint ?

Might there be any hope that in mappoint 2006 this would be better ?

Wilfried
11-17-2005, 07:51 AM
Hi,

Sorry that I was so unclear. First let mappoint calculate the route for the vehicle. Then you can draw a polygon around the route. For each point in the polygon you draw you have to save the coordinates. This you can do in a beforeClick event handler.

To actual see if each GPS position of the car is within the polygon has nothing to do with mappoint anymore. Your program has to calculate it. It can be done following way:

Reduce the polygon to a triangle by replacing 2 successive sides by 1 new side, then calculate if the residual riangle contains the point. If not then calculate on the next triangle etc...

Not very easy done but not a big problem tough.

calv1ns
11-17-2005, 12:23 PM
Hey Wil

I'm not getting what you mean too... do you have a bit of code or pseudo code that gives us a better idea... It seems your solution is brilliant but I'm not sure the majority of us are understanding it.

Ciao,

Wilfried
11-17-2005, 12:48 PM
Hi,

I guess you right. If I read my explanation then I dont understeand eahter :shock:

This it is difficult because I dont know all the naming of figures etc. I try to make some drawings to explain what I mean, because even with some pseudocode it will be difficult, and it is really not so difficult, I have done sutch things several times.

I'll keep in touch :)

Wilfried
11-17-2005, 01:06 PM
Hi,

Whell I made a little drawing to explain what I mean. See http://www.mestdagh.biz/mp/polygon.gif

The top drawing is the polygon where the vehicle is maybe in or maybe not. How to check this simple. See second drawing.

we connect 2 sides (starting at random place), eg the red one, and by connecting we only have a triangle. Since we have not a matematical figure it is mutch more simple to calculate if vehicle is in it or not. If it is not in then we connect next point, the green one, if not in then the blue, etc...

if we are at the end then we have red alert: vehicle is not where it should be.

Is this more clear ?

Maybe this is stuff for a little article, but then better explaned and with some code samples :)

calv1ns
12-01-2005, 05:46 PM
HI Wil

Sorry I missed your response on this item. Must of slipped through somehow.

It appears the link to the gif file is no longer available?

So Yes likey more clear - but No I didn't get a chance to look at it...

Thanks,
Ciao,

Wilfried
12-02-2005, 04:08 AM
Hi,

The link is still valid, it works here. It redirect to this: http://users.pandora.be/sonal.nv/mp/polygon.gif

Winwaed
12-02-2005, 07:53 AM
Another approach to point-in-polygon calculations is outlined in Sedgwick's "Algorithms" (I see this is now a multi-volume work: I only have the 1 volume edition).

Basically, you project a 'ray' from your point to inifinity. Count the number of times it crosses the polygon edge. If this is odd, then the point must be in the polygon. If it is even, then the point must be outside the polygon.
I've implemented it for cartesian coordinates, and the maths becomes pretty simple if your ray is parallel to one of the axes.

Richard

Wilfried
12-03-2005, 03:54 AM
Hi Richard,

Looks also a nice aproach :)

Gianmaria
04-19-2006, 10:46 AM
Hi,