Exemple #1
0
        /// <summary>
        /// Gets a custom factor for the given tags.
        /// </summary>
        private static Func <IAttributeCollection, Factor> InternalGetFactor(Bicycle bicycle)
        {
            // adjusts to a hypothetical speed indicating preference.

            var getFactorDefault = bicycle.GetGetFactor();
            var getSpeedDefault  = bicycle.GetGetSpeed();

            return((tags) =>
            {
                var speed = getSpeedDefault(tags);
                if (speed.Value == 0)
                {
                    return new Itinero.Profiles.Factor()
                    {
                        Value = 0,
                        Direction = 0
                    };
                }

                string cycleway;
                if (tags.TryGetValue("cycleway", out cycleway))
                {
                    speed.Value = speed.Value * HIGHEST_PREFER_FACTOR;
                    return new Factor()
                    {
                        Value = 1.0f / speed.Value,
                        Direction = speed.Direction
                    };
                }

                string highwayType;
                if (tags.TryGetValue("highway", out highwayType))
                {
                    switch (highwayType)
                    {
                    case "trunk":
                    case "trunk_link":
                    case "primary":
                    case "primary_link":
                    case "secondary":
                    case "secondary_link":
                        speed.Value = speed.Value * HIGHEST_AVOID_FACTOR;
                        break;

                    case "tertiary":
                    case "tertiary_link":
                        speed.Value = speed.Value * AVOID_FACTOR;
                        break;

                    case "residential":
                        break;

                    case "path":
                    case "cycleway":
                        speed.Value = speed.Value * HIGHEST_PREFER_FACTOR;
                        break;

                    case "footway":
                    case "pedestrian":
                    case "steps":
                        speed.Value = speed.Value * PREFER_FACTOR;
                        break;
                    }
                }
                return new Factor()
                {
                    Value = 1.0f / speed.Value,
                    Direction = speed.Direction
                };
            });
        }
        private static Func <TagsCollectionBase, Factor> InternalGetFactor(Bicycle bicycle)
        {
            bicycle.GetGetFactor();
            Func <TagsCollectionBase, Speed> getSpeedDefault = bicycle.GetGetSpeed();

            return((Func <TagsCollectionBase, Factor>)(tags =>
            {
                Speed speed = getSpeedDefault(tags);
                if ((double)speed.Value == 0.0)
                {
                    return new Factor()
                    {
                        Value = 0.0f,
                        Direction = 0
                    }
                }
                ;
                string empty = string.Empty;
                foreach (Tag tag in tags)
                {
                    if (tag.Key.StartsWith("cyclenetwork"))
                    {
                        speed.Value = speed.Value * 40f;
                        Factor factor = new Factor();
                        factor.Value = 1f / speed.Value;
                        factor.Direction = speed.Direction;
                        return factor;
                    }
                    if (tag.Key == "highway")
                    {
                        empty = tag.Value;
                    }
                }
                if (!string.IsNullOrWhiteSpace(empty))
                {
                    long stringHash = empty.GetHashCode();

                    if (stringHash <= 1266453457U)
                    {
                        if (stringHash <= 410259268U)
                        {
                            if ((int)stringHash != 4126140)
                            {
                                if ((int)stringHash != 155541048)
                                {
                                    if ((int)stringHash != 410259268 || !(empty == "tertiary_link"))
                                    {
                                        goto label_44;
                                    }
                                    else
                                    {
                                        goto label_41;
                                    }
                                }
                                else if (empty == "footway")
                                {
                                    goto label_43;
                                }
                                else
                                {
                                    goto label_44;
                                }
                            }
                            else if (empty == "pedestrian")
                            {
                                goto label_43;
                            }
                            else
                            {
                                goto label_44;
                            }
                        }
                        else if (stringHash <= 841786498U)
                        {
                            if ((int)stringHash != 741716276)
                            {
                                if ((int)stringHash != 841786498 || !(empty == "secondary_link"))
                                {
                                    goto label_44;
                                }
                            }
                            else if (empty == "steps")
                            {
                                goto label_43;
                            }
                            else
                            {
                                goto label_44;
                            }
                        }
                        else if ((int)stringHash != 908164533)
                        {
                            if ((int)stringHash != 1266453457 || !(empty == "secondary"))
                            {
                                goto label_44;
                            }
                        }
                        else if (empty == "residential")
                        {
                            speed.Value = speed.Value * 1.1f;
                            goto label_44;
                        }
                        else
                        {
                            goto label_44;
                        }
                    }
                    else if (stringHash <= 3045585386U)
                    {
                        if ((int)stringHash != 1512988633)
                        {
                            if ((int)stringHash != -2071507658)
                            {
                                if ((int)stringHash != -1249381910 || !(empty == "primary_link"))
                                {
                                    goto label_44;
                                }
                            }
                            else if (empty == "path")
                            {
                                goto label_43;
                            }
                            else
                            {
                                goto label_44;
                            }
                        }
                        else if (!(empty == "primary"))
                        {
                            goto label_44;
                        }
                    }
                    else if (stringHash <= 3713953405U)
                    {
                        if ((int)stringHash != -700661456)
                        {
                            if ((int)stringHash != -581013891 || !(empty == "trunk"))
                            {
                                goto label_44;
                            }
                        }
                        else if (empty == "cycleway")
                        {
                            goto label_43;
                        }
                        else
                        {
                            goto label_44;
                        }
                    }
                    else if ((int)stringHash != -424251197)
                    {
                        if ((int)stringHash != -37246338 || !(empty == "trunk_link"))
                        {
                            goto label_44;
                        }
                    }
                    else if (empty == "tertiary")
                    {
                        goto label_41;
                    }
                    else
                    {
                        goto label_44;
                    }
                    speed.Value = speed.Value * 0.8f;
                    goto label_44;
label_41:
                    speed.Value = speed.Value * 0.9f;
                    goto label_44;
label_43:
                    speed.Value = speed.Value * 1.2f;
                }
label_44:
                return new Factor()
                {
                    Value = 1f / speed.Value,
                    Direction = speed.Direction
                };
            }));
        }
Exemple #3
0
        private static Func <TagsCollectionBase, Factor> InternalGetFactor(Bicycle bicycle)
        {
            bicycle.GetGetFactor();
            Func <TagsCollectionBase, Speed> getSpeedDefault = bicycle.GetGetSpeed();

            return((Func <TagsCollectionBase, Factor>)(tags =>
            {
                Speed speed = getSpeedDefault(tags);
                if ((double)speed.Value == 0.0)
                {
                    return new Factor()
                    {
                        Value = 0.0f,
                        Direction = 0
                    }
                }
                ;
                string s;
                if (tags.TryGetValue("highway", out s))
                {
                    long stringHash = s.GetHashCode();

                    if (stringHash <= 1266453457U)
                    {
                        if (stringHash <= 410259268U)
                        {
                            if ((int)stringHash != 4126140)
                            {
                                if ((int)stringHash != 155541048)
                                {
                                    if ((int)stringHash != 410259268 || !(s == "tertiary_link"))
                                    {
                                        goto label_34;
                                    }
                                    else
                                    {
                                        goto label_31;
                                    }
                                }
                                else if (s == "footway")
                                {
                                    goto label_33;
                                }
                                else
                                {
                                    goto label_34;
                                }
                            }
                            else if (s == "pedestrian")
                            {
                                goto label_33;
                            }
                            else
                            {
                                goto label_34;
                            }
                        }
                        else if (stringHash <= 841786498U)
                        {
                            if ((int)stringHash != 741716276)
                            {
                                if ((int)stringHash != 841786498 || !(s == "secondary_link"))
                                {
                                    goto label_34;
                                }
                            }
                            else if (s == "steps")
                            {
                                goto label_33;
                            }
                            else
                            {
                                goto label_34;
                            }
                        }
                        else if ((int)stringHash != 908164533)
                        {
                            if ((int)stringHash != 1266453457 || !(s == "secondary"))
                            {
                                goto label_34;
                            }
                        }
                        else if (s == "residential")
                        {
                            speed.Value = speed.Value * 1.1f;
                            goto label_34;
                        }
                        else
                        {
                            goto label_34;
                        }
                    }
                    else if (stringHash <= 3045585386U)
                    {
                        if ((int)stringHash != 1512988633)
                        {
                            if ((int)stringHash != -2071507658)
                            {
                                if ((int)stringHash != -1249381910 || !(s == "primary_link"))
                                {
                                    goto label_34;
                                }
                            }
                            else if (s == "path")
                            {
                                goto label_33;
                            }
                            else
                            {
                                goto label_34;
                            }
                        }
                        else if (!(s == "primary"))
                        {
                            goto label_34;
                        }
                    }
                    else if (stringHash <= 3713953405U)
                    {
                        if ((int)stringHash != -700661456)
                        {
                            if ((int)stringHash != -581013891 || !(s == "trunk"))
                            {
                                goto label_34;
                            }
                        }
                        else if (s == "cycleway")
                        {
                            goto label_33;
                        }
                        else
                        {
                            goto label_34;
                        }
                    }
                    else if ((int)stringHash != -424251197)
                    {
                        if ((int)stringHash != -37246338 || !(s == "trunk_link"))
                        {
                            goto label_34;
                        }
                    }
                    else if (s == "tertiary")
                    {
                        goto label_31;
                    }
                    else
                    {
                        goto label_34;
                    }
                    speed.Value = speed.Value * 0.8f;
                    goto label_34;
label_31:
                    speed.Value = speed.Value * 0.9f;
                    goto label_34;
label_33:
                    speed.Value = speed.Value * 1.2f;
                }
label_34:
                return new Factor()
                {
                    Value = 1f / speed.Value,
                    Direction = speed.Direction
                };
            }));
        }
Exemple #4
0
        /// <summary>
        /// Gets a custom factor for the given tags.
        /// </summary>
        private static Func <IAttributeCollection, Factor> InternalGetFactor(Bicycle bicycle)
        {
            // adjusts to a hypothetical speed indicating preference.

            var getFactorDefault = bicycle.GetGetFactor();
            var getSpeedDefault  = bicycle.GetGetSpeed();

            return((tags) =>
            {
                var speed = getSpeedDefault(tags);
                if (speed.Value == 0)
                {
                    return new Factor()
                    {
                        Value = 0,
                        Direction = 0
                    };
                }

                var highwayType = string.Empty;
                foreach (var tag in tags)
                {
                    if (tag.Key.StartsWith("cyclenetwork"))
                    { // use for all cycle networks the best factor.
                        // THIS IS THE PLACE TO IMPLEMENT NETWORK-SPECIFIC WEIGHTS.
                        speed.Value = speed.Value * CYCLE_NETWORK_PREFER_FACTOR;
                        return new Factor()
                        {
                            Value = 1.0f / speed.Value,
                            Direction = speed.Direction
                        };
                    }

                    if (tag.Key == "highway")
                    {
                        highwayType = tag.Value;
                    }
                }

                if (!string.IsNullOrWhiteSpace(highwayType))
                {
                    switch (highwayType)
                    {
                    case "trunk":
                    case "trunk_link":
                    case "primary":
                    case "primary_link":
                    case "secondary":
                    case "secondary_link":
                        speed.Value = speed.Value * HIGHEST_AVOID_FACTOR;
                        break;

                    case "tertiary":
                    case "tertiary_link":
                        speed.Value = speed.Value * AVOID_FACTOR;
                        break;

                    case "residential":
                        speed.Value = speed.Value * PREFER_FACTOR;
                        break;

                    case "path":
                    case "footway":
                    case "cycleway":
                    case "pedestrian":
                    case "steps":
                        speed.Value = speed.Value * HIGHEST_PREFER_FACTOR;
                        break;
                    }
                }
                return new Factor()
                {
                    Value = 1.0f / speed.Value,
                    Direction = speed.Direction
                };
            });
        }