Skip to content

01 Reference line and Frenet projection (Step 1)

Entry function:

from trajlab.processing.reference_line import project_to_reference_line

tracks = project_to_reference_line(raw, ref_line, direction_consistency_min=0.9)

Purpose

Trajectories recorded by drones or roadside cameras are UTM positions. Car-following and lane-change analysis need road-relative Frenet coordinates: the longitudinal distance s along the road (pos_lon, increasing in the direction of travel) and the signed lateral offset d from a reference line (pos_lat, positive to the left). Step 1 computes them; the reference line is either derived from the data (estimate_ref_lines) or supplied by the user (e.g. from OpenStreetMap).

Interface

Pipeline step Requires columns Produces columns Further output columns
projection geometry pos_lon, pos_lat pos_lon_ref, ref_line_reversed

Input: one travel direction of a GeoDataFrame with point geometry in a metric CRS, id, datum (timestamps), optionally class, length, orientation. The reference line is a LineString in the same CRS. pos_lon_ref keeps the stationing in the digitising direction of the line; ref_line_reversed records whether the line ran against the traffic.

Parameter Default Description
projection.enabled True Run the step.
projection.direction_consistency_min 0.9 Minimum share (0-1) of moving vehicles that must travel in the same direction along the reference line (Step 1), and in the direction of increasing pos_lon (checked again in Steps 3-6).

Method

Reference line from the data (estimate_ref_lines)

Per travel direction (orientation > 0 / < 0):

  1. Road axis: the first principal component of the centerd UTM points, oriented so that the median net displacement of the vehicles along it is positive. Points are expressed as s (along the axis) and n (across). Any road orientation works.
  2. Ensemble: the top_n_vehicles (30) trajectories with the largest extent along the axis. In bins of s_step = 5 m the mean s and the median n of their points are taken, which cancels individual lane changes and steering.
  3. Smoothing spline: a cubic B-spline through the bin values, smoothing condition s_spline = n_bins · rms_tolerance_m², i.e. the line deviates from the bin medians by at most rms_tolerance_m RMS. Default 0.75 m: below that the spline follows the scatter of the bin medians and kinks (3–16° between 1 m segments on 5 of 44 directions of Sites 1 and 2), and every projected trajectory jumps laterally at a kink; above it the line cuts curves. The remaining slow deviation from the road edge is removed by the alignment (03). The former smoothing_factor (default 100, ≈ 10 m RMS) is deprecated.

Limitation: roads that curve by more than about 60–70° within the recording area are not monotonic along one axis (a UserWarning is emitted); a user-supplied line is needed there. For long curved sections (e.g. the 7.7 km A39 test data) the line can be built from the time-ordered positions of one fully observed vehicle.

Projection

For a point P and the reference line R of length L:

$$s = \mathrm{line_locate_point}(R, P), \qquad d = \operatorname{sign}\big((\vec T_R \times \vec V_P)_z\big)\,\lVert P - R(s) \rVert,$$

with $\vec T_R$ the tangent of R at s and $\vec V_P$ the vector from the foot point to P.

Direction normalization

The net displacement of every moving vehicle (≥ 1 m) along s decides its travel direction. If fewer than projection.direction_consistency_min (0.9) of them agree, a ValueError asks for the input to be split by direction. If the vehicles travel against the line, $s \leftarrow L - s$ and $d \leftarrow -d$ (equivalent to reversing the line). Steps 3–6 check that pos_lon increases with travel, also for input that skipped Step 1.

End clamping

Points that project within 1.0 m of either end of the line are dropped (projections beyond the line ends pile up at its end points).

Design choices

The choices below are made for this library unless a paper is named; the evidence for each is given under "Source" (a test, a script of applications/ant2027/ or a measurement named in the text).

  • The ensemble is binned along the principal axis of the positions. Bins along a fixed map axis (utm_x) mix road sections on diagonal roads. Compared with utm_x bins, pos_lon shifts by up to 1.8 m; lanes and neighbors are unchanged on > 99.7 % of the rows. Source: tests/processing/reference_line/test_ref_lines.py (any road orientation).
  • The spline smoothing is an RMS tolerance in meters (0.75 m), not a dimensionless factor. 0.75 m is the smallest tolerance without kinks (maximum turn ≤ 1° between 1 m segments in every direction); at 0.7 m one of 44 directions still turns by 1.07°. A tolerance that keeps the road-edge wander within ±0.5 m does not exist (the wander stays 1–4 m at every tolerance, see below), so the wander is left to the alignment (03). Source: tolerance scan on 22 recordings, applications/ant2027/text_numbers/refline_edges.py.

Validation and limitations

  • tests/processing/reference_line/test_ref_lines.py, tests/processing/test_direction.py, tests/processing/test_processing.py, tests/processing/test_conventions.py (reference lines, direction normalization, end clamping, signs); applications/ant2027/text_numbers/refline_edges.py (tolerance scan on 22 recordings).
  • Edge wander of the line (5 %/95 % road-edge quantiles along s) stays 1–4 m on Sites 1 and 2 at every tolerance; it is removed by the alignment, not by the line.