public OsmXmlReaderTests()
        {
            _details = new EntityMetadata() {
                Timestamp = new DateTime(2010, 11, 19, 22, 5, 56, DateTimeKind.Utc),
                Uid = 127998,
                User = "******",
                Visible = true,
                Version = 2,
                Changeset = 6410629
            };

            _node = new NodeInfo(1, 50.4, 16.2, new TagsCollection());
            _nodeTags = new NodeInfo(2, 50.4, 16.2, new TagsCollection(new Tag[] { new Tag("name", "test"), new Tag("name-2", "test-2") }));
            _nodeProperties = new NodeInfo(3, 50.4, 16.2, new TagsCollection(), _details);

            _way = new WayInfo(1, new TagsCollection(), new int[] { 10, 11, 12 });
            _wayTags = new WayInfo(2, new TagsCollection(new Tag[] { new Tag("name", "test"), new Tag("name-2", "test-2") }), new int[] { 10, 11, 12 });
            _wayProperties = new WayInfo(1, new TagsCollection(), new int[] { 10, 11, 12 }, _details);
            _wayWithoutNodes = new WayInfo(1, new TagsCollection(), new int[] { });

            _relationNode = new RelationInfo(1, new TagsCollection(), new RelationMemberInfo[] { new RelationMemberInfo() { MemberType = EntityType.Node, Reference = 10, Role = "test" } });
            _relationWay = new RelationInfo(1, new TagsCollection(), new RelationMemberInfo[] { new RelationMemberInfo() { MemberType = EntityType.Way, Reference = 10, Role = "test" } });
            _relationRelation = new RelationInfo(1, new TagsCollection(), new RelationMemberInfo[] { new RelationMemberInfo() { MemberType = EntityType.Relation, Reference = 10, Role = "test" } });
            _relationTags = new RelationInfo(
                2,
                new TagsCollection(new Tag[] { new Tag("name", "test"), new Tag("name-2", "test-2") }),
                new RelationMemberInfo[] { new RelationMemberInfo() { MemberType = EntityType.Node, Reference = 10, Role = "test" } });
            _relationProperties = new RelationInfo(1, new TagsCollection(), new RelationMemberInfo[] { new RelationMemberInfo() { MemberType = EntityType.Node, Reference = 10, Role = "test" } }, _details);
            _relationWithoutMembers = new RelationInfo(1, new TagsCollection(), new RelationMemberInfo[] { });
        }
        public void Constructor_Relation_SetsProperties()
        {
            Relation relation = new Relation(100, new RelationMember[0], new TagsCollection()) { Metadata = new EntityMetadata() };

            RelationInfo target = new RelationInfo(relation);

            Assert.Equal(relation.ID, target.ID);
            Assert.Same(relation.Tags, target.Tags);
            Assert.Same(relation.Metadata, target.Metadata);
        }
        public void Constructor_Relation_SetsRelationMembers()
        {
            Relation relation = new Relation(100, new RelationMember[] { new RelationMember(new Node(1)), new RelationMember(new Node(2)) }, new TagsCollection()) { Metadata = new EntityMetadata() };

            RelationInfo target = new RelationInfo(relation);

            Assert.Equal(relation.Geometries.Count, target.Members.Count);
            for (int i = 0; i < relation.Geometries.Count; i++) {
                Assert.Equal(relation.Geometries[i].Member.ID, target.Members[i].Reference);
            }
        }
        public void Constructor_PropertiesWithoutEntityDetails_SetsProperties()
        {
            int id = 45;
            TagsCollection tags = new TagsCollection();
            List<RelationMemberInfo> members = new List<RelationMemberInfo>();

            RelationInfo target = new RelationInfo(id, tags, members);

            Assert.Equal(EntityType.Relation, target.EntityType);
            Assert.Equal(id, target.ID);
            Assert.Same(tags, target.Tags);
            Assert.Same(members, target.Members);
            Assert.Null(target.Metadata);
        }
        public OsmEntityInfoDatabaseTests()
        {
            _nodeData = new NodeInfo[3];
            _nodeData[0] = new NodeInfo(1, 10.1, 11.1, new TagsCollection());
            _nodeData[1] = new NodeInfo(2, 10.2, 11.2, new TagsCollection());
            _nodeData[2] = new NodeInfo(3, 10.3, 11.3, new TagsCollection());

            _wayData = new WayInfo[2];
            _wayData[0] = new WayInfo(10, new TagsCollection(), _nodeData.Select(n => n.ID).ToArray());
            _wayData[1] = new WayInfo(11, new TagsCollection(), _nodeData.Select(n => n.ID).Skip(1).ToArray());

            _relationData = new RelationInfo[2];
            _relationData[0] = new RelationInfo(100, new TagsCollection(), new RelationMemberInfo[] { new RelationMemberInfo() { Reference = 10, Role = "way" }, new RelationMemberInfo() { Reference = 1, Role = "node" } });
            _relationData[1] = new RelationInfo(101, new TagsCollection(), new RelationMemberInfo[] { new RelationMemberInfo() { Reference = 101, Role = "relation" }, new RelationMemberInfo() { Reference = 1, Role = "node" } });

            _data = _nodeData.Concat<IEntityInfo>(_wayData).Concat<IEntityInfo>(_relationData).ToArray();
        }
        private void CompareRelation(RelationInfo expected, RelationInfo actual)
        {
            Assert.Equal(expected.ID, actual.ID);
            Assert.Equal(expected.Members.Count, actual.Members.Count);
            for (int i = 0; i < expected.Members.Count; i++) {
                Assert.Equal(expected.Members[i], actual.Members[i]);
            }

            this.CompareTags(expected.Tags, actual.Tags);
            this.CompareEntityDetails(expected.Metadata, actual.Metadata);
        }
Example #7
0
        /// <summary>
        /// Processes all relations from the PrimitiveGroup and adds them to the output queue.
        /// </summary>
        /// <param name="block">The PrimitiveBlock that contains specified PrimitiveGroup.</param>
        /// <param name="group">The PrimitiveGroup with nodes to process.</param>
        private void ProcessRelations(PrimitiveBlock block, PrimitiveGroup group)
        {
            if (group.Relations == null) {
                return;
            }

            foreach (var relation in group.Relations) {
                int memberRefStore = 0;

                List<RelationMemberInfo> members = new List<RelationMemberInfo>();
                for (int i = 0; i < relation.MemberIds.Count; i++) {
                    memberRefStore += (int)relation.MemberIds[i];
                    string role = block.StringTable[relation.RolesIndexes[i]];

                    EntityType memberType = 0;
                    switch (relation.Types[i]) {
                        case PbfRelationMemberType.Node: memberType = EntityType.Node; break;
                        case PbfRelationMemberType.Way: memberType = EntityType.Way; break;
                        case PbfRelationMemberType.Relation: memberType = EntityType.Relation; break;
                    }

                    members.Add(new RelationMemberInfo() { MemberType = memberType, Reference = memberRefStore, Role = role });
                }

                List<Tag> tags = new List<Tag>();
                if (relation.Keys != null) {
                    for (int i = 0; i < relation.Keys.Count; i++) {
                        tags.Add(new Tag(block.StringTable[relation.Keys[i]], block.StringTable[relation.Values[i]]));
                    }
                }

                EntityMetadata metadata = this.ProcessMetadata(relation.Metadata, block);

                RelationInfo parsed = new RelationInfo((int)relation.ID, new TagsCollection(tags), members, metadata);
                _cache.Enqueue(parsed);
            }
        }