-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeoPoint.cs
36 lines (29 loc) · 1.35 KB
/
GeoPoint.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// See https://aka.ms/new-console-template for more information
using System.Text.Json;
using System.Text.Json.Nodes;
internal class GeoPoint
{
public string id { get; set; }
public string name { get; set; }
public int capacity { get; set; }
public string lat { get; set; }
public string lon { get; set; }
internal static GeoPoint ParseLine(string line)
{
var dynamicPoint = JsonSerializer.Deserialize<JsonObject>(line.TrimStart('\u001e'));
var result = new GeoPoint
{
id = (string)dynamicPoint["features"][0]["properties"]["address"],
name = ((string)dynamicPoint["features"][0]["properties"]["name"]).Trim(),
capacity = int.Parse((string)dynamicPoint["features"][0]["properties"]["capacity"] ?? "0"),
lat = ParseCoords((string)dynamicPoint["features"][0]["properties"]["latitude"]).ToString(System.Globalization.CultureInfo.InvariantCulture),
lon = ParseCoords((string)dynamicPoint["features"][0]["properties"]["longitude"]).ToString(System.Globalization.CultureInfo.InvariantCulture),
};
return result;
}
public static double ParseCoords(string inp)
{
var result = Math.Round(double.Parse(inp, System.Globalization.CultureInfo.InvariantCulture), 5);
return result;
}
}