예제 #1
0
        internal static FactorAndSpeed FactorAndSpeed(IAttributeCollection attributes,
                                                      Whitelist whitelist)
        {
            if (attributes == null || attributes.Count == 0)
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }

            string highway = null;

            if (attributes.TryGetValue("highway", out highway))
            {
                whitelist.Add("highway");
            }
            string foot = null;

            if (attributes.TryGetValue("foot", out foot))
            {
                if (foot == "no" || foot == "0")
                {
                    return(Itinero.Profiles.FactorAndSpeed.NoFactor);
                }
                whitelist.Add("foot");
            }
            string footway;

            if (attributes.TryGetValue("footway", out footway))
            {
                whitelist.Add("footway");
            }
            var   result    = new FactorAndSpeed();
            var   speed     = 0.0f;
            short direction = 0;
            var   canstop   = true;

            if (String.IsNullOrEmpty(highway))
            {
                if (!String.IsNullOrEmpty(foot))
                {
                    highway = "footway";
                }
                else
                {
                    return(Itinero.Profiles.FactorAndSpeed.NoFactor);
                }
            }
            //get default speed profiles
            var highway_speed = SpeedProfiles.ContainsKey(highway) ? (int?)SpeedProfiles[highway] : null;

            if (highway_speed != null)
            {
                speed     = highway_speed.Value;
                direction = 0;
                canstop   = true;
            }
            else
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }

            if (CanAccess(attributes) == false || speed == 0)
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }

            result.SpeedFactor = 1.0f / (speed / 3.6f); // 1/m/s
            result.Value       = result.SpeedFactor;
            result.Direction   = direction;
            if (!canstop)
            {
                result.Direction += 3;
            }
            return(result);
        }
예제 #2
0
        internal static FactorAndSpeed FactorAndSpeed(IAttributeCollection attributes,
                                                      Whitelist whitelist)
        {
            if (attributes == null || attributes.Count == 0)
            {
                return(Profiles.FactorAndSpeed.NoFactor);
            }
            string highway = null;

            if (attributes.TryGetValue("highway", out highway))
            {
                whitelist.Add("highway");
            }
            var   result    = new FactorAndSpeed();
            var   speed     = 0.0f;
            short direction = 0;
            var   canstop   = true;
            //set highway to ferry when ferry.
            string route = null;

            if (attributes.TryGetValue("route", out route))
            {
                whitelist.Add("route");
            }
            if (route == "ferry")
            {
                highway = "ferry";
            }

            if (String.IsNullOrEmpty(highway))
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }
            //get default speed profiles
            var highway_speed = _speedProfiles.ContainsKey(highway) ? (int?)_speedProfiles[highway] : null;

            if (highway_speed != null)
            {
                speed     = highway_speed.Value;
                direction = 0;
                canstop   = true;
                if (highway == "motorway" ||
                    highway == "motorway_link")
                {
                    canstop = false;
                }
            }
            else
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }

            if (CanAccess(attributes) == false)
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }

            //get maxspeed if any.
            string maxSpeed = null;

            if (attributes.TryGetValue("maxspeed", out maxSpeed))
            {
                whitelist.Add("maxspeed");
                float lspeed;
                if (float.TryParse(maxSpeed, out lspeed))
                {
                    speed = lspeed * 0.75f;
                }
            }

            //get maxweight and maxwidth constraints if any
            var    maxweight       = 0.0f;
            var    maxwidth        = 0.0f;
            string maxWeightString = null;

            if (attributes.TryGetValue("maxweight", out maxWeightString))
            {
                whitelist.Add("maxweight");
                float.TryParse(maxWeightString, out maxweight);
            }

            string maxWidthString = null;

            if (attributes.TryGetValue("maxwidth", out maxWidthString))
            {
                whitelist.Add("maxwidth");
                float.TryParse(maxWidthString, out maxwidth);
            }

            if (maxwidth != 0 || maxweight != 0)
            {
                result.Constraints = new[]
                { maxweight, maxwidth };
            }

            //get directional information
            String junction = null;

            if (attributes.TryGetValue("junction", out junction))
            {
                whitelist.Add("junction");
                if (junction == "roundabout")
                {
                    direction = 1;
                }
            }
            var ldirection = IsOneway(attributes, whitelist, "oneway");

            if (ldirection != null)
            {
                direction = ldirection.Value;
            }
            if (speed == 0)
            {
                return(Itinero.Profiles.FactorAndSpeed.NoFactor);
            }
            result.SpeedFactor = 1.0f / (speed / 3.6f); // 1/m/s
            result.Value       = result.SpeedFactor;
            result.Direction   = direction;
            if (!canstop)
            {
                result.Direction += 3;
            }
            return(result);
        }