From a365c155b269a41fc8be6759e6dadfaa5cbe3b87 Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 24 Jul 2024 01:21:54 +0200 Subject: [PATCH] Add AccessType() AccessPermitted() to Way --- OSM_Graph/AccessEnum.cs | 11 +++++++++++ OSM_Graph/Way.cs | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 OSM_Graph/AccessEnum.cs diff --git a/OSM_Graph/AccessEnum.cs b/OSM_Graph/AccessEnum.cs new file mode 100644 index 0000000..b33e66e --- /dev/null +++ b/OSM_Graph/AccessEnum.cs @@ -0,0 +1,11 @@ +namespace OSM_Graph; + +public enum AccessEnum +{ + Yes, + No, + Private, + Permissive, + Agricultural, + Forestry +} \ No newline at end of file diff --git a/OSM_Graph/Way.cs b/OSM_Graph/Way.cs index 300c740..773a351 100644 --- a/OSM_Graph/Way.cs +++ b/OSM_Graph/Way.cs @@ -9,6 +9,19 @@ public class Way(ulong id, Dictionary tags, List nodeIds) public readonly ulong ID = id; public readonly List NodeIds = nodeIds; + public AccessEnum AccessType() + { + if (Tags.TryGetValue("access", out string? accessValue) && Enum.TryParse(accessValue, out AccessEnum access)) + return access; + return AccessEnum.Yes; + } + + public bool AccessPermitted() + { + AccessEnum[] permittedTypes = [AccessEnum.Yes, AccessEnum.Permissive]; + return permittedTypes.Contains(AccessType()); + } + public WayDirection GetDirection() { if (Tags.TryGetValue("oneway", out string? onewayStr))