geo/laneGeometry
Lane boundary computation, width sampling, and heading calculations using @turf/turf.
computeBoundaries
function computeBoundaries(
centerLine: Feature<LineString>,
widthMeters: number
): {
left: Feature<LineString>
right: Feature<LineString>
}Computes left and right boundary lines by offsetting the centerline by ±widthMeters/2.
Uses turf.lineOffset(centerLine, distance, { units: 'meters' }).
Parameters
| Name | Type | Description |
|---|---|---|
centerLine | Feature<LineString> | Lane centerline in WGS84 |
widthMeters | number | Full lane width in meters |
Example
const { left, right } = computeBoundaries(lane.centerLine, lane.width)
// left and right are LineString features parallel to centerLinecomputeLaneSamples
function computeLaneSamples(
centerLine: Feature<LineString>,
halfWidthMeters: number
): LaneSampleAssociation[]Returns a LaneSampleAssociation[] sampled every 1 m along the centerline. Each sample stores { s, width } where s is the arc-length position and width is halfWidthMeters (constant for uniform-width lanes).
Used to populate ApolloLane.left_sample and right_sample.
sampleLineEveryMeter
function sampleLineEveryMeter(line: Feature<LineString>): Array<[number, number]>Returns an array of [lng, lat] coordinates sampled every 1 m along the line using turf.along. Includes the start and end points.
computeStartHeading
function computeStartHeading(centerLine: Feature<LineString>): numberReturns the bearing (degrees, 0 = north, clockwise) from the first to the second coordinate of the centerline. Used to set CurveSegment.heading in the exported proto.
buildLanePolygon
function buildLanePolygon(left: Feature<LineString>, right: Feature<LineString>): Feature<Polygon>Constructs a filled polygon from left and right boundary lines. The polygon is formed by:
- Left boundary coordinates (start → end)
- Right boundary coordinates (end → start, reversed)
- Closing back to the left boundary start
Used by MapEditor to render the lane fill layer.
laneMidpointInfo
function laneMidpointInfo(line: Feature<LineString>): { point: Feature<Point>; bearing: number }Returns the midpoint of the line and the bearing at that point. Used by MapEditor to position and orient direction-arrow symbols.
pointToS
function pointToS(line: Feature<LineString>, point: Feature<Point>): numberReturns the arc-length s (meters from start) of the nearest point on line to point. Wraps turf.nearestPointOnLine(line, point).properties.location * turf.length(line).
lineEndpoints
function lineEndpoints(line: Feature<LineString>): {
start: [number, number]
end: [number, number]
}Returns the first and last coordinates of a LineString feature.