Esempio n. 1
0
        public override bool IsPotentiallyArea(TagsCollectionBase tags)
        {
            if (tags == null || tags.Count == 0)
            {
                return(false);
            }
            bool flag = false;

            if (tags.ContainsKey("building") && !tags.IsFalse("building") || tags.ContainsKey("landuse") && !tags.IsFalse("landuse") || (tags.ContainsKey("amenity") && !tags.IsFalse("amenity") || tags.ContainsKey("harbour") && !tags.IsFalse("harbour")) || (tags.ContainsKey("historic") && !tags.IsFalse("historic") || tags.ContainsKey("leisure") && !tags.IsFalse("leisure") || (tags.ContainsKey("man_made") && !tags.IsFalse("man_made") || tags.ContainsKey("military") && !tags.IsFalse("military"))) || (tags.ContainsKey("natural") && !tags.IsFalse("natural") || tags.ContainsKey("office") && !tags.IsFalse("office") || (tags.ContainsKey("place") && !tags.IsFalse("place") || tags.ContainsKey("power") && !tags.IsFalse("power")) || (tags.ContainsKey("public_transport") && !tags.IsFalse("public_transport") || tags.ContainsKey("shop") && !tags.IsFalse("shop") || (tags.ContainsKey("sport") && !tags.IsFalse("sport") || tags.ContainsKey("tourism") && !tags.IsFalse("tourism")))) || (tags.ContainsKey("waterway") && !tags.IsFalse("waterway") || tags.ContainsKey("wetland") && !tags.IsFalse("wetland") || (tags.ContainsKey("water") && !tags.IsFalse("water") || tags.ContainsKey("aeroway") && !tags.IsFalse("aeroway"))))
            {
                flag = true;
            }
            string str;

            if (tags.TryGetValue("type", out str))
            {
                if (str == "multipolygon")
                {
                    flag = true;
                }
                else if (str == "boundary")
                {
                    flag = true;
                }
            }
            if (tags.IsTrue("area"))
            {
                flag = true;
            }
            else if (tags.IsFalse("area"))
            {
                flag = false;
            }
            return(flag);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns true if the given tags collection contains tags that could represents an area.
        /// </summary>
        public override bool IsPotentiallyArea(TagsCollectionBase tags)
        {
            if (tags == null || tags.Count == 0)
            {
                return(false);
            }                                                      // no tags, assume no area.

            bool isArea = false;

            if ((tags.ContainsKey("building") && !tags.IsFalse("building")) ||
                (tags.ContainsKey("landuse") && !tags.IsFalse("landuse")) ||
                (tags.ContainsKey("amenity") && !tags.IsFalse("amenity")) ||
                (tags.ContainsKey("harbour") && !tags.IsFalse("harbour")) ||
                (tags.ContainsKey("historic") && !tags.IsFalse("historic")) ||
                (tags.ContainsKey("leisure") && !tags.IsFalse("leisure")) ||
                (tags.ContainsKey("man_made") && !tags.IsFalse("man_made")) ||
                (tags.ContainsKey("military") && !tags.IsFalse("military")) ||
                (tags.ContainsKey("natural") && !tags.IsFalse("natural")) ||
                (tags.ContainsKey("office") && !tags.IsFalse("office")) ||
                (tags.ContainsKey("place") && !tags.IsFalse("place")) ||
                (tags.ContainsKey("power") && !tags.IsFalse("power")) ||
                (tags.ContainsKey("public_transport") && !tags.IsFalse("public_transport")) ||
                (tags.ContainsKey("shop") && !tags.IsFalse("shop")) ||
                (tags.ContainsKey("sport") && !tags.IsFalse("sport")) ||
                (tags.ContainsKey("tourism") && !tags.IsFalse("tourism")) ||
                (tags.ContainsKey("waterway") && !tags.IsFalse("waterway") && !tags.Contains("waterway", "river") && !tags.Contains("waterway", "stream")) ||
                (tags.ContainsKey("wetland") && !tags.IsFalse("wetland")) ||
                (tags.ContainsKey("water") && !tags.IsFalse("water")) ||
                (tags.ContainsKey("aeroway") && !tags.IsFalse("aeroway")))
            {
                isArea = true;
            }

            string typeValue;

            if (tags.TryGetValue("type", out typeValue))
            {     // there is a type in this relation.
                if (typeValue == "multipolygon")
                { // this relation is a multipolygon.
                    isArea = true;
                }
                else if (typeValue == "boundary")
                { // this relation is a boundary.
                    isArea = true;
                }
            }

            if (tags.IsTrue("area"))
            { // explicitly indicated that this is an area.
                isArea = true;
            }
            else if (tags.IsFalse("area"))
            { // explicitly indicated that this is not an area.
                isArea = false;
            }

            return(isArea);
        }
Esempio n. 3
0
 protected bool TryGetHighwayType(TagsCollectionBase tags, out string highwayType)
 {
     highwayType = string.Empty;
     if (tags != null)
     {
         return(tags.TryGetValue("highway", out highwayType));
     }
     return(false);
 }
Esempio n. 4
0
        public static bool IsFalse(this TagsCollectionBase tags, string tagKey)
        {
            string str;

            if (tags == null || string.IsNullOrWhiteSpace(tagKey) || !tags.TryGetValue(tagKey, out str))
            {
                return(false);
            }
            return(((IEnumerable <string>)TagExtensions.BooleanFalseValues).Contains <string>(str.ToLowerInvariant()));
        }
Esempio n. 5
0
 /// <summary>
 ///     Returns true if the edge with the given tags is only accessible locally.
 /// </summary>
 /// <param name="tags"></param>
 /// <returns></returns>
 public bool IsOnlyLocalAccessible(TagsCollectionBase tags)
 {
     string tag;
     if (tags.TryGetValue("highway", out tag))
     {
         if (tag == "service")
         {
             return true;
         }
     }
     if (tags.TryGetValue("access", out tag))
     {
         if (tag == "private" || tag == "official")
         {
             return true;
         }
     }
     return false;
 }
Esempio n. 6
0
        /// <summary>
        /// Searches for a max width tag and returns the associated value.
        ///
        /// http://wiki.openstreetmap.org/wiki/Key:maxwidth
        /// </summary>
        /// <param name="tags">The tags to search.</param>
        /// <param name="result"></param>
        /// <returns></returns>
        public static bool TryGetMaxWidth(this TagsCollectionBase tags, out Meter result)
        {
            result = double.MaxValue;
            string tagValue;

            if (tags == null || !tags.TryGetValue("maxwidth", out tagValue) || Utilities.IsNullOrWhiteSpace(tagValue))
            {
                return(false);
            }
            return(TagExtensions.TryParseLength(tagValue, out result));
        }
Esempio n. 7
0
 internal static void ContainsTags(TagsCollectionBase tags, params string[] keys)
 {
     foreach (var key in keys)
     {
         if (!tags.TryGetValue(key, out string value) ||
             string.IsNullOrEmpty(value))
         {
             throw new ArgumentException($"TagCollection is missing the required key: {key}");
         }
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Returns true if the given tags key has an associated value that can be interpreted as false.
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="tagKey"></param>
        /// <returns></returns>
        public static bool IsFalse(this TagsCollectionBase tags, string tagKey)
        {
            if (tags == null || Utilities.IsNullOrWhiteSpace(tagKey))
            {
                return(false);
            }
            string tagValue;

            return(tags.TryGetValue(tagKey, out tagValue) &&
                   BooleanFalseValues.Contains(tagValue.ToLowerInvariant()));
        }
Esempio n. 9
0
        public static bool?InterpretAccessValue(this TagsCollectionBase tags, string key)
        {
            string key1;
            bool?  nullable;

            if (tags.TryGetValue(key, out key1) && VehicleExtensions.GetAccessValues().TryGetValue(key1, out nullable))
            {
                return(nullable);
            }
            return(new bool?());
        }
Esempio n. 10
0
        /// <summary>
        ///     Returns true if the edge with the given tags is only accessible locally.
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        public bool IsOnlyLocalAccessible(TagsCollectionBase tags)
        {
            string tag;

            if (tags.TryGetValue("highway", out tag))
            {
                if (tag == "service")
                {
                    return(true);
                }
            }
            if (tags.TryGetValue("access", out tag))
            {
                if (tag == "private" || tag == "official")
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 11
0
        public static bool TryGetMaxWeight(this TagsCollectionBase tags, out Kilogram result)
        {
            result = (Kilogram)double.MaxValue;
            string s;

            if (tags == null || !tags.TryGetValue("maxweight", out s) || string.IsNullOrWhiteSpace(s))
            {
                return(false);
            }
            return(TagExtensions.TryParseWeight(s, out result));
        }
Esempio n. 12
0
        public static bool TryGetMaxSpeed(this TagsCollectionBase tags, out KilometerPerHour result)
        {
            result = (KilometerPerHour)double.MaxValue;
            string s;

            if (tags == null || !tags.TryGetValue("maxspeed", out s) || (string.IsNullOrWhiteSpace(s) || s == "none") || (s == "signals" || s == "signs" || s == "no"))
            {
                return(false);
            }
            return(TagExtensions.TryParseSpeed(s, out result));
        }
Esempio n. 13
0
        /// <summary>
        /// Searches for a max axle load tag and returns the associated value.
        ///
        /// http://wiki.openstreetmap.org/wiki/Key:maxaxleload
        /// </summary>
        /// <param name="tags">The tags to search.</param>
        /// <param name="result"></param>
        /// <returns></returns>
        public static bool TryGetMaxAxleLoad(this TagsCollectionBase tags, out Kilogram result)
        {
            result = double.MaxValue;
            string tagValue;

            if (tags == null || !tags.TryGetValue("maxaxleload", out tagValue) || Utilities.IsNullOrWhiteSpace(tagValue))
            {
                return(false);
            }
            return(TagExtensions.TryParseWeight(tagValue, out result));
        }
Esempio n. 14
0
        public static bool TryGetMaxHeight(this TagsCollectionBase tags, out Meter result)
        {
            result = (Meter)double.MaxValue;
            string s;

            if (tags == null || !tags.TryGetValue("maxheight", out s) || string.IsNullOrWhiteSpace(s))
            {
                return(false);
            }
            return(TagExtensions.TryParseLength(s, out result));
        }
Esempio n. 15
0
        /// <summary>
        /// Searches for a maxspeed tag and returns the associated value.
        ///
        ///  http://wiki.openstreetmap.org/wiki/Key:maxspeed
        /// </summary>
        /// <param name="tags">The tags to search.</param>
        /// <param name="result"></param>
        /// <returns></returns>
        public static bool TryGetMaxSpeed(this TagsCollectionBase tags, out KilometerPerHour result)
        {
            result = double.MaxValue;
            string tagValue;

            if (tags == null || !tags.TryGetValue("maxspeed", out tagValue) || Utilities.IsNullOrWhiteSpace(tagValue) ||
                tagValue == "none" || tagValue == "signals" || tagValue == "signs" || tagValue == "no")
            {
                return(false);
            }
            return(TagExtensions.TryParseSpeed(tagValue, out result));
        }
Esempio n. 16
0
 public static void AddOrAppend(this TagsCollectionBase tags, string key, params string[] newValues)
 {
     if (tags.TryGetValue(key, out var oldValue))
     {
         foreach (var newValue in newValues.Where(n => !oldValue.Contains(n)))
         {
             tags[key] += ";" + newValue;
         }
     }
     else
     {
         tags.Add(key, string.Join(";", newValues));
     }
 }
Esempio n. 17
0
        //private const string REGEX_UNIT_KILOMETERS_PER_HOUR = @"\s*(kmh|km/h|kph)?\s*";
        //private const string REGEX_UNIT_MILES_PER_HOUR = @"\s*(mph)?\s*";

        /// <summary>
        /// Returns true if the given tags key has an associated value that can be interpreted as true.
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="tagKey"></param>
        /// <returns></returns>
        public static bool IsTrue(this TagsCollectionBase tags, string tagKey)
        {
            if (tags == null || Utilities.IsNullOrWhiteSpace(tagKey))
            {
                return(false);
            }

            // TryGetValue tests if the 'tagKey' is present, returns true if the associated value can be interpreted as true.
            //                                               returns false if the associated value can be interpreted as false.
            string tagValue;

            return(tags.TryGetValue(tagKey, out tagValue) &&
                   BooleanTrueValues.Contains(tagValue.ToLowerInvariant()));
        }
Esempio n. 18
0
        /// <summary>
        ///     Returns true if the edge is one way forward, false if backward, null if bidirectional.
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        public virtual bool?IsOneWay(TagsCollectionBase tags)
        {
            string oneway;

            if (tags.TryGetValue("oneway", out oneway))
            {
                if (oneway == "yes")
                {
                    return(true);
                }
                return(false);
            }
            string junction;

            if (tags.TryGetValue("junction", out junction))
            {
                if (junction == "roundabout")
                {
                    return(true);
                }
            }
            return(null);
        }
Esempio n. 19
0
        public override bool?IsOneWay(TagsCollectionBase tags)
        {
            string str1;

            if (tags.TryGetValue("oneway:bicycle", out str1))
            {
                if (str1 == "yes")
                {
                    return(new bool?(true));
                }
                if (str1 == "no")
                {
                    return(new bool?());
                }
                return(new bool?(false));
            }
            if (tags.TryGetValue("oneway", out str1))
            {
                if (str1 == "yes")
                {
                    return(new bool?(true));
                }
                if (str1 == "no")
                {
                    return(new bool?());
                }
                return(new bool?(false));
            }
            string str2;

            if (tags.TryGetValue("junction", out str2) && str2 == "roundabout")
            {
                return(new bool?(true));
            }
            return(new bool?());
        }
Esempio n. 20
0
 public static string GetAccessTag(this TagsCollectionBase tags, IEnumerable <string> accessTagHierachy)
 {
     if (tags == null)
     {
         return((string)null);
     }
     foreach (string key in accessTagHierachy)
     {
         string str;
         if (tags.TryGetValue(key, out str))
         {
             return(str);
         }
     }
     return((string)null);
 }
Esempio n. 21
0
 /// <summary>
 /// Searches for the tags collection for the <c>Access</c>-Tags and returns the associated values.
 ///
 /// http://wiki.openstreetmap.org/wiki/Key:access
 /// </summary>
 /// <param name="tags">The tags to search.</param>
 /// <param name="accessTagHierachy">The hierarchy of <c>Access</c>-Tags for different vehicle types.</param>
 /// <returns>The best fitting value is returned.</returns>
 public static string GetAccessTag(this TagsCollectionBase tags, IEnumerable <string> accessTagHierachy)
 {
     if (tags == null)
     {
         return(null);
     }
     foreach (string s in accessTagHierachy)
     {
         string access;
         if (tags.TryGetValue(s, out access))
         {
             return(access);
         }
     }
     return(null);
 }
Esempio n. 22
0
        /// <summary>
        /// Returns true if the edge is a suitable candidate as a target for a point to be resolved on.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="pointTags"></param>
        /// <param name="edgeTags"></param>
        /// <returns></returns>
        public bool MatchWithEdge(Vehicle vehicle,
            TagsCollectionBase pointTags, TagsCollectionBase edgeTags)
        {
            if (pointTags == null || pointTags.Count == 0)
            { // when the point has no tags it has no requirements.
                return true;
            }

            if (edgeTags == null || edgeTags.Count == 0)
            { // when the edge has no tags, no way to verify.
                return false;
            }

            string pointName, edgeName;
            if (pointTags.TryGetValue("name", out pointName) &&
                edgeTags.TryGetValue("name", out edgeName))
            { // both have names.
                return (pointName == edgeName);
            }
            return false;
        }
Esempio n. 23
0
        /// <summary>
        /// Returns true if the edge is a suitable candidate as a target for a point to be resolved on.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="pointTags"></param>
        /// <param name="edgeTags"></param>
        /// <returns></returns>
        public bool MatchWithEdge(Vehicle vehicle,
                                  TagsCollectionBase pointTags, TagsCollectionBase edgeTags)
        {
            if (pointTags == null || pointTags.Count == 0)
            { // when the point has no tags it has no requirements.
                return(true);
            }

            if (edgeTags == null || edgeTags.Count == 0)
            { // when the edge has no tags, no way to verify.
                return(false);
            }

            string pointName, edgeName;

            if (pointTags.TryGetValue("name", out pointName) &&
                edgeTags.TryGetValue("name", out edgeName))
            { // both have names.
                return(pointName.LevenshteinMatch(edgeName, 90));
            }
            return(false);
        }
Esempio n. 24
0
        /// <summary>
        /// Returns true if the given tags collection contains tags that could represents an area. waterway=river or waterway=stream could be potential false positives,
        /// but can't be confirmed without the actual geometry or the area=* tag set to true or false.
        /// </summary>
        public bool IsPotentiallyArea(TagsCollectionBase tags)
        {
            if (tags == null || tags.Count == 0)
            {
                return(false); // no tags, assume no area.
            }
            if (tags.IsTrue("area"))
            {
                return(true);
            }
            else if (tags.IsFalse("area"))
            {
                return(false);
            }

            bool isArea = false;

            if (tags.ContainsAnyKey(areaTags))
            {
                isArea = true;
            }

            if (tags.TryGetValue("type", out var typeValue))
            {
                switch (typeValue)
                {
                // there is a type in this relation.
                case "multipolygon":
                // this relation is a boundary.
                case "boundary":     // this relation is a multipolygon.
                    isArea = true;
                    break;
                }
            }
            return(isArea);
        }
        /// <summary>
        /// Returns true if the given tags collection contains tags that could represents an area.
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        public override bool IsPotentiallyArea(TagsCollectionBase tags)
        {
            if (tags == null || tags.Count == 0) { return false; } // no tags, assume no area.

            bool isArea = false;
            if ((tags.ContainsKey("building") && !tags.IsFalse("building")) ||
                (tags.ContainsKey("landuse") && !tags.IsFalse("landuse")) ||
                (tags.ContainsKey("amenity") && !tags.IsFalse("amenity")) ||
                (tags.ContainsKey("harbour") && !tags.IsFalse("harbour")) ||
                (tags.ContainsKey("historic") && !tags.IsFalse("historic")) ||
                (tags.ContainsKey("leisure") && !tags.IsFalse("leisure")) ||
                (tags.ContainsKey("man_made") && !tags.IsFalse("man_made")) ||
                (tags.ContainsKey("military") && !tags.IsFalse("military")) ||
                (tags.ContainsKey("natural") && !tags.IsFalse("natural")) ||
                (tags.ContainsKey("office") && !tags.IsFalse("office")) ||
                (tags.ContainsKey("place") && !tags.IsFalse("place")) ||
                (tags.ContainsKey("power") && !tags.IsFalse("power")) ||
                (tags.ContainsKey("public_transport") && !tags.IsFalse("public_transport")) ||
                (tags.ContainsKey("shop") && !tags.IsFalse("shop")) ||
                (tags.ContainsKey("sport") && !tags.IsFalse("sport")) ||
                (tags.ContainsKey("tourism") && !tags.IsFalse("tourism")) ||
                (tags.ContainsKey("waterway") && !tags.IsFalse("waterway")) ||
                (tags.ContainsKey("wetland") && !tags.IsFalse("wetland")) ||
                (tags.ContainsKey("water") && !tags.IsFalse("water")) ||
                (tags.ContainsKey("aeroway") && !tags.IsFalse("aeroway")))
            { // these tags usually indicate an area.
                isArea = true;
            }

            string typeValue;
            if (tags.TryGetValue("type", out typeValue))
            { // there is a type in this relation.
                if (typeValue == "multipolygon")
                { // this relation is a multipolygon.
                    isArea = true;
                }
                else if (typeValue == "boundary")
                { // this relation is a boundary.
                    isArea = true;
                }
            }

            if (tags.IsTrue("area"))
            { // explicitly indicated that this is an area.
                isArea = true;
            }
            else if (tags.IsFalse("area"))
            { // explicitly indicated that this is not an area.
                isArea = false;
            }

            return isArea;
        }
Esempio n. 26
0
        /// <summary>
        /// The actual conflation.
        /// Returns true if conflation is finished and this grbPoly has been matched
        /// </summary>
        private static bool AttemptConflate(Geometry grbPoly, Geometry osmPoly, TagsCollectionBase grbTags,
                                            ICompleteOsmGeo osmObj, EasyChangeset cs)
        {
            // Is there geographical match?
            if (Math.Abs(osmPoly.Centroid.Distance(grbPoly.Centroid)) > 0.000001)
            {
                return(false);
            }

            if (osmPoly.Difference(grbPoly).Area > 0.000000001)
            {
                return(false);
            }

            if (grbPoly.Difference(osmPoly).Area > 0.000000001)
            {
                return(false);
            }

            if (grbTags == null)
            {
                Console.WriteLine("PANIC for grb object " + grbPoly);
                return(false);
            }


            if (osmObj.Tags.TryGetValue("building", out var osmBuildingValue))
            {
                if (osmBuildingValue.Equals("yes"))
                {
                    osmObj.Tags.RemoveKey("building");
                }
                else
                {
                    grbTags.TryGetValue("building", out var grbBuildingValue);
                    if (grbBuildingValue == null)
                    {
                        Console.WriteLine("GRB Building value is null");
                    }
                    else if (osmBuildingValue != grbBuildingValue)
                    {
                        if (!grbBuildingValue.Equals("yes"))
                        {
                            Console.WriteLine(
                                $"Preferring OSM building-tag '{osmBuildingValue}' over the grb tag '{grbBuildingValue}'");
                        }

                        grbTags.RemoveKey("building");
                    }
                }
            }

            if (osmObj.Tags.TryGetValue("source:geometry:ref", out var osmSourceRef))
            {
                grbTags.TryGetValue("source:geometry:ref", out var grbRef);
                if (!osmSourceRef.Equals(grbRef))
                {
                    throw new Exception($"MISMATCH for {osmObj}: {osmSourceRef} != {grbRef}");
                }

                osmObj.Tags.RemoveKey("source:geometry:date");
            }


            if (osmObj.Tags.TryGetValue("addr:housenumber", out var osmHouseNumber))
            {
                grbTags.TryGetValue("addr:housenumber", out var grbHouseNumber);
                if (!osmHouseNumber.Equals(grbHouseNumber))
                {
                    grbTags.RemoveKey("addr:housenumber");

                    var msg = "GRB thinks that this has number " +
                              (string.IsNullOrEmpty(grbHouseNumber) ? "no number" : grbHouseNumber);

                    Console.WriteLine(
                        $"GRB and OSM disagree over housenumber of {osmObj}. Putting a fixme instead: grb: {grbHouseNumber} != osm {osmHouseNumber}");
                    if (grbTags.ContainsKey("fixme"))
                    {
                        msg += ";" + grbTags.GetValue("fixme");
                    }

                    grbTags.AddOrReplace("fixme", msg);
                }
            }

            if (osmObj.Tags.TryGetValue("addr:street", out var osmStreet))
            {
                grbTags.TryGetValue("addr:street", out var grbStreet);
                if (!string.IsNullOrEmpty(grbStreet) && !osmStreet.Equals(grbStreet))
                {
                    grbTags.RemoveKey("addr:street");

                    var msg = "GRB thinks that this lays in street " + grbStreet;

                    Console.WriteLine(
                        $"GRB and OSM disagree over streetname of {osmObj}. Putting a fixme instead: grb: {grbStreet} != osm {osmStreet}");
                    if (grbTags.ContainsKey("fixme"))
                    {
                        msg += ";" + grbTags.GetValue("fixme");
                    }

                    grbTags.AddOrReplace("fixme", msg);
                }
            }


            try
            {
                foreach (var grbTag in grbTags)
                {
                    if (grbTag.Key.Contains("wrong"))
                    {
                        continue;
                    }

                    osmObj.AddNewTag(grbTag.Key, grbTag.Value);
                }

                cs.AddChange(osmObj);
            }
            catch (Exception e)
            {
                Console.WriteLine($"{osmObj}: {e.Message}: skipping match");
            }


            return(true);
        }
Esempio n. 27
0
 /// <summary>
 /// Trys to return the highwaytype from the tags
 /// </summary>
 /// <param name="tags"></param>
 /// <param name="highwayType"></param>
 /// <returns></returns>
 protected bool TryGetHighwayType(TagsCollectionBase tags, out string highwayType)
 {
     return(tags.TryGetValue("highway", out highwayType));
 }
Esempio n. 28
0
        /// <summary>
        ///     Returns true if the edge with the given properties represents a roundabout.
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        public bool IsRoundabout(TagsCollectionBase tags)
        {
            string junction;

            return(tags != null && tags.TryGetValue("junction", out junction) && junction == "roundabout");
        }
Esempio n. 29
0
        /// <summary>
        /// Tries to match the given tags and figure out a corresponding frc and fow.
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="frc"></param>
        /// <param name="fow"></param>
        /// <returns>False if no matching was found.</returns>
        public override bool TryMatching(TagsCollectionBase tags, out FunctionalRoadClass frc, out FormOfWay fow)
        {
            frc = FunctionalRoadClass.Frc7;
            fow = FormOfWay.Undefined;
            string highway;

            if (tags.TryGetValue("highway", out highway))
            {
                switch (highway)
                { // check there reference values against OSM: http://wiki.openstreetmap.org/wiki/Highway
                case "motorway":
                case "trunk":
                    frc = FunctionalRoadClass.Frc0;
                    break;

                case "primary":
                case "primary_link":
                    frc = FunctionalRoadClass.Frc1;
                    break;

                case "secondary":
                case "secondary_link":
                    frc = FunctionalRoadClass.Frc2;
                    break;

                case "tertiary":
                case "tertiary_link":
                    frc = FunctionalRoadClass.Frc3;
                    break;

                case "road":
                case "road_link":
                case "unclassified":
                case "residential":
                    frc = FunctionalRoadClass.Frc4;
                    break;

                case "living_street":
                    frc = FunctionalRoadClass.Frc5;
                    break;

                default:
                    frc = FunctionalRoadClass.Frc7;
                    break;
                }
                switch (highway)
                { // check there reference values against OSM: http://wiki.openstreetmap.org/wiki/Highway
                case "motorway":
                case "trunk":
                    fow = FormOfWay.Motorway;
                    break;

                case "primary":
                case "primary_link":
                    fow = FormOfWay.MultipleCarriageWay;
                    break;

                case "secondary":
                case "secondary_link":
                case "tertiary":
                case "tertiary_link":
                    fow = FormOfWay.SingleCarriageWay;
                    break;

                default:
                    fow = FormOfWay.SingleCarriageWay;
                    break;
                }
                return(true); // should never fail on a highway tag.
            }
            return(false);
        }
 /// <summary>
 /// Tries to get the value for the given key.
 /// </summary>
 public bool TryGetValue(string key, out string value)
 {
     return(_tagCollection.TryGetValue(key, out value));
 }
Esempio n. 31
0
        /// <summary>
        /// Calculates a match between the tags collection and the properties of the OpenLR location reference.
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="fow"></param>
        /// <param name="frc"></param>
        /// <returns></returns>
        public override float MatchArc(TagsCollectionBase tags, FormOfWay fow, FunctionalRoadClass frc)
        {
            string highway;

            if (!tags.TryGetValue("highway", out highway))
            { // not even a highway tag!
                return(0);
            }

            // TODO: take into account form of way? Maybe not for OSM-data?
            switch (frc)
            {                              // check there reference values against OSM: http://wiki.openstreetmap.org/wiki/Highway
            case FunctionalRoadClass.Frc0: // main road.
                if (highway == "motorway" || highway == "trunk")
                {
                    return(1);
                }
                break;

            case FunctionalRoadClass.Frc1:     // first class road.
                if (highway == "primary" || highway == "primary_link")
                {
                    return(1);
                }
                break;

            case FunctionalRoadClass.Frc2:     // second class road.
                if (highway == "secondary" || highway == "secondary_link")
                {
                    return(1);
                }
                break;

            case FunctionalRoadClass.Frc3:     // third class road.
                if (highway == "tertiary" || highway == "tertiary_link")
                {
                    return(1);
                }
                break;

            case FunctionalRoadClass.Frc4:
                if (highway == "road" || highway == "road_link" ||
                    highway == "unclassified" || highway == "residential")
                {
                    return(1);
                }
                break;

            case FunctionalRoadClass.Frc5:
                if (highway == "road" || highway == "road_link" ||
                    highway == "unclassified" || highway == "residential" ||
                    highway == "living_street")
                {
                    return(1);
                }
                break;

            case FunctionalRoadClass.Frc6:
                if (highway == "road" || highway == "track" ||
                    highway == "unclassified" || highway == "residential" ||
                    highway == "living_street")
                {
                    return(1);
                }
                break;

            case FunctionalRoadClass.Frc7:     // other class road.
                if (highway == "footway" || highway == "bridleway" ||
                    highway == "steps" || highway == "path" ||
                    highway == "living_street")
                {
                    return(1);
                }
                break;
            }

            if (highway != null && highway.Length > 0)
            { // for any other highway return a low match.
                return(0.2f);
            }
            return(0);
        }
Esempio n. 32
0
 /// <summary>
 /// Trys to return the highwaytype from the tags
 /// </summary>
 /// <param name="tags"></param>
 /// <param name="highwayType"></param>
 /// <returns></returns>
 protected bool TryGetHighwayType(TagsCollectionBase tags, out string highwayType)
 {
     return tags.TryGetValue("highway", out highwayType);
 }
Esempio n. 33
0
 /// <summary>
 ///     Returns true if the edge is one way forward, false if backward, null if bidirectional.
 /// </summary>
 /// <param name="tags"></param>
 /// <returns></returns>
 public virtual bool? IsOneWay(TagsCollectionBase tags)
 {
     string oneway;
     if (tags.TryGetValue("oneway", out oneway))
     {
         if (oneway == "yes")
         {
             return true;
         }
         return false;
     }
     string junction;
     if (tags.TryGetValue("junction", out junction))
     {
         if (junction == "roundabout")
         {
             return true;
         }
     }
     return null;
 }
Esempio n. 34
0
 /// <summary>
 /// Trys to return the highwaytype from the tags
 /// </summary>
 /// <param name="tags"></param>
 /// <param name="highwayType"></param>
 /// <returns></returns>
 protected bool TryGetHighwayType(TagsCollectionBase tags, out string highwayType)
 {
     highwayType = string.Empty;
     return tags != null && tags.TryGetValue("highway", out highwayType);
 }
Esempio n. 35
0
        /// <summary>
        /// Calculates a match between the tags collection and the properties of the OpenLR location reference.
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="fow"></param>
        /// <param name="frc"></param>
        /// <returns></returns>
        public override float MatchArc(TagsCollectionBase tags, FormOfWay fow, FunctionalRoadClass frc)
        {
            string frcString;

            if (!tags.TryGetValue("FRC", out frcString))
            { // not even an FRC column.
                return(0);
            }

            float frcOneDifferent  = 0.8f;
            float frcTwoDifferent  = 0.6f;
            float frcMoreDifferent = 0.4f;

            var frcScore = 0.0f;

            switch (frcString)
            {
            case "0":     // main road.
                if (frc == FunctionalRoadClass.Frc0)
                {
                    frcScore = 1;
                }
                else if (frc == FunctionalRoadClass.Frc1)
                {
                    frcScore = frcOneDifferent;
                }
                else if (frc == FunctionalRoadClass.Frc2)
                {
                    frcScore = frcTwoDifferent;
                }
                else
                {
                    frcScore = frcMoreDifferent;
                }
                break;

            case "1":     // first class road.
                if (frc == FunctionalRoadClass.Frc1)
                {
                    frcScore = 1;
                }
                else if (frc == FunctionalRoadClass.Frc0 ||
                         frc == FunctionalRoadClass.Frc2)
                {
                    frcScore = frcOneDifferent;
                }
                else if (frc == FunctionalRoadClass.Frc3)
                {
                    frcScore = frcTwoDifferent;
                }
                else
                {
                    frcScore = frcMoreDifferent;
                }
                break;

            case "2":     // second class road.
                if (frc == FunctionalRoadClass.Frc2)
                {
                    frcScore = 1;
                }
                else if (frc == FunctionalRoadClass.Frc1 ||
                         frc == FunctionalRoadClass.Frc3)
                {
                    frcScore = frcOneDifferent;
                }
                else if (frc == FunctionalRoadClass.Frc4 ||
                         frc == FunctionalRoadClass.Frc0)
                {
                    frcScore = frcTwoDifferent;
                }
                else
                {
                    frcScore = frcMoreDifferent;
                }
                break;

            case "3":
                if (frc == FunctionalRoadClass.Frc3)
                {
                    frcScore = 1;
                }
                else if (frc == FunctionalRoadClass.Frc2 ||
                         frc == FunctionalRoadClass.Frc4)
                {
                    frcScore = frcOneDifferent;
                }
                else if (frc == FunctionalRoadClass.Frc1 ||
                         frc == FunctionalRoadClass.Frc5)
                {
                    frcScore = frcTwoDifferent;
                }
                else
                {
                    frcScore = frcMoreDifferent;
                }
                break;

            case "4":
                if (frc == FunctionalRoadClass.Frc4)
                {
                    frcScore = 1;
                }
                else if (frc == FunctionalRoadClass.Frc3 ||
                         frc == FunctionalRoadClass.Frc5)
                {
                    frcScore = frcOneDifferent;
                }
                else if (frc == FunctionalRoadClass.Frc2 ||
                         frc == FunctionalRoadClass.Frc6)
                {
                    frcScore = frcTwoDifferent;
                }
                else
                {
                    frcScore = frcMoreDifferent;
                }
                break;

            case "5":
                if (frc == FunctionalRoadClass.Frc5)
                {
                    frcScore = 1;
                }
                else if (frc == FunctionalRoadClass.Frc4 ||
                         frc == FunctionalRoadClass.Frc6)
                {
                    frcScore = frcOneDifferent;
                }
                else if (frc == FunctionalRoadClass.Frc3 ||
                         frc == FunctionalRoadClass.Frc7)
                {
                    frcScore = frcTwoDifferent;
                }
                else
                {
                    frcScore = frcMoreDifferent;
                }
                break;

            case "6":
                if (frc == FunctionalRoadClass.Frc6)
                {
                    frcScore = 1;
                }
                else if (frc == FunctionalRoadClass.Frc5 ||
                         frc == FunctionalRoadClass.Frc7)
                {
                    frcScore = frcOneDifferent;
                }
                else if (frc == FunctionalRoadClass.Frc4)
                {
                    frcScore = frcTwoDifferent;
                }
                else
                {
                    frcScore = frcMoreDifferent;
                }
                break;

            case "7":
                if (frc == FunctionalRoadClass.Frc7)
                {
                    frcScore = 1;
                }
                else if (frc == FunctionalRoadClass.Frc6)
                {
                    frcScore = frcOneDifferent;
                }
                else if (frc == FunctionalRoadClass.Frc5)
                {
                    frcScore = frcTwoDifferent;
                }
                else
                {
                    frcScore = frcMoreDifferent;
                }
                break;

            case "8":
                if (frc == FunctionalRoadClass.Frc7)
                {
                    frcScore = frcOneDifferent;
                }
                else if (frc == FunctionalRoadClass.Frc6)
                {
                    frcScore = frcTwoDifferent;
                }
                else
                {
                    frcScore = frcMoreDifferent;
                }
                break;
            }

            float fowOneDifferent  = 0.8f;
            float fowMoreDifferent = 0.4f;

            var    fowScore = 0.0f;
            string fowString;

            if (tags.TryGetValue("FOW", out fowString))
            {
                fowScore = 0.2f;
                switch (fowString)
                {
                case "1":
                    if (fow == FormOfWay.Motorway)
                    {
                        fowScore = 1;
                    }
                    else if (fow == FormOfWay.MultipleCarriageWay)
                    {
                        fowScore = fowOneDifferent;
                    }
                    break;

                case "2":
                    if (fow == FormOfWay.MultipleCarriageWay)
                    {
                        fowScore = 1;
                    }
                    else if (fow == FormOfWay.Motorway ||
                             fow == FormOfWay.SingleCarriageWay)
                    {
                        fowScore = fowOneDifferent;
                    }
                    break;

                case "3":
                    if (fow == FormOfWay.SingleCarriageWay)
                    {
                        fowScore = 1;
                    }
                    else if (fow == FormOfWay.MultipleCarriageWay)
                    {
                        fowScore = fowOneDifferent;
                    }
                    break;

                case "4":
                    if (fow == FormOfWay.Roundabout)
                    {
                        fowScore = 1;
                    }
                    fowScore = fowMoreDifferent;
                    break;

                case "8":
                    if (fow == FormOfWay.TrafficSquare)
                    {
                        fowScore = 1;
                    }
                    fowScore = fowMoreDifferent;
                    break;

                case "10":
                    if (fow == FormOfWay.SlipRoad)
                    {
                        fowScore = 1;
                    }
                    fowScore = fowMoreDifferent;
                    break;

                case "6":
                case "7":
                case "9":
                case "11":
                case "12":
                case "14":
                case "15":
                    if (fow == FormOfWay.Other)
                    {
                        fowScore = fowOneDifferent;
                    }
                    break;

                default:
                    if (fow == FormOfWay.Undefined)
                    {
                        fowScore = fowMoreDifferent;
                    }
                    break;
                }
            }
            return(frcScore + fowScore);
        }
Esempio n. 36
0
 /// <summary>
 ///     Returns true if the edge with the given properties represents a roundabout.
 /// </summary>
 /// <param name="tags"></param>
 /// <returns></returns>
 public bool IsRoundabout(TagsCollectionBase tags)
 {
     string junction;
     return (tags != null && tags.TryGetValue("junction", out junction) && junction == "roundabout");
 }
Esempio n. 37
0
        private void processTag <T>(string v, TagsCollectionBase tags, LaneDescription[] descriptions, ProcessTagValue <T> process, Action <LaneDescription, int, T> setter)
        {
            T      parsedValue;
            string value;

            if (tags.TryGetValue(v, out value))
            {
                if (process(value, out parsedValue))
                {
                    for (int i = 0; i < descriptions.Length; i++)
                    {
                        setter(descriptions[i], i, parsedValue);
                    }
                }
            }


            if (tags.TryGetValue(v + ":lanes", out value))
            {
                var split = value.Split('|');
                for (int i = 0; i < split.Length; i++)
                {
                    if (i < descriptions.Length)
                    {
                        foreach (var val in split[i].Split(';'))
                        {
                            if (process(val, out parsedValue))
                            {
                                setter(descriptions[i], i, parsedValue);
                            }
                        }
                    }
                    else
                    {
                        // something wrong here
                    }
                }
            }


            if (tags.TryGetValue(v + ":lanes:forward", out value))
            {
                var forwardLanes = descriptions.Where(l => !l.Reverse).ToArray();
                var split        = value.Split('|');
                for (int i = 0; i < split.Length; i++)
                {
                    if (i < forwardLanes.Length)
                    {
                        foreach (var val in split[i].Split(';'))
                        {
                            if (process(val, out parsedValue))
                            {
                                setter(forwardLanes[i], i, parsedValue);
                            }
                        }
                    }
                    else
                    {
                        // something wrong here
                    }
                }
            }
            if (tags.TryGetValue(v + ":lanes:backward", out value))
            {
                var forwardLanes = descriptions.Where(l => l.Reverse).ToArray();
                var split        = value.Split('|');
                for (int i = 0; i < split.Length; i++)
                {
                    if (i < forwardLanes.Length)
                    {
                        foreach (var val in split[i].Split(';'))
                        {
                            if (process(val, out parsedValue))
                            {
                                setter(forwardLanes[i], i, parsedValue);
                            }
                        }
                    }
                    else
                    {
                        // something wrong here
                    }
                }
            }
        }