Beispiel #1
0
        /// <summary>
        /// Creates a collection of Node objects from nodes in tokens.
        /// </summary>
        /// <param name="timestampGranularity">Timestamp granularity as defined in PrimitiveBlock.</param>
        /// <param name="positionGranularity">Granularity as defined in PrimitiveBlock.</param>
        /// <param name="latOffset">Latitude offset as defined in PrimitiveBlock.</param>
        /// <param name="lonOffset">Longitude offset as defined in PrimitiveBlock.</param>
        /// <returns>The DenseNode obejct with data from nodes in tokens.</returns>
        private List <PbfNode> BuildNodes(int timestampGranularity, int positionGranularity, long latOffset, long lonOffset)
        {
            List <PbfNode> result = new List <PbfNode>(_nodesBuffer.Count);

            foreach (var node in _nodesBuffer)
            {
                PbfNode toAdd = new PbfNode();

                toAdd.ID        = node.ID;
                toAdd.Latitude  = (long)Math.Round(((node.Latitude / 1E-09) - latOffset) / positionGranularity);
                toAdd.Longitude = (long)Math.Round(((node.Longitude / 1E-09) - lonOffset) / positionGranularity);

                if (node.Tags.Count > 0)
                {
                    toAdd.Keys   = new List <uint>();
                    toAdd.Values = new List <uint>();

                    foreach (var tag in node.Tags)
                    {
                        toAdd.Keys.Add(_nodesBuffer.GetStringIndex(tag.Key));
                        toAdd.Values.Add(_nodesBuffer.GetStringIndex(tag.Value));
                    }
                }

                if (node.Metadata != null && this.Settings.WriteMetadata)
                {
                    toAdd.Metadata = this.BuildInfo(node.Metadata, timestampGranularity, _nodesBuffer);
                }

                result.Add(toAdd);
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Creates collection of PbfRelation objects from relations in tokens.
        /// </summary>
        /// <param name="timestampGranularity">Timestamp granularity as defined in PrimitiveBlock.</param>
        /// <returns>The collection of PbfRelation objects created from relations in tokens.</returns>
        private List <PbfRelation> BuildRelations(int timestampGranularity)
        {
            List <PbfRelation> result = new List <PbfRelation>();

            foreach (var relation in _relationBuffer)
            {
                PbfRelation toAdd = new PbfRelation();
                toAdd.ID = relation.ID;

                long lastRef = 0;
                foreach (var member in relation.Members)
                {
                    toAdd.MemberIds.Add(member.Reference - lastRef);
                    lastRef = member.Reference;

                    toAdd.RolesIndexes.Add((int)_relationBuffer.GetStringIndex(member.Role ?? string.Empty));
                    PbfRelationMemberType memberType = 0;
                    switch (member.MemberType)
                    {
                    case EntityType.Node: memberType = PbfRelationMemberType.Node; break;

                    case EntityType.Way: memberType = PbfRelationMemberType.Way; break;

                    case EntityType.Relation: memberType = PbfRelationMemberType.Relation; break;
                    }

                    toAdd.Types.Add(memberType);
                }

                toAdd.Keys   = new List <uint>(relation.Tags.Count);
                toAdd.Values = new List <uint>(relation.Tags.Count);

                if (relation.Tags.Count > 0)
                {
                    foreach (var tag in relation.Tags)
                    {
                        toAdd.Keys.Add(_relationBuffer.GetStringIndex(tag.Key));
                        toAdd.Values.Add(_relationBuffer.GetStringIndex(tag.Value));
                    }
                }

                if (relation.Metadata != null && this.Settings.WriteMetadata)
                {
                    toAdd.Metadata = this.BuildInfo(relation.Metadata, timestampGranularity, _relationBuffer);
                }

                result.Add(toAdd);
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Creates collection of PbfWay objects from ways in tokens.
        /// </summary>
        /// <param name="timestampGranularity">Timestamp granularity as defined in PrimitiveBlock.</param>
        /// <returns>The collection of PbfWay objects created from relations in tokens.</returns>
        private List <PbfWay> BuildWays(int timestampGranularity)
        {
            List <PbfWay> result = new List <PbfWay>();

            foreach (var way in _wayBuffer)
            {
                long lastRef = 0;

                PbfWay toAdd = new PbfWay();

                toAdd.ID = way.ID;

                if (way.Nodes.Count > 0)
                {
                    toAdd.Refs = new List <long>(way.Nodes.Count);

                    for (int i = 0; i < way.Nodes.Count; i++)
                    {
                        toAdd.Refs.Add(way.Nodes[i] - lastRef);
                        lastRef = way.Nodes[i];
                    }
                }

                if (way.Tags.Count > 0)
                {
                    toAdd.Keys   = new List <uint>();
                    toAdd.Values = new List <uint>();

                    foreach (var tag in way.Tags)
                    {
                        toAdd.Keys.Add(_wayBuffer.GetStringIndex(tag.Key));
                        toAdd.Values.Add(_wayBuffer.GetStringIndex(tag.Value));
                    }
                }

                if (way.Metadata != null && this.Settings.WriteMetadata)
                {
                    toAdd.Metadata = this.BuildInfo(way.Metadata, timestampGranularity, _wayBuffer);
                }

                result.Add(toAdd);
            }

            return(result);
        }