Esempio n. 1
0
        /// <summary>
        /// Converts the PBF node into an OsmSharp-node.
        /// </summary>
        /// <returns></returns>
        public static OsmSharp.Osm.Node DecodeNode(PrimitiveBlock block, OsmSharp.Osm.PBF.Node pbfNode, OsmSharp.Osm.Node node)
        {
            // clear old data.
            if (node.Tags != null)
            { // clear tags.
                node.Tags.Clear();
            }
            if (node.Tags == null)
            { // create tags collection.
                node.Tags = new TagsCollection();
            }

            // set new stuff.
            node.ChangeSetId = pbfNode.info.changeset;
            node.Id          = pbfNode.id;
            node.Latitude    = Encoder.DecodeLatLon(pbfNode.lat, block.lat_offset, block.granularity);
            node.Longitude   = Encoder.DecodeLatLon(pbfNode.lon, block.lon_offset, block.granularity);
            for (var i = 0; i < pbfNode.keys.Count; i++)
            {
                node.Tags.Add(new Tag()
                {
                    Key   = System.Text.Encoding.UTF8.GetString(block.stringtable.s[(int)pbfNode.keys[i]]),
                    Value = System.Text.Encoding.UTF8.GetString(block.stringtable.s[(int)pbfNode.vals[i]])
                });
            }
            if (pbfNode.info != null)
            { // add the metadata if any.
                node.TimeStamp = Encoder.DecodeTimestamp(pbfNode.info.timestamp, block.date_granularity);
                node.Visible   = true;
                node.Version   = (uint)pbfNode.info.version;
                node.UserId    = pbfNode.info.uid;
                node.UserName  = null;
                if (block.stringtable != null)
                {
                    node.UserName = System.Text.Encoding.UTF8.GetString(block.stringtable.s[pbfNode.info.user_sid]);
                }
                node.Version = (ulong)pbfNode.info.version;
            }
            node.Visible = true;

            return(node);
        }
Esempio n. 2
0
 public static OsmSharp.Osm.Node DecodeNode(PrimitiveBlock block, Node pbfNode, OsmSharp.Osm.Node node)
 {
     if (node.Tags != null)
     {
         node.Tags.Clear();
     }
     if (node.Tags == null)
     {
         node.Tags = (TagsCollectionBase) new TagsCollection();
     }
     node.ChangeSetId = new long?(pbfNode.info.changeset);
     node.Id          = new long?(pbfNode.id);
     node.Latitude    = new double?(Encoder.DecodeLatLon(pbfNode.lat, block.lat_offset, (long)block.granularity));
     node.Longitude   = new double?(Encoder.DecodeLatLon(pbfNode.lon, block.lon_offset, (long)block.granularity));
     for (int index = 0; index < pbfNode.keys.Count; ++index)
     {
         node.Tags.Add(new Tag()
         {
             Key   = Encoding.UTF8.GetString(block.stringtable.s[(int)pbfNode.keys[index]]),
             Value = Encoding.UTF8.GetString(block.stringtable.s[(int)pbfNode.vals[index]])
         });
     }
     if (pbfNode.info != null)
     {
         node.TimeStamp = new DateTime?(Encoder.DecodeTimestamp(pbfNode.info.timestamp, (long)block.date_granularity));
         node.Visible   = new bool?(true);
         node.Version   = new ulong?((ulong)(uint)pbfNode.info.version);
         node.UserId    = new long?((long)pbfNode.info.uid);
         node.UserName  = (string)null;
         if (block.stringtable != null)
         {
             node.UserName = Encoding.UTF8.GetString(block.stringtable.s[pbfNode.info.user_sid]);
         }
         node.Version = new ulong?((ulong)pbfNode.info.version);
     }
     node.Visible = new bool?(true);
     return(node);
 }