示例#1
0
        /// <summary>
        /// Tests a simple relation read/write operation.
        /// </summary>
        /// <param name="cache"></param>
        public void DoOsmDataCacheTestRelation(OsmDataCache cache)
        {
            Relation relation = Relation.Create(1, new TagsCollection(
                                                    Tag.Create("relation", "yes")), RelationMember.Create(1, "something", OsmGeoType.Node));

            // test invalid stuff.
            Assert.Throws <ArgumentNullException>(() => cache.AddRelation(null));
            Assert.Throws <Exception>(() => cache.AddRelation(new Relation()));
            Assert.IsNull(cache.GetRelation(relation.Id.Value));

            cache.AddRelation(relation);

            Assert.IsTrue(cache.ContainsRelation(relation.Id.Value));
            Relation readRelation = cache.GetRelation(relation.Id.Value);

            Assert.IsNotNull(readRelation);
            Assert.AreEqual(1, readRelation.Id.Value);
            Assert.IsNotNull(relation.Tags);
            Assert.AreEqual(1, relation.Tags.Count);
            Assert.AreEqual("yes", relation.Tags["relation"]);

            Assert.IsTrue(cache.TryGetRelation(relation.Id.Value, out readRelation));
            Assert.IsNotNull(readRelation);
            Assert.AreEqual(1, readRelation.Id.Value);
            Assert.IsNotNull(relation.Tags);
            Assert.AreEqual(1, relation.Tags.Count);
            Assert.AreEqual("yes", relation.Tags["relation"]);

            Assert.IsTrue(cache.RemoveRelation(relation.Id.Value));
            Assert.IsFalse(cache.ContainsRelation(relation.Id.Value));
            Assert.IsFalse(cache.RemoveRelation(relation.Id.Value));
        }
示例#2
0
        /// <summary>
        /// Seeks for objects that are children of other objects.
        /// </summary>
        private void Seek()
        {
            var relations = new List <Relation>();

            _simpleSource.Initialize();
            while (_simpleSource.MoveNext(true, false, false))
            {
                var osmGeo = _simpleSource.Current();

                switch (osmGeo.Type)
                {
                case OsmGeoType.Way:
                    var way = (osmGeo as Way);
                    if (way.Nodes != null)
                    {
                        foreach (long nodeId in way.Nodes)
                        {
                            this.MarkNodeAsChild(nodeId);
                        }
                    }
                    break;

                case OsmGeoType.Relation:
                    var relation = (osmGeo as Relation);
                    if (relation.Members != null)
                    {
                        foreach (RelationMember member in relation.Members)
                        {
                            switch (member.MemberType.Value)
                            {
                            case OsmGeoType.Node:
                                this.MarkNodeAsChild(member.MemberId.Value);
                                break;

                            case OsmGeoType.Way:
                                this.MarkWayAsChild(member.MemberId.Value);
                                break;

                            case OsmGeoType.Relation:
                                this.MarkRelationAsChild(member.MemberId.Value);
                                break;
                            }
                        }
                    }
                    relations.Add(relation);
                    break;
                }
            }
            foreach (var relation in relations)
            {
                if (_relationsToInclude.Contains(relation.Id.Value))
                { // yep, cache relation!
                    _dataCache.AddRelation(relation);
                }
            }
            _simpleSource.Reset();
        }
 /// <summary>
 /// Cache all needed relations.
 /// </summary>
 private void CacheRelations()
 {
     // TODO: enhance this to only cache relations that are not in the correct 'order' in the stream.
     foreach (OsmGeo osmGeo in _simpleSource)
     {
         switch (osmGeo.Type)
         {
         case OsmGeoType.Relation:
             if (_relationsToInclude.Contains(osmGeo.Id.Value))
             {     // yep, cache relation!
                 _dataCache.AddRelation(osmGeo as Relation);
             }
             break;
         }
     }
     _simpleSource.Reset();
 }
示例#4
0
        /// <summary>
        /// Tests the clear functionality on the datacache.
        /// </summary>
        /// <param name="cache"></param>
        public void DoOsmDataCacheTestClear(OsmDataCache cache)
        {
            Node node = Node.Create(1, new TagsCollection(
                                        Tag.Create("node", "yes")), 1, 2);
            Way way = Way.Create(1, new TagsCollection(
                                     Tag.Create("way", "yes")), 1, 2);
            Relation relation = Relation.Create(1, new TagsCollection(
                                                    Tag.Create("relation", "yes")), RelationMember.Create(1, "something", OsmGeoType.Node));

            cache.AddNode(node);
            cache.AddWay(way);
            cache.AddRelation(relation);

            Assert.IsTrue(cache.ContainsNode(node.Id.Value));
            Assert.IsTrue(cache.ContainsWay(way.Id.Value));
            Assert.IsTrue(cache.ContainsRelation(relation.Id.Value));

            cache.Clear();

            Assert.IsFalse(cache.ContainsNode(node.Id.Value));
            Assert.IsFalse(cache.ContainsWay(way.Id.Value));
            Assert.IsFalse(cache.ContainsRelation(relation.Id.Value));
        }