Esempio n. 1
0
        public static bool BikingPermitted(string id, Way way)
        {
            if (way.HasTag("highway") || way.HasTag("bicycle"))
            {
                if (way.HasTag("bicycle", "no"))
                {
                    return(false);
                }
                if (way.HasTag("highway", "motorway") || way.HasTag("highway", "motorway_link"))
                {
                    return(false);
                }
                if (way.HasTag("footway", "sidewalk"))
                {
                    if (!way.HasTag("bicycle", "yes"))
                    {
                        if (way.HasTag("highway", "footway") || way.HasTag("highway", "path"))
                        {
                            return(false);
                        }
                    }
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
 /// <summary>
 /// Calculates the maximum speed for this way.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="way"></param>
 private int MaxSpeed(Way way)
 {
     if (way.Tags.ContainsKey("maxspeed"))
     {
         int    result;
         string maxspeed = way.Tags["maxspeed"];
         if (maxspeed == "national")
         {
             return(40);
         }
         else if (int.TryParse(maxspeed, out result))
         {
             return(result);
         }
         else
         {
             throw new Exception("Error: Unknown maxspeed value '" + maxspeed + "'.");
         }
     }
     else
     {
         if (way.HasTag("highway", "motorway"))
         {
             return(100);
         }
         else
         {
             return(50);
         }
     }
 }
Esempio n. 3
0
        private bool IsBikeLane(string id, Way way)
        {
            if (!IsSeparatedPath(id, way))
            {
                if (way.HasTag("cycleway", "lane") || way.HasTag("cycleway:right", "lane") || way.HasTag("cycleway:middle", "lane") || way.HasTag("cycleway", "opposite_lane"))
                {
                    return(true);
                }
                if (way.TagStartsWith("shoulder"))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        public int MixedTrafficAnalysis(string id, Way way)
        {
            int lanes;
            int maxSpeed = MaxSpeed(way);

            if (maxSpeed <= 40)
            {
                lanes = Lanes(way);
                if (lanes <= 3)
                {
                    return(2);
                }
                else if (lanes <= 5)
                {
                    return(3);
                }
            }
            else if (maxSpeed <= 50)
            {
                if (way.HasTag("service", "parking_aisle"))
                {
                    return(2);
                }
                lanes = Lanes(way);
                if (lanes < 3 && IsResidential(way))
                {
                    return(2);
                }
                else if (lanes <= 3)
                {
                    return(3);
                }
            }
            return(4);
        }
Esempio n. 5
0
        private bool IsSeparatedPath(string id, Way way)
        {
            if (way.HasTag("highway", "path") || way.HasTag("highway", "footway") || way.HasTag("highway", "cycleway"))
            {
                return(true);
            }
            if (way.HasTag("highway", "construction"))
            {
                if (way.HasTag("construction", "path") || way.HasTag("construction", "footway") || way.HasTag("construction", "cycleway"))
                {
                    return(true);
                }
            }
            // FIXME: This doesn't seem to be covered by the Ottawa OSM guide. E.g. Laurier.
            if (way.HasTag("cycleway", "track"))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 6
0
 /// <summary>
 /// Determines if the way has parking on it.
 /// </summary>
 /// <param name="way"></param>
 /// <returns></returns>
 private bool ParkingPresent(string id, Way way)
 {
     if (way.HasTag("parking", "yes"))
     {
         return(true);
     }
     if (way.TagStartsWith("parking:"))
     {
         foreach (KeyValuePair <string, string> tag in way.Tags)
         {
             string k = tag.Key;
             if (k.StartsWith("parking:lane:"))
             {
                 string v = tag.Value;
                 if (v == "parallel" || v == "perpendicular" || v == "diagonal" || v == "yes" || v == "marked")
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Esempio n. 7
0
 private bool IsResidential(Way way)
 {
     return(way.HasTag("highway", "residential"));
 }
Esempio n. 8
0
 /// <summary>
 /// Processes a way element at the current read position in the reader.
 /// Exits with the reader positioned at the next sibling element.
 /// </summary>
 /// <param name="i_reader">An XmlReader object with the read position on a way element.</param>
 private void ProcessWays1(XmlReader reader)
 {
     if (reader.IsStartElement("way"))
     {
         Way    way = new Way();
         string id  = reader.GetAttribute("id");
         if (reader.IsEmptyElement)
         {
             // Next node.
             reader.Read();
         }
         else
         {
             while (reader.Read())
             {
                 if (reader.Name == "tag")
                 {
                     way.AddTag(reader);
                 }
                 else if (reader.Name == "nd")
                 {
                     string nodeRef = reader.GetAttribute("ref");
                     way.Nodes.Add(nodeRef);
                 }
                 else
                 {
                     if (reader.NodeType == XmlNodeType.EndElement)
                     {
                         reader.Read();
                         break;
                     }
                     else
                     {
                         throw new Exception("Unexpected element: " + reader.ReadOuterXml());
                     }
                 }
             }
         }
         // This is a preliminary test to make sure we only add ways that are potentially valid
         // routes. This could be expanded to further filter the ways but this will typically
         // be done in the analysis phase.
         if (_options.IncludeBannedHighways || StressModel.BikingPermitted(id, way))
         {
             if (way.HasTag("highway"))
             {
                 _ways.Add(id, way);
                 foreach (string nodeRef in way.Nodes)
                 {
                     if (!_usedNodes.Contains(nodeRef))
                     {
                         _usedNodes.Add(nodeRef);
                     }
                 }
             }
         }
     }
     else
     {
         throw new Exception("Unexpected node: " + reader.Name);
     }
 }