Use case
Cleaning fleet GPS data with map matching
Raw fleet GPS overstates mileage, wanders between parallel streets and jumps when a receiver loses the sky. Cleaning it means cutting each vehicle’s fixes into trips, matching every trip to the roads it was driven on, and measuring along those roads rather than between raw points. With oslew the matching is one request per trip, and each matched fix comes back with its road class and the posted limit where the data has one, so mileage and time over the limit follow from the answer and your own timestamps.
Last reviewed
A fleet’s trackers report a position every few seconds. Somewhere in that stream are the numbers operations actually wants — how far each vehicle drove on each trip, and how long it spent above the limit — and between them and the raw file stand noise, gaps and roads with no posted limit. This page is the pipeline from one to the other, and the decisions that keep the numbers defensible when a driver disputes them.
The pipeline
- Cut trips. Group fixes by vehicle, sort by time, and start a new trip after a quiet period.
- Match each trip with the map matching API, in requests of at most 10,000 points.
- Measure mileage from the matched distance, and measure the breaks the matcher skipped separately.
- Measure speeding from matched positions and your own timestamps, against the posted limit where one exists.
- Snap single fixes, which have no path to match, to record the road they were beside.
- Write one row per trip: fixes, matched and unmatched, road kilometres, gap kilometres, minutes with a known limit, minutes over it, and a confidence.
The GPS cleanup example is the whole program in Python and TypeScript, reading a CSV of vehicle, time, latitude and longitude.
Cutting trips
A trip is a run of fixes with no long silence in it. The threshold is yours: ten minutes separates a delivery stop from the end of a shift for most vans, while a taxi fleet idling on a rank may want longer. Cutting before matching matters for two reasons. The matcher is told nothing about time, so a vehicle parked overnight and moved in the morning would otherwise be joined by an imaginary drive. And per-trip rows are what a report needs.
Matching long trips
A long trip may have more fixes than one request takes. Send it in pieces of at most 10,000 points, with each piece after the first starting on the last fix of the piece before, and drop that repeated fix from the second answer so the step between pieces is routed once and counted once. Near each join a piece sees context on one side only, so the result can differ by a few metres from one long request — immaterial for mileage, worth knowing when comparing runs. Each piece is one request against the routing rate however many fixes it carries.
Set sigma_m to the real noise of your receivers rather than a hopeful figure: a phone in a van is noisier than a hard-wired tracker. A trip whose matched fixes mostly sit further from their roads than that noise predicts gets a low confidence, which usually means sigma_m is too tight rather than that the match is wrong.
Mileage that holds up
The matched distance_m is the length of road driven within each matched segment. The matcher does not route across a break — a fix with no road nearby, or two fixes too far apart to be one continuous drive — so those stretches are not in it. Measure each break as a straight line between the matched fixes either side and report it in its own column. That way a single absurd jump is skipped rather than counted as kilometres, and a long stretch with no fixes, such as a tunnel, is counted at its straight length rather than lost.
Mind the sampling rate. On a motorway, a fix once a minute can put consecutive fixes far enough apart to break the chain every time, and the trip becomes a string of one-point segments. A fix every thirty seconds or less keeps fast trips whole.
Time over the limit
Nothing in the match answer is a speed the vehicle drove; durations come from the roads’ speeds, not your clock. Speeds are yours to compute, and the method decides whether the number is fair:
- Use consecutive matched positions, not raw ones, so GPS jitter does not register as speed.
- Divide the straight line between the two positions by the seconds between their timestamps. The straight line is never longer than the road between them, so the speed errs low — the right side to err on for a number that may reach a driver.
- Compare it with the limit in
speed_limits_kmhfor the fix where the step starts, allowing a small tolerance for jitter the match leaves. - Skip steps longer than a minute or so; an average over a long gap says nothing about speeding.
- Skip steps whose limit is null, and count their minutes separately.
Roads with no posted limit
Which roads carry a posted limit depends on the data loaded for the area, and residential and service roads often carry none. A report that says “four minutes over the limit” without saying how many minutes had a known limit invites the wrong conclusion. Report both: minutes with a known limit and minutes over it. Do not fill the gaps with the road class’s default speed. That figure is an assumption the routing API uses to time routes, not a limit anyone posted, and presenting it as one to a driver would be wrong.
Trips that consist of a single fix — a tracker that woke, reported once and slept — have no path. Snap the fix instead and record the road class it was beside; the snap looks further afield for a road than the matcher does.
Traces are personal data
A vehicle’s trace says where its driver went, and a fleet dataset is a record of people’s working days. The service is built to hold as little of it as possible: the trace travels as the body of a match request, and bodies are never written to the query log. What the log does record is narrow. Each event keeps the minute and second, the route, the tenant (a customer, never a person), the product, the status, the latency, a relative weight and the outcome. Keep the key on your server and send traces from there, never from the device. The security page sets out the rest, including what a dedicated deployment changes.
Matched output is derived from ODbL road data. Keeping it in your own systems is unrestricted; sharing a database of matched trips outside your organisation brings share-alike and attribution with it, as the licensing page explains.
Pacing and plan
A day of short trips is many small requests, and that is the case where the rate matters. The Routing plan allows 5 requests a second sustained, burst 25 for matching; the Platform plan raises that to 20 requests a second sustained, burst 100. A nightly batch over the previous day’s fixes fits comfortably in either if it paces itself and retries on HTTP 429 after the Retry-After interval. The pricing page lists every plan.
Bottom line
Cut trips before matching, match in overlapping pieces, count road kilometres and gap kilometres separately, compute speeds from matched positions and your own clock, and never report time over the limit without the time for which a limit was known. The numbers that come out are ones you can defend line by line.
Where this workflow falls short
- Posted limits are patchy: how many roads carry one depends on the data for the area, and minor roads often have none. A speeding figure covers only the minutes spent on roads that have one; report those minutes beside it, never the figure on its own.
- The matcher breaks a trace where consecutive fixes are far apart or a fix has no road nearby, and road distance leaves the breaks out; sparse sampling on fast roads turns one trip into many short segments.
- Matched positions and distances derive from ODbL road data; a database of them that you share outside your organisation carries share-alike and attribution.
- Matching needs road data loaded where the vehicle drove; outside it every fix comes back unmatched and the trip has no road mileage.
Questions
How should raw GPS fixes be split into trips?
Group the fixes by vehicle, sort each group by time, and start a new trip wherever the tracker went quiet for longer than a threshold you choose — ten minutes suits most vans. A trip of a single fix has no path to match; snap it to the nearest road instead, to record where the vehicle stood.
Why is matched mileage lower than the sum of raw GPS distances?
Because raw distances add up noise. A parked vehicle’s position drifts a few metres at every fix and each wobble on a straight road adds a little, so the straight lines between raw points overstate the distance. The matched distance is the length of the road the trip was actually on.
How is time over the speed limit measured?
Take consecutive matched positions, divide the straight line between them by the seconds between your timestamps, and compare the result with the posted limit on the road where the step starts. Skip long steps and steps with no posted limit, and allow a small tolerance for the jitter that matching leaves behind.
Should the road’s class speed stand in where no limit is posted?
No. The class speed is an assumption the router uses to estimate travel times, not a legal limit, and it is not returned as one. Where the limit is null, the step is unknown: leave it out of the speeding figure and count those minutes separately so the report shows how much of the trip was measurable.
Does oslew keep our vehicles’ traces?
No. A trace sent for matching is the body of the request, and request bodies are never written to the query log, so none of its positions is kept. The log notes only that a match request happened, when, with its status and latency, and the tenant it came from.