/// <summary> /// Converts the PBF node into an OsmSharp-node. /// </summary> /// <returns></returns> public static OsmSharp.Node DecodeNode(PrimitiveBlock block, OsmSharp.IO.PBF.Node pbfNode, OsmSharp.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(0); } // 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++) { var key = System.Text.Encoding.UTF8.GetString(block.stringtable.s[(int)pbfNode.keys[i]]); var value = System.Text.Encoding.UTF8.GetString(block.stringtable.s[(int)pbfNode.vals[i]]); if (!node.Tags.TryAdd(key, value)) { // Addition of the tag failed Logger.Log("invalid tag", TraceEventType.Error, $"Could not add tag `{key}={value}` to the tagscollection of osm.org/node/{node.Id} - possible duplicate keys?"); } } if (pbfNode.info != null) { // add the metadata if any. node.TimeStamp = Encoder.DecodeTimestamp(pbfNode.info.timestamp, block.date_granularity); node.Visible = true; node.Version = 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.Visible = true; return(node); }
/// <summary> /// Converts the PBF node into an OsmSharp-node. /// </summary> /// <returns></returns> public static OsmSharp.Node DecodeNode(PrimitiveBlock block, OsmSharp.IO.PBF.Node pbfNode, OsmSharp.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 = 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.Visible = true; return(node); }