/// <summary>
 /// Returns true if the given attribute is found.
 /// </summary>
 public static bool Contains(this IReadonlyAttributeCollection attributes, string key, string value)
 {
     if (!attributes.TryGetValue(key, out var foundValue))
     {
         return(false);
     }
     return(value == foundValue);
 }
Пример #2
0
        /// <summary>
        /// Tries to get a single value for the given key.
        /// </summary>
        public static bool TryGetSingle(this IReadonlyAttributeCollection attributes, string key, out float value)
        {
            string stringValue;

            if (!attributes.TryGetValue(key, out stringValue))
            {
                value = 0;
                return(false);
            }
            return(float.TryParse(stringValue, NumberStyles.Any, CultureInfo.InvariantCulture, out value));
        }
Пример #3
0
        /// <summary>
        /// Returns true if the given tags key has an associated value that can be interpreted as false.
        /// </summary>
        public static bool IsFalse(this IReadonlyAttributeCollection tags, string tagKey)
        {
            if (tags == null || string.IsNullOrWhiteSpace(tagKey))
            {
                return(false);
            }
            string tagValue;

            return(tags.TryGetValue(tagKey, out tagValue) &&
                   BooleanFalseValues.Contains(tagValue.ToLowerInvariant()));
        }
Пример #4
0
        /// <summary>
        /// Searches for a max axle load tag and returns the associated value.
        ///
        /// http://wiki.openstreetmap.org/wiki/Key:maxaxleload
        /// </summary>
        public static bool TryGetMaxAxleLoad(this IReadonlyAttributeCollection tags, out float kilogram)
        {
            kilogram = float.MaxValue;
            string tagValue;

            if (tags == null || !tags.TryGetValue("maxaxleload", out tagValue) || string.IsNullOrWhiteSpace(tagValue))
            {
                return(false);
            }
            return(IAttributeCollectionExtension.TryParseWeight(tagValue, out kilogram));
        }
Пример #5
0
        /// <summary>
        /// Searches for a maxspeed tag and returns the associated value.
        ///
        ///  http://wiki.openstreetmap.org/wiki/Key:maxspeed
        /// </summary>
        public static bool TryGetMaxSpeed(this IReadonlyAttributeCollection attributes, out float kmPerHour)
        {
            kmPerHour = float.MaxValue;
            string tagValue;

            if (attributes == null || !attributes.TryGetValue("maxspeed", out tagValue) || string.IsNullOrWhiteSpace(tagValue) ||
                tagValue == "none" || tagValue == "signals" || tagValue == "signs" || tagValue == "no")
            {
                return(false);
            }
            return(IAttributeCollectionExtension.TryParseSpeed(tagValue, out kmPerHour));
        }
Пример #6
0
        /// <summary>
        /// Searches for a max width tag and returns the associated value.
        ///
        /// http://wiki.openstreetmap.org/wiki/Key:maxwidth
        /// </summary>
        /// <param name="attributes">The tags to search.</param>
        /// <param name="meter"></param>
        /// <returns></returns>
        public static bool TryGetMaxWidth(this IReadonlyAttributeCollection attributes, out float meter)
        {
            meter = float.MaxValue;
            string tagValue;

            if (attributes == null || !attributes.TryGetValue("maxwidth", out tagValue) || string.IsNullOrWhiteSpace(tagValue))
            {
                return(false);
            }

            return(IAttributeCollectionExtension.TryParseLength(tagValue, out meter));
        }
Пример #7
0
        /// <summary>
        /// Returns true if the given tags key has an associated value that can be interpreted as true.
        /// </summary>
        public static bool IsTrue(this IReadonlyAttributeCollection tags, string tagKey)
        {
            if (tags == null || string.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()));
        }
Пример #8
0
 /// <summary>
 /// Searches the attributes collection for the access attributes 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 IReadonlyAttributeCollection 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);
 }