I have a GPX file with large set of points (longitude and latitude sorted by time), how can I calculate how many laps my set contains?
The GPS is recorded during circuit racing session.
The lap is number of times vehicle passes start/finish of circuit.
The solution is going to require some trial and error to see what works, as it depends a lot on the quality of data and how many data points you have.
If data points are taken at a high frequency, it might be good enough to do use line-line intersection tests. If the line formed by two adjacent data points intersects with the finish line on the racing track, then you can count this as a lap. This will, however, fail when the data points are too far apart. It could also fail if a car leaves the track at the finish line, unless you're careful with your solution.
A more general solution is to separate the track into two polygons: each representing half the track. Make their coverage include off-track. Then use point in polygon tests to determine which data points are in which half of the track. Then iterate through the points and take note of when the car moves from one half to the other. Every second transition should indicate a lap. This, however, will fail if the car spins out of control and oscillates between the two halves without going around the full lap.
You can work around this by enforcing a minimum number of data points between transitions. Another idea is to break the track into three polygons and make sure the car always moves "forward".