< Summary

Class:Itinero.IO.Json.GeoJson.SnapPointExtensions
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/IO/Json/GeoJson/SnapPointExtensions.cs
Covered lines:0
Uncovered lines:18
Coverable lines:18
Total lines:52
Line coverage:0% (0 of 18)
Covered branches:0
Total branches:0
Tag:224_14471318300

Metrics

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

File(s)

/home/runner/work/routing2/routing2/src/Itinero/IO/Json/GeoJson/SnapPointExtensions.cs

#LineLine coverage
 1using System.IO;
 2using System.Linq;
 3using System.Text;
 4using System.Text.Json;
 5using Itinero.Network;
 6using Itinero.Snapping;
 7
 8namespace Itinero.IO.Json.GeoJson;
 9
 10/// <summary>
 11/// Contains route extensions
 12/// </summary>
 13public static class SnapPointExtensions
 14{
 15    /// <summary>
 16    /// Returns geojson for the given snap point.
 17    /// </summary>
 18    /// <param name="snapPoint">The snap point.</param>
 19    /// <param name="routerDb">The router db.</param>
 20    /// <returns>A geojson string.</returns>
 21    public static string ToGeoJson(this SnapPoint snapPoint, RoutingNetwork routerDb)
 022    {
 023        using var stream = new MemoryStream();
 24
 025        using (var jsonWriter = new Utf8JsonWriter(stream))
 026        {
 027            jsonWriter.WriteFeatureCollectionStart();
 028            WriteFeatures(jsonWriter, snapPoint, routerDb);
 029            jsonWriter.WriteFeatureCollectionEnd();
 030        }
 31
 032        return Encoding.UTF8.GetString(stream.ToArray());
 033    }
 34
 35    /// <summary>
 36    /// Writes a geojson feature collection to the given json writer.
 37    /// </summary>
 38    /// <param name="snapPoint">The snap point.</param>
 39    /// <param name="routerDb">The router db.</param>
 40    /// <param name="jsonWriter">The json writer.</param>
 41    public static void WriteFeatures(this Utf8JsonWriter jsonWriter, SnapPoint snapPoint, RoutingNetwork routerDb)
 042    {
 043        jsonWriter.WriteFeatureStart();
 044        jsonWriter.WriteProperties(Enumerable.Empty<(string key, string value)>());
 45
 046        jsonWriter.WritePropertyName("geometry");
 047        var locationOnNetwork = snapPoint.LocationOnNetwork(routerDb);
 048        jsonWriter.WritePoint(locationOnNetwork);
 49
 050        jsonWriter.WriteFeatureEnd();
 051    }
 52}

Methods/Properties

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