예제 #1
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 IAttributeCollection 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));
        }
예제 #2
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 IAttributeCollection 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));
        }
예제 #3
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 IAttributeCollection 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));
        }
예제 #4
0
        /// <summary>
        /// Tries to parse a speed value from a given tag-value.
        /// </summary>
        public static bool TryParseSpeed(string s, out float kmPerHour)
        {
            kmPerHour = float.MaxValue;

            if (string.IsNullOrWhiteSpace(s))
            {
                return(false);
            }

            if (s[0] != '0' && s[0] != '1' && s[0] != '2' && s[0] != '3' && s[0] != '4' &&
                s[0] != '5' && s[0] != '6' && s[0] != '7' && s[0] != '8' && s[0] != '9')
            { // performance improvement, quick negative answer.
                return(false);
            }

            if (s.Contains(","))
            { // refuse comma as a decimal seperator or anywhere else in the number.
                return(false);
            }

            // try regular speed: convention in OSM is km/h in this case.
            if (float.TryParse(s, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out kmPerHour))
            {
                return(true);
            }

            // try km/h
            if (IAttributeCollectionExtension.TryParseKilometerPerHour(s, out kmPerHour))
            {
                return(true);
            }

            // try mph.
            float milesPerHour;

            if (IAttributeCollectionExtension.TryParseMilesPerHour(s, out milesPerHour))
            {
                kmPerHour = milesPerHour * 1.60934f;
                return(true);
            }

            // try knots.
            float resultKnots;

            if (IAttributeCollectionExtension.TryParseKnots(s, out resultKnots))
            {
                kmPerHour = resultKnots * 1.85200f;
                return(true);
            }

            return(false);
        }
예제 #5
0
        /// <summary>
        /// Searches for a max height tag and returns the associated value.
        ///
        /// http://wiki.openstreetmap.org/wiki/Maxheight
        /// </summary>
        public static bool TryGetMaxHeight(this IReadonlyAttributeCollection tags, out float meter)
        {
            meter = float.MaxValue;

            string tagValue;

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

            return(IAttributeCollectionExtension.TryParseLength(tagValue, out meter));
        }