pub fn project_onto_path(
gnss_positions: &[GnssPosition],
path: &TrainPath,
netelements: &[Netelement],
_config: &PathConfig,
) -> Result<Vec<ProjectedPosition>, ProjectionError>Expand description
Project GNSS coordinates onto a calculated train path (US2: T093-T097)
Projects each GNSS position onto the nearest segment in the provided path, calculating intrinsic coordinates (0-1 range) for each position.
§Arguments
gnss_positions- Vector of GNSS positions to projectpath- Pre-calculated train path (from calculate_train_path or loaded from file)netelements- Railway network elements (needed for geometry)config- Path configuration (not currently used, reserved for future)
§Returns
Vector of ProjectedPosition structs, one per GNSS coordinate
§Errors
Returns ProjectionError if:
- GNSS positions or path is empty
- Netelement IDs in path don’t exist in netelements collection
- Projection onto linestring fails
- Intrinsic coordinates fall outside valid range [0, 1]
§Example
use tp_lib_core::{project_onto_path, PathConfig};
use tp_lib_core::models::{GnssPosition, TrainPath, Netelement};
// Load pre-calculated path
let path: TrainPath = todo!(); // From file or calculate_train_path
let netelements: Vec<Netelement> = todo!();
let gnss_positions: Vec<GnssPosition> = todo!();
let config = PathConfig::default();
let projected = project_onto_path(&gnss_positions, &path, &netelements, &config)?;
// Each projected position has netelement_id and intrinsic coordinate
for proj in projected {
if let Some(intrinsic) = proj.intrinsic {
println!("Projected to {} at intrinsic {:.3}", proj.netelement_id, intrinsic);
}
}