/// <summary> /// Encodes an OsmSharp-node into a PBF-node. /// </summary> public static OsmSharp.IO.PBF.Node EncodeNode(PrimitiveBlock block, Dictionary <string, int> reverseStringTable, OsmSharp.Node node) { var pbfNode = new OsmSharp.IO.PBF.Node(); Encoder.EncodeNode(block, reverseStringTable, pbfNode, node); return(pbfNode); }
/// <summary> /// Converts the PBF node into an OsmSharp-node. /// </summary> public static OsmSharp.Node DecodeNode(PrimitiveBlock block, OsmSharp.IO.PBF.Node pbfNode) { var node = new OsmSharp.Node(); Encoder.DecodeNode(block, pbfNode, node); return(node); }
/// <summary> /// Encodes an OsmSharp-node into a PBF-node. /// </summary> public static OsmSharp.IO.PBF.Node EncodeNode(PrimitiveBlock block, Dictionary <string, int> reverseStringTable, OsmSharp.IO.PBF.Node pbfNode, OsmSharp.Node node) { pbfNode.id = node.Id.Value; pbfNode.info = new Info(); pbfNode.info.version = 0; if (node.ChangeSetId.HasValue) { pbfNode.info.changeset = node.ChangeSetId.Value; } else { pbfNode.info.changeset = 0; } if (node.TimeStamp.HasValue) { pbfNode.info.timestamp = Encoder.EncodeTimestamp(node.TimeStamp.Value, block.date_granularity); } else { pbfNode.info.timestamp = 0; } if (node.UserId.HasValue) { pbfNode.info.uid = (int)node.UserId.Value; } else { pbfNode.info.uid = 0; } pbfNode.info.user_sid = Encoder.EncodeString(block, reverseStringTable, node.UserName); if (node.Version.HasValue) { pbfNode.info.version = (int)node.Version.Value; } else { pbfNode.info.version = 0; } pbfNode.lat = Encoder.EncodeLatLon(node.Latitude.Value, block.lat_offset, block.granularity); pbfNode.lon = Encoder.EncodeLatLon(node.Longitude.Value, block.lon_offset, block.granularity); if (node.Tags != null) { foreach (var tag in node.Tags) { pbfNode.keys.Add((uint)Encoder.EncodeString(block, reverseStringTable, tag.Key)); pbfNode.vals.Add((uint)Encoder.EncodeString(block, reverseStringTable, tag.Value)); } } else { pbfNode.keys.Clear(); pbfNode.vals.Clear(); } return(pbfNode); }
/// <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); }