[8290] | 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 |
|
---|
[8293] | 41 | public Way() {
|
---|
| 42 | nodes = new List<Node>();
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public Way(long id)
|
---|
[8290] | 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 | }
|
---|
[8369] | 70 |
|
---|
| 71 | public bool OneWay {
|
---|
| 72 | get {
|
---|
| 73 | if (base.Tags.ContainsKey(TagConstants.OneWayTag)) {
|
---|
| 74 | string value = base.Tags[TagConstants.OneWayTag];
|
---|
[8426] | 75 | return value.Equals(TagConstants.YesValue);
|
---|
[8369] | 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) {}
|
---|
[8408] | 96 |
|
---|
| 97 | public int GetMaxSpeed() {
|
---|
| 98 | int speed = 0;
|
---|
| 99 |
|
---|
| 100 | //TODO:
|
---|
| 101 | HighwayType highwayType = HighwayTag;
|
---|
| 102 | switch (highwayType) {
|
---|
| 103 | case HighwayType.bridleway:
|
---|
| 104 | case HighwayType.bus_guideway:
|
---|
| 105 | case HighwayType.raceway:
|
---|
| 106 | case HighwayType.cycleway:
|
---|
| 107 | case HighwayType.footway:
|
---|
| 108 | case HighwayType.steps:
|
---|
| 109 | case HighwayType.null_type:
|
---|
| 110 | speed = 1;
|
---|
| 111 | break;
|
---|
| 112 |
|
---|
| 113 | case HighwayType.path:
|
---|
| 114 | case HighwayType.service:
|
---|
| 115 | case HighwayType.pedestrian:
|
---|
| 116 | case HighwayType.living_street:
|
---|
| 117 | speed = 15;
|
---|
| 118 | break;
|
---|
| 119 |
|
---|
| 120 | case HighwayType.road:
|
---|
| 121 | case HighwayType.track:
|
---|
| 122 | speed = 30;
|
---|
| 123 | break;
|
---|
| 124 |
|
---|
| 125 | case HighwayType.tertiary:
|
---|
| 126 | case HighwayType.tertiary_link:
|
---|
| 127 | case HighwayType.secondary:
|
---|
| 128 | case HighwayType.secondary_link:
|
---|
| 129 | speed = 80;
|
---|
| 130 | break;
|
---|
| 131 |
|
---|
| 132 | case HighwayType.unclassified:
|
---|
| 133 | case HighwayType.residential:
|
---|
| 134 | speed = 50;
|
---|
| 135 | break;
|
---|
| 136 |
|
---|
| 137 | case HighwayType.trunk:
|
---|
| 138 | case HighwayType.trunk_link:
|
---|
| 139 | case HighwayType.primary:
|
---|
| 140 | case HighwayType.primary_link:
|
---|
| 141 | speed = 100;
|
---|
| 142 | break;
|
---|
| 143 | case HighwayType.motorway:
|
---|
| 144 | case HighwayType.motorway_link:
|
---|
| 145 | speed = 130;
|
---|
| 146 | break;
|
---|
| 147 |
|
---|
| 148 | default:
|
---|
| 149 | speed = 1;
|
---|
| 150 | break;
|
---|
| 151 | }
|
---|
| 152 | return speed;
|
---|
| 153 | }
|
---|
[8290] | 154 | }
|
---|
| 155 | }
|
---|