コード例 #1
0
 /// <summary>
 /// Compares two tags collections.
 /// </summary>
 public static void CompareTags(TagsCollectionBase expected, TagsCollectionBase actual)
 {
     if (expected == null)
     {
         Assert.IsNull(actual);
     }
     else
     {
         if (expected.Count == 0)
         {
             Assert.IsTrue(actual == null || actual.Count == 0);
         }
         else
         {
             Assert.IsNotNull(actual);
             Assert.AreEqual(expected.Count, actual.Count);
             foreach (Tag tag in expected)
             {
                 Assert.IsTrue(actual.ContainsKeyValue(tag.Key, tag.Value));
             }
             foreach (Tag tag in actual)
             {
                 Assert.IsTrue(expected.ContainsKeyValue(tag.Key, tag.Value));
             }
         }
     }
 }
コード例 #2
0
 /// <summary>
 /// Compares two tags collections.
 /// </summary>
 public static void CompareTags(TagsCollectionBase expected, TagsCollectionBase actual)
 {
     if (expected == null)
     {
         Assert.IsNull(actual);
     }
     else
     {
         if (expected.Count == 0)
         {
             Assert.IsTrue(actual == null || actual.Count == 0);
         }
         else
         {
             Assert.IsNotNull(actual);
             Assert.AreEqual(expected.Count, actual.Count);
             foreach (Tag tag in expected)
             {
                 Assert.IsTrue(actual.ContainsKeyValue(tag.Key, tag.Value));
             }
             foreach (Tag tag in actual)
             {
                 Assert.IsTrue(expected.ContainsKeyValue(tag.Key, tag.Value));
             }
         }
     }
 }
コード例 #3
0
ファイル: HighwayComparer.cs プロジェクト: hungdluit/OsmSharp
        public static bool CompareOpposite(AttributesIndex tags, uint tags1, uint tags2)
        {
            TagsCollectionBase tags3 = tags.Get(tags1);
            TagsCollectionBase tags4 = tags.Get(tags2);
            bool?nullable1           = Vehicle.Car.IsOneWay(tags3);
            bool?nullable2           = Vehicle.Car.IsOneWay(tags4);

            if (nullable1.HasValue && nullable2.HasValue && nullable1.Value == nullable2.Value)
            {
                return(false);
            }
            foreach (Tag tag in tags3)
            {
                if (tag.Key != "oneway" && !tags4.ContainsKeyValue(tag.Key, tag.Value))
                {
                    return(false);
                }
            }
            foreach (Tag tag in tags4)
            {
                if (tag.Key != "oneway" && !tags3.ContainsKeyValue(tag.Key, tag.Value))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Tests the given tags collection index.
        /// </summary>
        /// <param name="tagsCollectionIndex"></param>
        protected void TestTagsCollectionIndex(ITagsCollectionIndex tagsCollectionIndex)
        {
            List <KeyValuePair <uint, TagsCollectionBase> > addedTags = new List <KeyValuePair <uint, TagsCollectionBase> >();

            for (int i = 0; i < 100; i++)
            {
                TagsCollection tagsCollection    = new TagsCollection();
                int            tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3) + 1;
                for (int idx = 0; idx < tagCollectionSize; idx++)
                {
                    int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3);
                    tagsCollection.Add(
                        string.Format("key_{0}", tagValue),
                        string.Format("value_{0}", tagValue));
                }
                int addCount = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(2) + 1;
                for (int idx = 0; idx < addCount; idx++)
                {
                    uint tagsId = tagsCollectionIndex.Add(tagsCollection);
                    addedTags.Add(new KeyValuePair <uint, TagsCollectionBase>(tagsId, tagsCollection));

                    TagsCollectionBase indexTags = tagsCollectionIndex.Get(tagsId);
                    Assert.AreEqual(tagsCollection.Count, indexTags.Count);
                    foreach (Tag tag in tagsCollection)
                    {
                        Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value));
                    }
                }
            }

            // check the index.
            foreach (KeyValuePair <uint, TagsCollectionBase> pair in addedTags)
            {
                TagsCollectionBase indexTags = tagsCollectionIndex.Get(pair.Key);
                Assert.AreEqual(pair.Value.Count, indexTags.Count);
                foreach (Tag tag in pair.Value)
                {
                    Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value));
                }
                foreach (Tag tag in indexTags)
                {
                    Assert.IsTrue(pair.Value.ContainsKeyValue(tag.Key, tag.Value));
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// Returns true if the given object can be a routing restriction.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="tags"></param>
 /// <returns></returns>
 public bool IsRestriction(OsmGeoType type, TagsCollectionBase tags)
 {     // at least there need to be some tags.
     if (type == OsmGeoType.Relation)
     { // filter out relation-based turn-restrictions.
         if (tags != null &&
             tags.ContainsKeyValue("type", "restriction"))
         { // yep, there's a restriction here!
             return(true);
         }
     }
     else if (type == OsmGeoType.Node)
     { // a node is possibly a restriction too.
         if (tags != null)
         {
             return(tags.ContainsKey("barrier"));
         }
     }
     return(false);
 }
コード例 #6
0
ファイル: Bicycle.cs プロジェクト: hungdluit/OsmSharp
 protected override bool IsVehicleAllowed(TagsCollectionBase tags, string highwayType)
 {
     if (!tags.InterpretAccessValues((IEnumerable <string>) this.VehicleTypes, "access"))
     {
         return(false);
     }
     if (tags.ContainsKey("bicycle"))
     {
         if (tags["bicycle"] == "designated" || tags["bicycle"] == "yes")
         {
             return(true);
         }
         if (tags["bicycle"] == "no")
         {
             return(false);
         }
     }
     if (!(highwayType == "steps"))
     {
         return(this.AccessibleTags.ContainsKey(highwayType));
     }
     return(tags.ContainsKeyValue("ramp", "yes"));
 }
コード例 #7
0
 /// <summary>
 /// Returns true if the given object can be a routing restriction.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="tags"></param>
 /// <returns></returns>
 public bool IsRestriction(OsmGeoType type, TagsCollectionBase tags)
 { // at least there need to be some tags.
     if (type == OsmGeoType.Relation)
     { // filter out relation-based turn-restrictions.
         if (tags != null &&
             tags.ContainsKeyValue("type", "restriction"))
         { // yep, there's a restriction here!
             return true;
         }
     }
     else if(type == OsmGeoType.Node)
     { // a node is possibly a restriction too.
         if(tags != null)
         {
             return tags.ContainsKey("barrier");
         }
     }
     return false;
 }