OpenDataVisualizer/Schaad.OpenData.Traffic/Geometry/DirectionTarget.cs
Claudio Schaad 8de869b023 Fix roundabout arm geometry for untargetable directions
Stations like "WEINFELDEN Kreisel West - Umfahrung" have directions
such as "zur Umfahrung" or "von Egelseestrasse" that cannot be
geocoded, so their dots were drawn on a nearby side road or around
the roundabout ring.

- Derive the roundabout centre from all stations sharing the name
  before " - " and point each arm outward from it
- Prefer road segments named like the station's address when
  following an arm; reject arms that don't get away from the centre
- Parse "zur", "zum", "Richtung" and "vom" direction prefixes
- Treat only swissTLM3D object kinds 12-19 as non-roads; kind 20 is
  a regular road (e.g. Dunantstrasse in Weinfelden)
- Bump the geometry cache to v7 so all stations are rebuilt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 20:50:48 +01:00

29 lines
959 B
C#

namespace Schaad.OpenData.Traffic.Geometry;
public sealed record DirectionTarget(string Place, bool IsDestination)
{
private static readonly string[] DestinationPrefixes = ["nach ", "zur ", "zum ", "richtung "];
private static readonly string[] OriginPrefixes = ["von ", "vom "];
public static DirectionTarget Parse(string direction)
{
var text = direction.Trim();
foreach (var prefix in OriginPrefixes)
{
if (text.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
{
return new DirectionTarget(text[prefix.Length..].Trim(), false);
}
}
foreach (var prefix in DestinationPrefixes)
{
if (text.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
{
return new DirectionTarget(text[prefix.Length..].Trim(), true);
}
}
return new DirectionTarget(text, true);
}
}