1 |
|
---|
2 | using System;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | namespace HeuristicLab.Problems.RoutePlanning.Osm {
|
---|
5 | #region Highway Types
|
---|
6 |
|
---|
7 | // see: https://wiki.openstreetmap.org/wiki/Key:highway
|
---|
8 | public enum HighwayType {
|
---|
9 | null_type,
|
---|
10 | motorway,
|
---|
11 | motorway_link,
|
---|
12 | trunk,
|
---|
13 | trunk_link,
|
---|
14 | primary,
|
---|
15 | primary_link,
|
---|
16 | secondary,
|
---|
17 | secondary_link,
|
---|
18 | tertiary,
|
---|
19 | tertiary_link,
|
---|
20 | living_street,
|
---|
21 | pedestrian,
|
---|
22 | residential,
|
---|
23 | unclassified,
|
---|
24 | service,
|
---|
25 | track,
|
---|
26 | bus_guideway,
|
---|
27 | raceway,
|
---|
28 | road,
|
---|
29 | path,
|
---|
30 | footway,
|
---|
31 | cycleway,
|
---|
32 | bridleway,
|
---|
33 | steps
|
---|
34 | }
|
---|
35 |
|
---|
36 | #endregion
|
---|
37 |
|
---|
38 | public class Way : OsmBase {
|
---|
39 | private List<Node> nodes;
|
---|
40 |
|
---|
41 | public Way() {
|
---|
42 | nodes = new List<Node>();
|
---|
43 | }
|
---|
44 |
|
---|
45 | public Way(long id)
|
---|
46 | : base(id) {
|
---|
47 | nodes = new List<Node>();
|
---|
48 | }
|
---|
49 |
|
---|
50 | public List<Node> Nodes {
|
---|
51 | get { return nodes; }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public HighwayType HighwayTag {
|
---|
55 | get {
|
---|
56 | if (!base.Tags.ContainsKey(TagConstants.HighwayTagKey)) {
|
---|
57 | return HighwayType.null_type;
|
---|
58 | }
|
---|
59 | if (Enum.IsDefined(typeof(HighwayType), base.Tags[TagConstants.HighwayTagKey])) {
|
---|
60 | HighwayType ht = (HighwayType)Enum.Parse(
|
---|
61 | typeof(HighwayType),
|
---|
62 | base.Tags[TagConstants.HighwayTagKey],
|
---|
63 | true);
|
---|
64 | return ht;
|
---|
65 | } else {
|
---|
66 | return HighwayType.null_type;
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | public bool OneWay {
|
---|
72 | get {
|
---|
73 | if (base.Tags.ContainsKey(TagConstants.OneWayTag)) {
|
---|
74 | string value = base.Tags[TagConstants.OneWayTag];
|
---|
75 | return value.Equals(TagConstants.YesValue);
|
---|
76 | } else {
|
---|
77 | return false;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | public bool CanBeTraversed(Node source, Node target) {
|
---|
83 | // check if way can be traveld by a specific vehicle (car, public transport, pedestiran, bicycle)
|
---|
84 | // if (!CanBeTraversed(Vehicle)) return false
|
---|
85 | if (OneWay) {
|
---|
86 | // if vehicle == pedestrian or bicylce -> return true
|
---|
87 | int sourceIndex = Nodes.IndexOf(source);
|
---|
88 | int targetIndex = Nodes.IndexOf(target);
|
---|
89 | // order of the nodes determines the driving direction
|
---|
90 | return (sourceIndex < targetIndex);
|
---|
91 | }
|
---|
92 | return true;
|
---|
93 | }
|
---|
94 |
|
---|
95 | //public bool CanBeTraversed(Vehicle) {}
|
---|
96 | }
|
---|
97 | }
|
---|