Exemplo n.º 1
0
        /// <summary>
        /// Creates an PbfMetadata obejct from given Metadata.
        /// </summary>
        /// <param name="metadata">Metadata obejct to be used as source of data.</param>
        /// <param name="timestampGranularity">Timestamp granularity as defined in PrimitiveBlock.</param>
        /// <param name="stringTableBuilder">IStrignTable object to save string values to.</param>
        /// <returns>PbfMetadata obejct with data from specified metadata object.</returns>
        private PbfMetadata BuildInfo(EntityMetadata metadata, int timestampGranularity, IStringTableBuilder stringTableBuilder)
        {
            PbfMetadata result = new PbfMetadata();
            result.Changeset = metadata.Changeset;
            result.Timestamp = (long)Math.Round((metadata.Timestamp - _unixEpoch).TotalMilliseconds / timestampGranularity);
            result.UserID = metadata.Uid;
            result.UserNameIndex = (int)stringTableBuilder.GetStringIndex(metadata.User);
            result.Version = metadata.Version;

            return result;
        }
Exemplo n.º 2
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;
        }