/// <summary> /// Returns true if the given tags collection contains tags that could represents an area. /// </summary> /// <param name="tags"></param> /// <returns></returns> public override bool IsPotentiallyArea(TagsCollection tags) { if (tags == null || tags.Count == 0) { return(false); } // no tags, assume no area. bool isArea = false; if ((tags.ContainsKey("building") && !tags.IsFalse("building")) || (tags.ContainsKey("landuse") && !tags.IsFalse("landuse")) || (tags.ContainsKey("amenity") && !tags.IsFalse("amenity")) || (tags.ContainsKey("harbour") && !tags.IsFalse("harbour")) || (tags.ContainsKey("historic") && !tags.IsFalse("historic")) || (tags.ContainsKey("leisure") && !tags.IsFalse("leisure")) || (tags.ContainsKey("man_made") && !tags.IsFalse("man_made")) || (tags.ContainsKey("military") && !tags.IsFalse("military")) || (tags.ContainsKey("natural") && !tags.IsFalse("natural")) || (tags.ContainsKey("office") && !tags.IsFalse("office")) || (tags.ContainsKey("place") && !tags.IsFalse("place")) || (tags.ContainsKey("power") && !tags.IsFalse("power")) || (tags.ContainsKey("public_transport") && !tags.IsFalse("public_transport")) || (tags.ContainsKey("shop") && !tags.IsFalse("shop")) || (tags.ContainsKey("sport") && !tags.IsFalse("sport")) || (tags.ContainsKey("tourism") && !tags.IsFalse("tourism")) || (tags.ContainsKey("waterway") && !tags.IsFalse("waterway")) || (tags.ContainsKey("wetland") && !tags.IsFalse("wetland")) || (tags.ContainsKey("water") && !tags.IsFalse("water")) || (tags.ContainsKey("aeroway") && !tags.IsFalse("aeroway"))) { // these tags usually indicate an area. isArea = true; } string typeValue; if (tags.TryGetValue("type", out typeValue)) { // there is a type in this relation. if (typeValue == "multipolygon") { // this relation is a multipolygon. isArea = true; } else if (typeValue == "boundary") { // this relation is a boundary. isArea = true; } } if (tags.IsTrue("area")) { // explicitly indicated that this is an area. isArea = true; } else if (tags.IsFalse("area")) { // explicitly indicated that this is not an area. isArea = false; } return(isArea); }
public static void NormalizeJunction(this TagsCollection tags, TagsCollection profileTags, TagsCollection metaTags) { string str; if (!tags.TryGetValue("junction", out str) || !(str == "roundabout")) { return; } profileTags.Add("junction", "roundabout"); }
public static void NormalizeOnewayBicycle(this TagsCollection tags, TagsCollection profileTags, TagsCollection metaTags) { string str; if (!tags.TryGetValue("oneway:bicycle", out str) || !(str == "no")) { return; } profileTags.Add("oneway:bicycle", "no"); }
/// <summary> /// Searches for a max width tag and returns the associated value. /// /// http://wiki.openstreetmap.org/wiki/Key:maxwidth /// </summary> /// <param name="tags">The tags to search.</param> /// <param name="result"></param> /// <returns></returns> public static bool TryGetMaxWidth(this TagsCollection tags, out Meter result) { result = double.MaxValue; string tagValue; if (tags == null || !tags.TryGetValue("maxwidth", out tagValue) || string.IsNullOrWhiteSpace(tagValue)) { return(false); } return(TagExtensions.TryParseLength(tagValue, out result)); }
/// <summary> /// Searches for a max axle load tag and returns the associated value. /// /// http://wiki.openstreetmap.org/wiki/Key:maxaxleload /// </summary> /// <param name="tags">The tags to search.</param> /// <param name="result"></param> /// <returns></returns> public static bool TryGetMaxAxleLoad(this TagsCollection tags, out Kilogram result) { result = double.MaxValue; string tagValue; if (tags == null || !tags.TryGetValue("maxaxleload", out tagValue) || string.IsNullOrWhiteSpace(tagValue)) { return(false); } return(TagExtensions.TryParseWeight(tagValue, out result)); }
/// <summary> /// Returns true if the given tags key has an associated value that can be interpreted as false. /// </summary> /// <param name="tags"></param> /// <param name="tagKey"></param> /// <returns></returns> public static bool IsFalse(this TagsCollection tags, string tagKey) { if (tags == null || string.IsNullOrWhiteSpace(tagKey)) { return(false); } string tagValue; return(tags.TryGetValue(tagKey, out tagValue) && BooleanFalseValues.Contains(tagValue.ToLowerInvariant())); }
/// <summary> /// Returns true if the edge with the given tags is only accessible locally. /// </summary> /// <param name="tags"></param> /// <returns></returns> public bool IsOnlyLocalAccessible(TagsCollection tags) { string tag; if (tags.TryGetValue("highway", out tag)) { if (tag == "service") { return(true); } } if (tags.TryGetValue("access", out tag)) { if (tag == "private" || tag == "official") { return(true); } } return(false); }
/// <summary> /// Searches for a maxspeed tag and returns the associated value. /// /// http://wiki.openstreetmap.org/wiki/Key:maxspeed /// </summary> /// <param name="tags">The tags to search.</param> /// <param name="result"></param> /// <returns></returns> public static bool TryGetMaxSpeed(this TagsCollection tags, out KilometerPerHour result) { result = double.MaxValue; string tagValue; if (tags == null || !tags.TryGetValue("maxspeed", out tagValue) || string.IsNullOrWhiteSpace(tagValue)) { return(false); } return(TagExtensions.TryParseSpeed(tagValue, out result)); }
/// <summary> /// Searches for a maxweight tag and returns the associated value. /// /// http://wiki.openstreetmap.org/wiki/Key:maxweight /// </summary> /// <param name="tags">The tags to search.</param> /// <param name="result"></param> /// <returns></returns> public static bool TryGetMaxWeight(this TagsCollection tags, out double result) { result = double.MaxValue; string tagValue; if (tags == null || !tags.TryGetValue("maxweight", out tagValue) || string.IsNullOrWhiteSpace(tagValue)) { return(false); } return(TryParseWeight(tagValue, out result)); }
/// <summary> /// Returns true if the edge is one way forward, false if backward, null if bidirectional. /// </summary> /// <param name="tags"></param> /// <returns></returns> public virtual bool?IsOneWay(TagsCollection tags) { string oneway; if (tags.TryGetValue("oneway", out oneway)) { if (oneway == "yes") { return(true); } return(false); } string junction; if (tags.TryGetValue("junction", out junction)) { if (junction == "roundabout") { return(true); } } return(null); }
/// <summary> /// Returns true if the edge is one way forward, false if backward, null if bidirectional. /// </summary> /// <param name="tags"></param> /// <returns></returns> public virtual bool?IsOneWay(TagsCollection tags) { string oneway; if (tags.TryGetValue("oneway", out oneway)) { if (oneway == "yes") { return(true); } return(false); } return(null); }
//private const string REGEX_UNIT_KILOMETERS_PER_HOUR = @"\s*(kmh|km/h|kph)?\s*"; //private const string REGEX_UNIT_MILES_PER_HOUR = @"\s*(mph)?\s*"; /// <summary> /// Returns true if the given tags key has an associated value that can be interpreted as true. /// </summary> /// <param name="tags"></param> /// <param name="tagKey"></param> /// <returns></returns> public static bool IsTrue(this TagsCollection 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())); }
/// <summary> /// Searches for the tags collection for the <c>Access</c>-Tags 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 TagsCollection 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); }
public static void NormalizeOneway(this TagsCollection tags, TagsCollection profileTags, TagsCollection metaTags) { string key; bool flag; if (!tags.TryGetValue("oneway", out key) || !OsmRoutingTagNormalizer.OnewayValues.TryGetValue(key, out flag)) { return; } if (flag) { profileTags.Add("oneway", "yes"); } else { profileTags.Add("oneway", "-1"); } }
public static void NormalizeRamp(this TagsCollection tags, TagsCollection profileTags, TagsCollection metaTags, bool defaultAccess) { string key; bool? nullable1; if (!tags.TryGetValue("ramp", out key) || !OsmRoutingTagNormalizer.RampValues.TryGetValue(key, out nullable1)) { return; } int num1 = defaultAccess ? 1 : 0; bool?nullable2 = nullable1; int num2 = nullable2.GetValueOrDefault() ? 1 : 0; if ((num1 == num2 ? (!nullable2.HasValue ? 1 : 0) : 1) == 0) { return; } profileTags.Add("ramp", key); }
/// <summary> /// Returns true if the edge is a suitable candidate as a target for a point to be resolved on. /// </summary> /// <param name="vehicle"></param> /// <param name="pointTags"></param> /// <param name="edgeTags"></param> /// <returns></returns> public bool MatchWithEdge(Vehicle vehicle, TagsCollection pointTags, TagsCollection edgeTags) { if (pointTags == null || pointTags.Count == 0) { // when the point has no tags it has no requirements. return(true); } if (edgeTags == null || edgeTags.Count == 0) { // when the edge has no tags, no way to verify. return(false); } string pointName, edgeName; if (pointTags.TryGetValue("name", out pointName) && edgeTags.TryGetValue("name", out edgeName)) { // both have names. return(pointName.LevenshteinMatch(edgeName, 90)); } return(false); }
public static void NormalizeMaxspeed(this TagsCollection tags, TagsCollection profileTags, TagsCollection metaTags) { string s; if (!tags.TryGetValue("maxspeed", out s)) { return; } int result; if (int.TryParse(s, out result) && result > 0 && result <= 200) { profileTags.Add("maxspeed", s); } else { if (!s.EndsWith("mph") || !int.TryParse(s.Substring(0, s.Length - 4), out result) || (result <= 0 || result > 150)) { return; } profileTags.Add("maxspeed", s); } }
/// <summary> /// Returns true if the edge with the given properties represents a roundabout. /// </summary> /// <param name="tags"></param> /// <returns></returns> public bool IsRoundabout(TagsCollection tags) { string junction; return(tags != null && tags.TryGetValue("junction", out junction) && junction == "roundabout"); }
/// <summary> /// Interpreters the given expression. /// </summary> /// <param name="function"></param> /// <param name="tags"></param> /// <returns></returns> private string Interpreter(string expression, TagsCollection tags) { // test for one of the tokens. if (expression.StartsWith(TAG_TOKEN)) { // get the tag value. string[] args = this.ParseFunction(expression); if (args.Length != 1) { throw new EvalInterpreterException("Invalid argument count: {0}", expression); } string tagValue; if (tags.TryGetValue(args[0], out tagValue)) { // the tag value. tagValue = null; } return(tagValue); } else if (expression.StartsWith(PROP_TOKEN)) { // not supported for now: mapcss interpretation code needs to change first to keep a list // of current properties. return(null); // return 'none'. } else if (expression.StartsWith(COND_TOKEN)) { // evaluate expression and decide on the next expression. string[] args = this.ParseFunction(expression); if (args.Length != 3) { throw new EvalInterpreterException("Invalid argument count: {0}", expression); } if (this.ParseBool(this.Interpreter(args[0], tags))) { // evaluate and return the true-part. return(this.Interpreter(args[1], tags)); } else { // evaluate and return the false-part. return(this.Interpreter(args[2], tags)); } } else if (expression.StartsWith(ANY_TOKEN)) { // return the first expression that does not evaluate to 'none'. string[] args = this.ParseFunction(expression); if (args.Length == 0) { throw new EvalInterpreterException("Invalid argument count: {0}", expression); } for (int idx = 0; idx < args.Length; idx++) { // evaluate each expression in the correct order. string result = this.Interpreter(args[idx], tags); if (!this.IsNone(result)) { // expression was found not returning 'none'. return(result); } } return(null); } else if (expression.StartsWith(MAX_TOKEN)) { // returns the maximum value of all arguments. } else if (expression.StartsWith(MIN_TOKEN)) { // returns the minimum value of all arguments. } throw new EvalInterpreterException("Failed to evaluate expression: {0}", expression); }
/// <summary> /// Trys to return the highwaytype from the tags /// </summary> /// <param name="tags"></param> /// <param name="highwayType"></param> /// <returns></returns> protected bool TryGetHighwayType(TagsCollection tags, out string highwayType) { return(tags.TryGetValue("highway", out highwayType)); }
public static bool Normalize(this TagsCollection tags, TagsCollection profileTags, TagsCollection metaTags, IEnumerable <Vehicle> vehicles) { string str; if (!tags.TryGetValue("highway", out str)) { return(false); } tags.NormalizeMaxspeed(profileTags, metaTags); tags.NormalizeOneway(profileTags, metaTags); tags.NormalizeOnewayBicycle(profileTags, metaTags); tags.NormalizeJunction(profileTags, metaTags); // ISSUE: reference to a compiler-generated method long stringHash = str.GetHashCode(); if (stringHash <= 2067622972U) { if (stringHash <= 841786498U) { if (stringHash <= 155541048U) { if ((int)stringHash != 4126140) { if ((int)stringHash != 155541048 || !(str == "footway")) { goto label_50; } } else if (!(str == "pedestrian")) { goto label_50; } } else if ((int)stringHash != 410259268) { if ((int)stringHash != 741716276) { if ((int)stringHash != 841786498 || !(str == "secondary_link")) { goto label_50; } else { goto label_46; } } else if (!(str == "steps")) { goto label_50; } } else if (str == "tertiary_link") { goto label_46; } else { goto label_50; } tags.NormalizeRamp(profileTags, metaTags, false); profileTags.Add("highway", str); goto label_50; } else if (stringHash <= 1266453457U) { if ((int)stringHash != 908164533) { if ((int)stringHash != 1025494171) { if ((int)stringHash != 1266453457 || !(str == "secondary")) { goto label_50; } else { goto label_46; } } else if (str == "road") { goto label_46; } else { goto label_50; } } else if (str == "residential") { goto label_46; } else { goto label_50; } } else if ((int)stringHash != 1457512036) { if ((int)stringHash != 1512988633) { if ((int)stringHash != 2067622972 || !(str == "track")) { goto label_50; } else { goto label_46; } } else if (!(str == "primary")) { goto label_50; } } else if (str == "service") { goto label_46; } else { goto label_50; } } else if (stringHash <= 3245824490U) { if (stringHash <= 2772881565U) { if ((int)stringHash != -2071507658) { if ((int)stringHash != -1522085731 || !(str == "unclassified")) { goto label_50; } else { goto label_46; } } else if (str == "path") { profileTags.Add("highway", str); goto label_50; } else { goto label_50; } } else if ((int)stringHash != -1306006370) { if ((int)stringHash != -1249381910) { if ((int)stringHash != -1049142806 || !(str == "motorway_link")) { goto label_50; } } else if (!(str == "primary_link")) { goto label_50; } } else if (str == "living_street") { goto label_46; } else { goto label_50; } } else if (stringHash <= 3647643189U) { if ((int)stringHash != -705505319) { if ((int)stringHash != -700661456) { if ((int)stringHash != -647324107 || !(str == "services")) { goto label_50; } else { goto label_46; } } else if (str == "cycleway") { profileTags.Add("highway", str); goto label_50; } else { goto label_50; } } else if (!(str == "motorway")) { goto label_50; } } else if ((int)stringHash != -581013891) { if ((int)stringHash != -424251197) { if ((int)stringHash != -37246338 || !(str == "trunk_link")) { goto label_50; } } else if (str == "tertiary") { goto label_46; } else { goto label_50; } } else if (!(str == "trunk")) { goto label_50; } profileTags.Add("highway", str); goto label_50; label_46: profileTags.Add("highway", str); label_50: foreach (Vehicle vehicle in vehicles) { tags.NormalizeAccess(vehicle, str, profileTags); } return(true); }