コード例 #1
0
        /// <summary>
        /// Splits the given tags into a normalized version, profile tags, and the rest in metatags.
        /// </summary>
        public static bool Normalize(IAttributeCollection tags, IAttributeCollection profileTags, VehicleCache vehicleCache)
        {
            var normalizedTags = new HashSet <string>(new string[] { "highway", "maxspeed", "oneway", "oneway:bicycle",
                                                                     "cycleway", "junction", "access" });

            foreach (var vehicle in vehicleCache.Vehicles)
            {
                foreach (var vehicleType in vehicle.VehicleTypes)
                {
                    normalizedTags.Add(vehicleType);
                }
            }

            string highway;

            if (!tags.TryGetValue("highway", out highway))
            { // there is no highway tag, don't continue the search.
                return(false);
            }

            // add the highway tag.
            profileTags.AddOrReplace("highway", highway);

            // normalize maxspeed tags.
            tags.NormalizeMaxspeed(profileTags);

            // normalize oneway tags.
            tags.NormalizeOneway(profileTags);
            tags.NormalizeOnewayBicycle(profileTags);

            // normalize cyclceway.
            tags.NormalizeCycleway(profileTags);

            // normalize junction=roundabout tag.
            tags.NormalizeJunction(profileTags);

            // normalize access tags.
            foreach (var vehicle in vehicleCache.Vehicles)
            {
                tags.NormalizeAccess(vehicleCache, vehicle, highway, profileTags);
            }

            // add whitelisted tags but only when they haven't been considered for normalization.
            foreach (var vehicle in vehicleCache.Vehicles)
            {
                foreach (var key in vehicle.ProfileWhiteList)
                {
                    var value = string.Empty;
                    if (tags.TryGetValue(key, out value))
                    {
                        if (!normalizedTags.Contains(key))
                        {
                            profileTags.AddOrReplace(key, value);
                        }
                    }
                }
            }

            return(true);
        }
コード例 #2
0
ファイル: Vehicle.cs プロジェクト: ikyaqoob/routing
        /// <summary>
        /// Returns true if the edge is one way forward, false if backward, null if bidirectional.
        /// </summary>
        public virtual bool?IsOneWay(IAttributeCollection tags)
        {
            string oneway;

            if (tags.TryGetValue("oneway", out oneway))
            {
                if (oneway == "yes")
                {
                    return(true);
                }
                else if (oneway == "no")
                { // explicitly tagged as not oneway.
                    return(null);
                }
                return(false);
            }
            string junction;

            if (tags.TryGetValue("junction", out junction))
            {
                if (junction == "roundabout")
                {
                    return(true);
                }
            }
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Returns true if the vehicle is allowed on the way represented by these tags
        /// </summary>
        protected override bool IsVehicleAllowed(IAttributeCollection tags, string highwayType)
        {
            if (!tags.InterpretAccessValues(VehicleTypes, "access"))
            {
                return(false);
            }

            var foot = string.Empty;

            if (tags.TryGetValue("foot", out foot))
            {
                if (foot == "designated")
                {
                    return(true); // designated foot
                }
                if (foot == "yes")
                {
                    return(true); // yes for foot
                }
                if (foot == "no")
                {
                    return(false); // no for foot
                }
            }
            return(AccessibleTags.ContainsKey(highwayType));
        }
コード例 #4
0
ファイル: Bicycle.cs プロジェクト: ikyaqoob/routing
        /// <summary>
        /// Returns true if the vehicle is allowed on the way represented by these tags
        /// </summary>
        protected override bool IsVehicleAllowed(IAttributeCollection tags, string highwayType)
        {
            if (!tags.InterpretAccessValues(VehicleTypes, "access"))
            {
                return(false);
            }

            // do the designated tags.
            var bicycle = string.Empty;

            if (tags.TryGetValue("bicycle", out bicycle))
            {
                if (bicycle == "designated")
                {
                    return(true); // designated bicycle
                }
                if (bicycle == "yes")
                {
                    return(true); // yes for bicycle
                }
                if (bicycle == "no")
                {
                    return(false); //  no for bicycle
                }
            }
            if (highwayType == "steps")
            {
                if (tags.Contains("ramp", "yes"))
                {
                    return(true);
                }
                return(false);
            }
            return(AccessibleTags.ContainsKey(highwayType));
        }
コード例 #5
0
ファイル: Vehicle.cs プロジェクト: ikyaqoob/routing
        /// <summary>
        /// Returns the name of a given edge.
        /// </summary>
        protected virtual string GetName(IAttributeCollection tags)
        {
            string name;

            if (tags.TryGetValue("name", out name))
            {
                return(name);
            }
            if (tags.TryGetValue("Name", out name))
            {
                return(name);
            }
            if (tags.TryGetValue("NAME", out name))
            {
                return(name);
            }
            return(string.Empty);
        }
コード例 #6
0
ファイル: Vehicle.cs プロジェクト: ikyaqoob/routing
        /// <summary>
        /// Returns the name of a given way.
        /// </summary>
        private string GetName(IAttributeCollection tags)
        {
            var name = string.Empty;

            if (!tags.TryGetValue("name", out name))
            {
                return(string.Empty);
            }
            return(name);
        }
コード例 #7
0
ファイル: Vehicle.cs プロジェクト: ikyaqoob/routing
        /// <summary>
        /// Returns true if an edge with the given profile can be use for an end- or startpoint.
        /// </summary>
        public virtual bool CanStopOn(IAttributeCollection tags)
        {
            string highway;

            if (tags != null && tags.TryGetValue("highway", out highway))
            {
                return(!string.IsNullOrWhiteSpace(highway));
            }
            return(false);
        }
コード例 #8
0
        /// <summary>
        /// Returns true if the given attribute is found.
        /// </summary>
        public static bool Contains(this IAttributeCollection attributes, string key, string value)
        {
            string foundValue;

            if (!attributes.TryGetValue(key, out foundValue))
            {
                return(false);
            }
            return(value == foundValue);
        }
コード例 #9
0
        /// <summary>
        /// Tries to get a single value for the given key.
        /// </summary>
        public static bool TryGetSingle(this IAttributeCollection 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));
        }
コード例 #10
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 IAttributeCollection tags, string tagKey)
        {
            if (tags == null || string.IsNullOrWhiteSpace(tagKey))
            {
                return(false);
            }
            string tagValue;

            return(tags.TryGetValue(tagKey, out tagValue) &&
                   BooleanFalseValues.Contains(tagValue.ToLowerInvariant()));
        }
コード例 #11
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));
        }
コード例 #12
0
ファイル: Bicycle.cs プロジェクト: ikyaqoob/routing
        /// <summary>
        /// Returns true if the edge is one way forward, false if backward, null if bidirectional.
        /// </summary>
        public override bool?IsOneWay(IAttributeCollection tags)
        {
            string oneway;

            if (tags.TryGetValue("oneway:bicycle", out oneway))
            {
                if (oneway == "yes")
                {
                    return(true);
                }
                else if (oneway == "no")
                {
                    return(null);
                }
                return(false);
            }

            if (tags.TryGetValue("oneway", out oneway))
            {
                if (oneway == "yes")
                {
                    return(true);
                }
                else if (oneway == "no")
                {
                    return(null);
                }
                return(false);
            }

            string junction;

            if (tags.TryGetValue("junction", out junction))
            {
                if (junction == "roundabout")
                {
                    return(true);
                }
            }
            return(null);
        }
コード例 #13
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));
        }
コード例 #14
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));
        }
コード例 #15
0
        /// <summary>
        /// Normalizes the junction tag.
        /// </summary>
        /// <returns></returns>
        public static void NormalizeJunction(this IAttributeCollection tags, IAttributeCollection profileTags)
        {
            string junction;

            if (!tags.TryGetValue("junction", out junction))
            { // nothing to normalize.
                return;
            }
            if (junction == "roundabout")
            {
                profileTags.AddOrReplace("junction", "roundabout");
            }
        }
コード例 #16
0
        //interprets access tags
        private static bool?CanAccess(IAttributeCollection attributes)
        {
            bool?  last_access = null;
            string accessValue = null;

            if (attributes.TryGetValue("access", out accessValue) &&
                AccessValues.ContainsKey(accessValue))
            {
                var access = AccessValues[accessValue];
                last_access = access;
            }
            foreach (var vtype in Vehicles)
            {
                string accessKey = null;
                if (attributes.TryGetValue(vtype, out accessKey) && AccessValues.ContainsKey(accessKey))
                {
                    var access = AccessValues[accessKey];
                    last_access = access;
                }
            }
            return(last_access);
        }
コード例 #17
0
        /// <summary>
        /// Normalizes the oneway bicycle tag.
        /// </summary>
        public static void NormalizeOnewayBicycle(this IAttributeCollection tags, IAttributeCollection profileTags)
        {
            string oneway;

            if (!tags.TryGetValue("oneway:bicycle", out oneway))
            { // nothing to normalize.
                return;
            }
            if (oneway == "no")
            {
                profileTags.AddOrReplace("oneway:bicycle", "no");
            }
        }
コード例 #18
0
ファイル: VehicleExtensions.cs プロジェクト: ikyaqoob/routing
        /// <summary>
        /// Interprets a given access tag value.
        /// </summary>
        public static bool?InterpretAccessValue(this IAttributeCollection tags, string key)
        {
            string accessValue;

            if (tags.TryGetValue(key, out accessValue))
            {
                bool?value;
                if (VehicleExtensions.GetAccessValues().TryGetValue(accessValue, out value))
                {
                    return(value);
                }
            }
            return(null);
        }
コード例 #19
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 IAttributeCollection 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()));
        }
コード例 #20
0
ファイル: Vehicle.cs プロジェクト: amseet/Orion
        /// <summary>
        /// Interprets a given access tag value.
        /// </summary>
        public static bool?InterpretAccessValue(IAttributeCollection attributes, string key)
        {
            string accessValue;

            if (attributes.TryGetValue(key, out accessValue))
            {
                bool?value;
                if (Vehicle.GetAccessValues().TryGetValue(accessValue, out value))
                {
                    return(value);
                }
            }
            return(null);
        }
コード例 #21
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 IAttributeCollection 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);
 }
コード例 #22
0
        /// <summary>
        /// Returns true if the edge is oneway forward, false if backward, null if bidirectional.
        /// </summary>
        protected override bool?IsOneWay(IAttributeCollection tags)
        {
            string oneway;

            if (tags.TryGetValue("RIJRICHTNG", out oneway))
            {
                if (oneway == "H")
                {
                    return(true);
                }
                else if (oneway == "T")
                {
                    return(false);
                }
            }
            return(null);
        }
コード例 #23
0
ファイル: Car.cs プロジェクト: ikyaqoob/routing
        /// <summary>
        /// Returns the probable speed.
        /// </summary>
        public override float ProbableSpeed(IAttributeCollection tags)
        {
            string highwayType;

            if (tags.TryGetValue("highway", out highwayType))
            {
                switch (highwayType)
                {
                case "services":
                case "proposed":
                case "cycleway":
                case "pedestrian":
                case "steps":
                case "path":
                case "footway":
                case "living_street":
                    return(5);

                case "service":
                case "track":
                case "road":
                    return(30);

                case "residential":
                case "unclassified":
                    return(50);

                case "motorway":
                case "motorway_link":
                    return(120);

                case "trunk":
                case "trunk_link":
                case "primary":
                case "primary_link":
                    return(90);

                default:
                    return(70);
                }
            }
            return(0);
        }
コード例 #24
0
        /// <summary>
        /// Normalize the cycleway tag.
        /// </summary>
        public static void NormalizeCycleway(this IAttributeCollection tags, IAttributeCollection profileTags)
        {
            string cycleway;

            if (!tags.TryGetValue("cycleway", out cycleway))
            { // nothing to normalize.
                return;
            }
            if (cycleway == "cyclestreet")
            {
                profileTags.AddOrReplace("cycleway", "cyclestreet");
            }
            else if (cycleway == "lane")
            {
                profileTags.AddOrReplace("cycleway", "lane");
            }

            // TODO: add the unidirectional cycleway stuff. WARNING: direction of 'left' and 'right' depends on country.
        }
コード例 #25
0
        /// <summary>
        /// Normalizes the ramp tag.
        /// </summary>
        public static void NormalizeRamp(this IAttributeCollection tags, IAttributeCollection profileTags, bool defaultAccess)
        {
            string ramp;

            if (!tags.TryGetValue("ramp", out ramp))
            { // nothing to normalize.
                return;
            }
            bool?defaultAccessFound;

            if (!RampValues.TryGetValue(ramp, out defaultAccessFound))
            { // invalid value.
                return;
            }

            if (defaultAccess != defaultAccessFound)
            {
                profileTags.AddOrReplace("ramp", ramp);
            }
        }
コード例 #26
0
        private static short?IsOneway(IAttributeCollection attributes, Whitelist whitelist, String name)
        {
            String oneway = null;

            if (attributes.TryGetValue(name, out oneway))
            {
                whitelist.Add(name);
                if (!String.IsNullOrEmpty(oneway))
                {
                    if (oneway == "yes" ||
                        oneway == "true" ||
                        oneway == "1")
                    {
                        return(1);
                    }
                    if (oneway == "-1")
                    {
                        return(2);
                    }
                }
            }
            return(null);
        }
コード例 #27
0
        /// <summary>
        /// Returns the probable speed.
        /// </summary>
        public override float ProbableSpeed(IAttributeCollection tags)
        {
            string highwayType;

            if (tags.TryGetValue("BAANSUBSRT", out highwayType))
            {
                switch (highwayType)
                {
                case "BVD":
                    return(50);

                case "AF":
                case "OP":
                    return(70);

                case "HR":
                    return(120);

                default:
                    return(70);
                }
            }
            return(0);
        }
コード例 #28
0
        /// <summary>
        /// Normalizes the oneway tag.
        /// </summary>
        public static void NormalizeOneway(this IAttributeCollection tags, IAttributeCollection profileTags)
        {
            string oneway;

            if (!tags.TryGetValue("oneway", out oneway))
            { // nothing to normalize.
                return;
            }
            bool defaultOnewayFound;

            if (!OnewayValues.TryGetValue(oneway, out defaultOnewayFound))
            { // invalid value.
                return;
            }

            if (defaultOnewayFound)
            {
                profileTags.AddOrReplace("oneway", "yes");
            }
            else
            {
                profileTags.AddOrReplace("oneway", "-1");
            }
        }
コード例 #29
0
        /// <summary>
        /// Normalizes maxspeed.
        /// </summary>
        public static void NormalizeMaxspeed(this IAttributeCollection tags, IAttributeCollection profileTags)
        {
            string maxspeed;

            if (!tags.TryGetValue("maxspeed", out maxspeed))
            { // nothing to normalize.
                return;
            }
            int maxSpeedValue;

            if (int.TryParse(maxspeed, out maxSpeedValue) &&
                maxSpeedValue > 0 && maxSpeedValue <= 200)
            {
                profileTags.AddOrReplace("maxspeed", maxspeed);
            }
            else if (maxspeed.EndsWith("mph"))
            {
                if (int.TryParse(maxspeed.Substring(0, maxspeed.Length - 4), out maxSpeedValue) &&
                    maxSpeedValue > 0 && maxSpeedValue <= 150)
                {
                    profileTags.AddOrReplace("maxspeed", maxspeed);
                }
            }
        }
コード例 #30
0
ファイル: Vehicle.cs プロジェクト: ikyaqoob/routing
 /// <summary>
 /// Trys to return the highwaytype from the tags
 /// </summary>
 protected bool TryGetHighwayType(IAttributeCollection tags, out string highwayType)
 {
     highwayType = string.Empty;
     return(tags != null && tags.TryGetValue("highway", out highwayType));
 }