2023-04-06 01:29:30 +02:00
|
|
|
using System.Text.Json;
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
2023-04-09 17:06:45 +02:00
|
|
|
namespace OSMDatastructure;
|
2023-03-30 16:29:42 +02:00
|
|
|
|
2023-03-30 18:24:57 +02:00
|
|
|
[Serializable]
|
2023-03-30 16:29:42 +02:00
|
|
|
public class Tag
|
|
|
|
{
|
|
|
|
public TagType key { get; }
|
|
|
|
public dynamic value { get; }
|
|
|
|
|
2023-04-06 01:29:30 +02:00
|
|
|
[JsonConstructor]
|
2023-03-30 16:29:42 +02:00
|
|
|
public Tag(TagType key, dynamic value)
|
|
|
|
{
|
|
|
|
this.key = key;
|
2023-04-06 01:29:30 +02:00
|
|
|
if (value is JsonElement)
|
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case TagType.highway:
|
|
|
|
this.value = (WayType)value.GetByte();
|
|
|
|
break;
|
|
|
|
case TagType.maxspeed:
|
|
|
|
this.value = value.GetByte();
|
|
|
|
break;
|
|
|
|
case TagType.forward:
|
|
|
|
case TagType.oneway:
|
|
|
|
this.value = value.GetBoolean();
|
|
|
|
break;
|
|
|
|
case TagType.id:
|
|
|
|
this.value = value.GetUInt64();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.value = value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.value = value;
|
|
|
|
}
|
2023-03-30 16:29:42 +02:00
|
|
|
}
|
|
|
|
|
2023-04-01 01:31:58 +02:00
|
|
|
public static Tag? ConvertToTag(string key, string value)
|
2023-03-30 16:29:42 +02:00
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case "highway":
|
|
|
|
try
|
|
|
|
{
|
2023-04-01 14:21:58 +02:00
|
|
|
return new Tag(TagType.highway, (WayType)Enum.Parse(typeof(WayType), value, true));
|
2023-03-30 16:29:42 +02:00
|
|
|
}
|
|
|
|
catch (ArgumentException)
|
|
|
|
{
|
2023-04-01 14:21:58 +02:00
|
|
|
return new Tag(TagType.highway, WayType.unclassified);
|
2023-03-30 16:29:42 +02:00
|
|
|
}
|
|
|
|
case "maxspeed":
|
|
|
|
try
|
|
|
|
{
|
|
|
|
byte speed = Convert.ToByte(value);
|
|
|
|
if (speed == 255)
|
2023-04-01 14:21:58 +02:00
|
|
|
return new Tag(TagType.highway, false);
|
2023-03-30 16:29:42 +02:00
|
|
|
else
|
2023-04-01 14:21:58 +02:00
|
|
|
return new Tag(TagType.maxspeed, speed);
|
2023-03-30 16:29:42 +02:00
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
//Console.WriteLine(e);
|
|
|
|
//Console.WriteLine("Continuing...");
|
2023-04-01 14:21:58 +02:00
|
|
|
return new Tag(TagType.maxspeed, byte.MaxValue);
|
2023-03-30 16:29:42 +02:00
|
|
|
}
|
|
|
|
case "oneway":
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case "yes":
|
2023-04-01 14:21:58 +02:00
|
|
|
return new Tag(TagType.oneway, true);
|
2023-03-30 16:29:42 +02:00
|
|
|
case "-1":
|
2023-04-01 14:21:58 +02:00
|
|
|
return new Tag(TagType.forward, false);
|
2023-03-30 16:29:42 +02:00
|
|
|
case "no":
|
2023-04-01 14:21:58 +02:00
|
|
|
return new Tag(TagType.oneway, false);
|
2023-03-30 16:29:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2023-04-01 01:31:58 +02:00
|
|
|
|
|
|
|
return null;
|
2023-03-30 16:29:42 +02:00
|
|
|
}
|
2023-04-01 01:31:58 +02:00
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return $"TAG {key.ToString()} {value.ToString()}";
|
|
|
|
}
|
|
|
|
|
2023-03-30 16:29:42 +02:00
|
|
|
public enum TagType : byte
|
|
|
|
{
|
2023-04-01 01:31:58 +02:00
|
|
|
highway, oneway, footway, sidewalk, cycleway, busway, forward, maxspeed, name, surface, lanes, access, tracktype, id
|
2023-03-30 16:29:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static readonly Dictionary<WayType, byte> defaultSpeedCar = new() {
|
2023-04-09 17:37:52 +02:00
|
|
|
{ WayType.NONE, 0 },
|
2023-03-30 16:29:42 +02:00
|
|
|
{ WayType.motorway, 110 },
|
|
|
|
{ WayType.trunk, 100 },
|
|
|
|
{ WayType.primary, 80 },
|
|
|
|
{ WayType.secondary, 80 },
|
|
|
|
{ WayType.tertiary, 70 },
|
|
|
|
{ WayType.unclassified, 20 },
|
|
|
|
{ WayType.residential, 10 },
|
|
|
|
{ WayType.motorway_link, 50 },
|
|
|
|
{ WayType.trunk_link, 50 },
|
|
|
|
{ WayType.primary_link, 30 },
|
|
|
|
{ WayType.secondary_link, 25 },
|
|
|
|
{ WayType.tertiary_link, 25 },
|
2023-04-09 17:14:14 +02:00
|
|
|
{ WayType.living_street, 5 },
|
2023-04-01 18:28:21 +02:00
|
|
|
{ WayType.service, 1 },
|
2023-03-30 16:29:42 +02:00
|
|
|
{ WayType.pedestrian, 0 },
|
2023-04-01 18:28:21 +02:00
|
|
|
{ WayType.track, 15 },
|
2023-03-30 16:29:42 +02:00
|
|
|
{ WayType.bus_guideway, 0 },
|
|
|
|
{ WayType.escape, 0 },
|
|
|
|
{ WayType.raceway, 0 },
|
2023-04-01 18:28:21 +02:00
|
|
|
{ WayType.road, 20 },
|
2023-03-30 16:29:42 +02:00
|
|
|
{ WayType.busway, 0 },
|
|
|
|
{ WayType.footway, 0 },
|
|
|
|
{ WayType.bridleway, 0 },
|
|
|
|
{ WayType.steps, 0 },
|
|
|
|
{ WayType.corridor, 0 },
|
|
|
|
{ WayType.path, 0 },
|
|
|
|
{ WayType.cycleway, 0 },
|
|
|
|
{ WayType.construction, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
public static readonly Dictionary<WayType, byte> defaultSpeedPedestrian = new() {
|
2023-04-09 17:37:52 +02:00
|
|
|
{ WayType.NONE, 0 },
|
2023-03-30 16:29:42 +02:00
|
|
|
{ WayType.motorway, 0 },
|
|
|
|
{ WayType.trunk, 0 },
|
|
|
|
{ WayType.primary, 0 },
|
|
|
|
{ WayType.secondary, 0 },
|
2023-04-01 18:28:21 +02:00
|
|
|
{ WayType.tertiary, 2 },
|
2023-03-30 16:29:42 +02:00
|
|
|
{ WayType.unclassified, 1 },
|
2023-04-01 18:28:21 +02:00
|
|
|
{ WayType.residential, 4 },
|
2023-03-30 16:29:42 +02:00
|
|
|
{ WayType.motorway_link, 0 },
|
|
|
|
{ WayType.trunk_link, 0 },
|
|
|
|
{ WayType.primary_link, 0 },
|
|
|
|
{ WayType.secondary_link, 0 },
|
|
|
|
{ WayType.tertiary_link, 0 },
|
|
|
|
{ WayType.living_street, 5 },
|
|
|
|
{ WayType.service, 2 },
|
|
|
|
{ WayType.pedestrian, 5 },
|
2023-04-01 18:28:21 +02:00
|
|
|
{ WayType.track, 1 },
|
2023-03-30 16:29:42 +02:00
|
|
|
{ WayType.bus_guideway, 0 },
|
2023-04-01 18:28:21 +02:00
|
|
|
{ WayType.escape, 1 },
|
2023-03-30 16:29:42 +02:00
|
|
|
{ WayType.raceway, 0 },
|
2023-04-09 17:14:14 +02:00
|
|
|
{ WayType.road, 2 },
|
2023-03-30 16:29:42 +02:00
|
|
|
{ WayType.busway, 0 },
|
|
|
|
{ WayType.footway, 4 },
|
|
|
|
{ WayType.bridleway, 1 },
|
|
|
|
{ WayType.steps, 2 },
|
|
|
|
{ WayType.corridor, 3 },
|
|
|
|
{ WayType.path, 4 },
|
2023-04-09 17:14:14 +02:00
|
|
|
{ WayType.cycleway, 1 },
|
2023-03-30 16:29:42 +02:00
|
|
|
{ WayType.construction, 0 }
|
|
|
|
};
|
2023-04-09 17:14:14 +02:00
|
|
|
// ReSharper disable InconsistentNaming
|
2023-03-30 16:29:42 +02:00
|
|
|
public enum WayType : byte { NONE, motorway, trunk, primary, secondary, tertiary, unclassified, residential, motorway_link, trunk_link, primary_link, secondary_link, tertiary_link, living_street, service, pedestrian, track, bus_guideway, escape, raceway, road, busway, footway, bridleway, steps, corridor, path, cycleway, construction }
|
2023-04-09 17:14:14 +02:00
|
|
|
// ReSharper restore InconsistentNaming
|
2023-03-30 16:29:42 +02:00
|
|
|
|
|
|
|
public enum SpeedType { pedestrian, car, road }
|
|
|
|
}
|