コード例 #1
0
        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[] { });
        }
コード例 #2
0
        public void Constructor_Node_SetsProperties()
        {
            Node node = new Node(1, 10.1, 12.1, new TagsCollection()) { Metadata = new EntityMetadata() };

            NodeInfo target = new NodeInfo(node);

            Assert.Equal(node.ID, target.ID);
            Assert.Equal(node.Position.X, target.Longitude);
            Assert.Equal(node.Position.Y, target.Latitude);
            Assert.Same(node.Tags, target.Tags);
            Assert.Same(node.Metadata, target.Metadata);
        }
コード例 #3
0
        public void Constructor_PropertiesWithoutEntityDetails_SetsProperties()
        {
            int id = 15;
            double latitude = 15.4;
            double longitude = -23.7;
            TagsCollection tags = new TagsCollection();

            NodeInfo target = new NodeInfo(id, latitude, longitude, tags);

            Assert.Equal(EntityType.Node, target.EntityType);
            Assert.Equal(id, target.ID);
            Assert.Equal(latitude, target.Latitude);
            Assert.Equal(longitude, target.Longitude);
            Assert.Same(tags, target.Tags);
            Assert.Null(target.Metadata);
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        private void CompareNodes(NodeInfo expected, NodeInfo actual)
        {
            Assert.Equal(expected.ID, actual.ID);
            Assert.Equal(expected.Longitude, actual.Longitude);
            Assert.Equal(expected.Latitude, actual.Latitude);

            this.CompareTags(expected.Tags, actual.Tags);
            this.CompareEntityDetails(expected.Metadata, actual.Metadata);
        }
コード例 #6
0
ファイル: NodeTests.cs プロジェクト: najira/spatiallite-net
        public void Constructor_NodeInfo_CreatesNodeFromNodeInfo()
        {
            NodeInfo info = new NodeInfo(1, 15.6, 20.4, new TagsCollection(), new EntityMetadata());

            Node target = Node.FromNodeInfo(info);

            Assert.Equal(info.ID, target.ID);
            Assert.Equal(info.Longitude, target.Position.X);
            Assert.Equal(info.Latitude, target.Position.Y);
            Assert.Same(info.Tags, target.Tags);
            Assert.Same(info.Metadata, target.Metadata);
        }
コード例 #7
0
ファイル: PbfReader.cs プロジェクト: najira/spatiallite-net
        /// <summary>
        /// Processes all nodes in non-dense format 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 ProcessNodes(PrimitiveBlock block, PrimitiveGroup group)
        {
            if (group.Nodes == null) {
                return;
            }

            foreach (PbfNode node in group.Nodes) {
                double lat = 1E-09 * (block.LatOffset + (block.Granularity * node.Latitude));
                double lon = 1E-09 * (block.LonOffset + (block.Granularity * node.Longitude));

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

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

                NodeInfo parsed = new NodeInfo((int)node.ID, lat, lon, new TagsCollection(tags), metadata);
                _cache.Enqueue(parsed);
            }
        }
コード例 #8
0
ファイル: PbfReader.cs プロジェクト: najira/spatiallite-net
        /// <summary>
        /// Processes all nodes in dense format 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 ProcessDenseNodes(PrimitiveBlock block, PrimitiveGroup group)
        {
            if (group.DenseNodes == null) {
                return;
            }

            long idStore = 0;
            long latStore = 0;
            long lonStore = 0;

            int keyValueIndex = 0;

            long timestampStore = 0;
            long changesetStore = 0;
            int userIdStore = 0;
            int usernameIdStore = 0;

            for (int i = 0; i < group.DenseNodes.Id.Count; i++) {
                idStore += group.DenseNodes.Id[i];
                lonStore += group.DenseNodes.Longitude[i];
                latStore += group.DenseNodes.Latitude[i];

                double lat = 1E-09 * (block.LatOffset + (block.Granularity * latStore));
                double lon = 1E-09 * (block.LonOffset + (block.Granularity * lonStore));

                List<Tag> tags = new List<Tag>();
                if (group.DenseNodes.KeysVals.Count > 0) {
                    while (group.DenseNodes.KeysVals[keyValueIndex] != 0) {
                        string key = block.StringTable[group.DenseNodes.KeysVals[keyValueIndex++]];
                        string value = block.StringTable[group.DenseNodes.KeysVals[keyValueIndex++]];

                        tags.Add(new Tag(key, value));
                    }

                    //Skip '0' used as delimiter
                    keyValueIndex++;
                }

                EntityMetadata metadata = null;
                if (this.Settings.ReadMetadata && group.DenseNodes.DenseInfo != null) {
                    timestampStore += group.DenseNodes.DenseInfo.Timestamp[i];
                    changesetStore += group.DenseNodes.DenseInfo.Changeset[i];
                    userIdStore += group.DenseNodes.DenseInfo.UserId[i];
                    usernameIdStore += group.DenseNodes.DenseInfo.UserNameIndex[i];

                    metadata = new EntityMetadata() {
                        Changeset = (int)changesetStore,
                        Timestamp = _unixEpoch.AddMilliseconds(timestampStore * block.DateGranularity),
                        Uid = userIdStore,
                        User = block.StringTable[usernameIdStore],
                        Version = group.DenseNodes.DenseInfo.Version[i],
                        Visible = true
                    };

                    if (group.DenseNodes.DenseInfo.Visible.Count > 0) {
                        metadata.Visible = group.DenseNodes.DenseInfo.Visible[i];
                    }
                }

                NodeInfo parsed = new NodeInfo((int)idStore, lat, lon, new TagsCollection(tags), metadata);
                _cache.Enqueue(parsed);
            }
        }
コード例 #9
0
        private void CompareNodes(NodeInfo expected, NodeInfo actual)
        {
            Assert.Equal(expected.ID, actual.ID);
            Assert.InRange(actual.Longitude, expected.Longitude - _resolution, expected.Longitude + _resolution);
            Assert.InRange(actual.Latitude, expected.Latitude - _resolution, expected.Latitude + _resolution);

            this.CompareTags(expected.Tags, actual.Tags);
            this.CompareEntityDetails(expected.Metadata, actual.Metadata);
        }
コード例 #10
0
        public void Flush_ForcesWriterToWriteDataToUnderalyingStorage()
        {
            MemoryStream stream = new MemoryStream();

            PbfWriter target = new PbfWriter(stream, new PbfWriterSettings() { UseDenseFormat = false, Compression = CompressionMode.None, WriteMetadata = false });

            //1000 nodes should fit into tokens
            for (int i = 0; i < 1000; i++) {
                NodeInfo node = new NodeInfo(i, 45.87, -126.5, new TagsCollection());
                target.Write(node);
            }
            int minimalExpectedLengthIncrease = 1000 * 8;

            long originalStreamLength = stream.Length;
            target.Flush();

            Assert.True(stream.Length > originalStreamLength + minimalExpectedLengthIncrease);
        }