< Summary

Class:Itinero.MapMatching.IO.GeoJson.TrackExtensions
Assembly:Itinero.MapMatching
File(s):/home/runner/work/routing2/routing2/src/Itinero.MapMatching/IO/GeoJson/TrackExtensions.cs
Covered lines:0
Uncovered lines:40
Coverable lines:40
Total lines:58
Line coverage:0% (0 of 40)
Covered branches:0
Total branches:4
Branch coverage:0% (0 of 4)
Tag:251_23667616543

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
ToGeoJson(...)100%10%
WriteFeatures(...)0%40%

File(s)

/home/runner/work/routing2/routing2/src/Itinero.MapMatching/IO/GeoJson/TrackExtensions.cs

#LineLine coverage
 1using System.Globalization;
 2using System.IO;
 3using System.Text;
 4using System.Text.Json;
 5using Itinero.Geo;
 6
 7namespace Itinero.MapMatching.IO.GeoJson;
 8
 9public static class TrackExtensions
 10{
 11    public static string ToGeoJson(this Track track)
 012    {
 013        using var stream = new MemoryStream();
 014        using (var jsonWriter = new Utf8JsonWriter(stream))
 015        {
 016            jsonWriter.WriteFeatureCollectionStart();
 017            jsonWriter.WriteFeatures(track);
 018            jsonWriter.WriteFeatureCollectionEnd();
 019        }
 20
 021        return Encoding.UTF8.GetString(stream.ToArray());
 022    }
 23
 24    public static void WriteFeatures(this Utf8JsonWriter jsonWriter, Track track)
 025    {
 026        for (var n = 0; n < track.Count; n++)
 027        {
 028            var trackPoint = track[n];
 29
 030            var nodeLocation = (trackPoint.Location.longitude, trackPoint.Location.latitude, (float?)null);
 031            jsonWriter.WriteFeatureStart();
 032            jsonWriter.WriteGeometryStart();
 033            jsonWriter.WritePoint((nodeLocation));
 034            jsonWriter.WriteProperties(new (string key, string value)[]
 035            {
 036                ("type", "track-point"), ("track-point-id", n.ToString())
 037            });
 038            jsonWriter.WriteFeatureEnd();
 39
 040            if (n == 0) continue;
 41
 042            var previousTrackPoint = track[n - 1];
 043            var previousLocation = (previousTrackPoint.Location.longitude, previousTrackPoint.Location.latitude,
 044                (float?)null);
 045            var length =
 046                nodeLocation.DistanceEstimateInMeter(
 047                    previousLocation);
 048            jsonWriter.WriteFeatureStart();
 049            jsonWriter.WriteGeometryStart();
 050            jsonWriter.WriteLineString(new (double longitude, double latitude, float? e)[] { previousLocation, nodeLocat
 051            jsonWriter.WriteProperties(new (string key, string value)[]
 052            {
 053                ("type", "track"), ("length", length.ToString(CultureInfo.InvariantCulture))
 054            });
 055            jsonWriter.WriteFeatureEnd();
 056        }
 057    }
 58}

Methods/Properties

ToGeoJson(...)
WriteFeatures(...)