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
 /// <summary>
 /// Initializes a new instance of the RelationInfo class with specified ID, Tags, Member and optionaly EntityMetadata.
 /// </summary>
 /// <param name="id">The id of the relation.</param>
 /// <param name="tags">The collection of tags associated with the relation.</param>
 /// <param name="members">The members of the relation.</param>
 /// <param name="additionalInfo">The EntityMetadata structure with additinal properties. Default value is null.</param> 
 public RelationInfo(int id, TagsCollection tags, IList<RelationMemberInfo> members, EntityMetadata additionalInfo = null)
 {
     this.ID = id;
     this.Tags = tags;
     this.Members = members;
     this.Metadata = additionalInfo;
 }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the WayInfo class with specified ID, Nodes, collection of tags and optionaly EntityMetadata.
 /// </summary>
 /// <param name="id">The Id of the way.</param>
 /// <param name="tags">The collection of tags associated with the way.</param>
 /// <param name="nodes">The nodes of the way.</param>
 /// <param name="additionalInfo">The EntityMetadata structure with additinal properties. Default value is null.</param>
 public WayInfo(int id, TagsCollection tags, IList<int> nodes, EntityMetadata additionalInfo = null)
 {
     this.ID = id;
     this.Tags = tags;
     this.Nodes = nodes;
     this.Metadata = additionalInfo;
 }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the NodeInfo class with specified ID, latitude, longitude, collection of tags and optionaly EntityMetadata.
 /// </summary>
 /// <param name="id">The id of the node.</param>
 /// <param name="latitude">The latitude of the node.</param>
 /// <param name="longitude">The longitude of the node.</param>
 /// <param name="tags">The collection of thag associated with the node.</param>
 /// <param name="additionalInfo">The EntityMetadata structure with additinal properties. Default value is null.</param>
 public NodeInfo(int id, double latitude, double longitude, TagsCollection tags, EntityMetadata additionalInfo = null)
 {
     this.ID = id;
     this.Latitude = latitude;
     this.Longitude = longitude;
     this.Tags = tags;
     this.Metadata = additionalInfo;
 }
        public void Constructor_Properties_SetsProperties()
        {
            int id = 45;
            TagsCollection tags = new TagsCollection();
            List<RelationMemberInfo> members = new List<RelationMemberInfo>();
            EntityMetadata details = new EntityMetadata();

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

            Assert.Equal(EntityType.Relation, target.EntityType);
            Assert.Equal(id, target.ID);
            Assert.Same(tags, target.Tags);
            Assert.Same(members, target.Members);
            Assert.Same(details, target.Metadata);
        }
示例#6
0
        public void Constructor_Properties_SetsProperties()
        {
            int id = 15;
            double latitude = 15.4;
            double longitude = -23.7;
            TagsCollection tags = new TagsCollection();
            EntityMetadata details = new EntityMetadata();

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

            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.Same(details, target.Metadata);
        }
        private void CompareEntityDetails(EntityMetadata expected, EntityMetadata actual)
        {
            if (expected == null && actual == null) {
                return;
            }

            Assert.Equal(expected.Timestamp, actual.Timestamp);
            Assert.Equal(expected.Uid, actual.Uid);
            Assert.Equal(expected.User, actual.User);
            Assert.Equal(expected.Visible, actual.Visible);
            Assert.Equal(expected.Version, actual.Version);
            Assert.Equal(expected.Changeset, actual.Changeset);
        }
示例#8
0
        /// <summary>
        /// Processes entity metadata.
        /// </summary>
        /// <param name="serializedMetadata">Serilized metadata.</param>
        /// <param name="block">PrimitiveBlock that contains metadata being processed.</param>
        /// <returns>Parsed metadata.</returns>
        private EntityMetadata ProcessMetadata(PbfMetadata serializedMetadata, PrimitiveBlock block)
        {
            EntityMetadata metadata = null;

            if (this.Settings.ReadMetadata && serializedMetadata != null) {
                //PBF has no field for 'visible' property, true is default value for OSM entity read from PBF file
                metadata = new EntityMetadata() { Visible = true };
                if (serializedMetadata.Changeset.HasValue) {
                    metadata.Changeset = (int)serializedMetadata.Changeset.Value;
                }

                if (serializedMetadata.Timestamp.HasValue) {
                    metadata.Timestamp = _unixEpoch.AddMilliseconds(serializedMetadata.Timestamp.Value * block.DateGranularity);
                }

                if (serializedMetadata.UserID.HasValue) {
                    metadata.Uid = serializedMetadata.UserID.Value;
                }

                if (serializedMetadata.UserNameIndex.HasValue) {
                    metadata.User = block.StringTable[serializedMetadata.UserNameIndex.Value];
                }

                if (serializedMetadata.Version.HasValue) {
                    metadata.Version = serializedMetadata.Version.Value;
                }
            }

            return metadata;
        }
示例#9
0
        /// <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);
            }
        }
示例#10
0
 private void CheckOsmDetails(EntityMetadata details, XElement element)
 {
     if (details == null) {
         Assert.Null(element.Attribute("version"));
         Assert.Null(element.Attribute("changeset"));
         Assert.Null(element.Attribute("uid"));
         Assert.Null(element.Attribute("user"));
         Assert.Null(element.Attribute("visible"));
         Assert.Null(element.Attribute("timestamp"));
     }
     else {
         Assert.Equal("2", element.Attribute("version").Value);
         Assert.Equal("123", element.Attribute("changeset").Value);
         Assert.Equal("4587", element.Attribute("uid").Value);
         Assert.Equal("username", element.Attribute("user").Value);
         Assert.Equal("true", element.Attribute("visible").Value);
         Assert.Equal("2011-01-20T14:00:04Z", element.Attribute("timestamp").Value);
     }
 }
示例#11
0
 /// <summary>
 /// Initializes a new instance of the NodeInfo class with specified ID, latitude, longitude, collection of tags and optionally EntityMetadata.
 /// </summary>
 /// <param name="id">The id of the node.</param>
 /// <param name="latitude">The latitude of the node.</param>
 /// <param name="longitude">The longitude of the node.</param>
 /// <param name="tags">The collection of thag associated with the node.</param>
 /// <param name="additionalInfo">The EntityMetadata structure with additinal properties. Default value is null.</param>
 public NodeInfo(long id, double latitude, double longitude, TagsCollection tags, EntityMetadata additionalInfo = null)
 {
     this.ID        = id;
     this.Latitude  = latitude;
     this.Longitude = longitude;
     this.Tags      = tags;
     this.Metadata  = additionalInfo;
 }