/// <summary> /// Encodes an OsmSharp-node into a PBF-node. /// </summary> /// <returns></returns> public static OsmSharp.Osm.PBF.Node EncodeNode(PrimitiveBlock block, Dictionary <string, int> reverseStringTable, Osm.Node node) { var pbfNode = new OsmSharp.Osm.PBF.Node(); Encoder.EncodeNode(block, reverseStringTable, pbfNode, node); return(pbfNode); }
public override bool MoveNext(bool ignoreNodes, bool ignoreWays, bool ignoreRelations) { for (KeyValuePair <PrimitiveBlock, object> nextPrimitive = this.MoveToNextPrimitive(ignoreNodes, ignoreWays, ignoreRelations); nextPrimitive.Value != null; nextPrimitive = this.MoveToNextPrimitive(ignoreNodes, ignoreWays, ignoreRelations)) { OsmSharp.Osm.PBF.Node pbfNode = nextPrimitive.Value as OsmSharp.Osm.PBF.Node; if (pbfNode != null && !ignoreNodes) { this._current = (OsmGeo)Encoder.DecodeNode(nextPrimitive.Key, pbfNode); return(true); } OsmSharp.Osm.PBF.Way pbfWay = nextPrimitive.Value as OsmSharp.Osm.PBF.Way; if (pbfWay != null && !ignoreWays) { this._current = (OsmGeo)Encoder.DecodeWay(nextPrimitive.Key, pbfWay); return(true); } OsmSharp.Osm.PBF.Relation pbfRelation = nextPrimitive.Value as OsmSharp.Osm.PBF.Relation; if (pbfRelation != null && !ignoreRelations) { this._current = (OsmGeo)Encoder.DecodeRelation(nextPrimitive.Key, pbfRelation); return(true); } } return(false); }
/// <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) { var node = new OsmSharp.Osm.Node(); Encoder.DecodeNode(block, pbfNode, node); return(node); }
/// <summary> /// Move to the next item in the stream. /// </summary> /// <param name="ignoreNodes">Makes this source skip all nodes.</param> /// <param name="ignoreWays">Makes this source skip all ways.</param> /// <param name="ignoreRelations">Makes this source skip all relations.</param> /// <returns></returns> public override bool MoveNext(bool ignoreNodes, bool ignoreWays, bool ignoreRelations) { var nextPBFPrimitive = this.MoveToNextPrimitive(ignoreNodes, ignoreWays, ignoreRelations); while (nextPBFPrimitive.Value != null) { OsmSharp.Osm.PBF.Node node = (nextPBFPrimitive.Value as OsmSharp.Osm.PBF.Node); if (node != null && !ignoreNodes) { // next primitve is a node. _current = this.ConvertNode(nextPBFPrimitive.Key, node); return(true); } OsmSharp.Osm.PBF.Way way = (nextPBFPrimitive.Value as OsmSharp.Osm.PBF.Way); if (way != null && !ignoreWays) { // next primitive is a way. _current = this.ConvertWay(nextPBFPrimitive.Key, way); return(true); } OsmSharp.Osm.PBF.Relation relation = (nextPBFPrimitive.Value as OsmSharp.Osm.PBF.Relation); if (relation != null && !ignoreRelations) { // next primitive is a relation. _current = this.ConvertRelation(nextPBFPrimitive.Key, relation); return(true); } nextPBFPrimitive = this.MoveToNextPrimitive(ignoreNodes, ignoreWays, ignoreRelations); } return(false); }
/// <summary> /// Converts the PBF node into an OsmSharp-node. /// </summary> /// <param name="block"></param> /// <param name="node"></param> /// <returns></returns> internal OsmSharp.Osm.Node ConvertNode(PrimitiveBlock block, OsmSharp.Osm.PBF.Node node) { var simpleNode = new OsmSharp.Osm.Node(); simpleNode.ChangeSetId = node.info.changeset; simpleNode.Id = node.id; simpleNode.Latitude = .000000001 * ((double)block.lat_offset + ((double)block.granularity * (double)node.lat)); simpleNode.Longitude = .000000001 * ((double)block.lon_offset + ((double)block.granularity * (double)node.lon)); simpleNode.Tags = new TagsCollection(node.keys.Count); if (node.keys.Count > 0) { for (int tag_idx = 0; tag_idx < node.keys.Count; tag_idx++) { string key = Encoding.UTF8.GetString(block.stringtable.s[(int)node.keys[tag_idx]]); string value = Encoding.UTF8.GetString(block.stringtable.s[(int)node.vals[tag_idx]]); simpleNode.Tags.Add(new Tag() { Key = key, Value = value }); } } simpleNode.TimeStamp = Utilities.FromUnixTime((long)node.info.timestamp * (long)block.date_granularity); simpleNode.Visible = true; simpleNode.Version = (uint)node.info.version; simpleNode.UserId = node.info.uid; simpleNode.UserName = Encoding.UTF8.GetString(block.stringtable.s[node.info.user_sid]); simpleNode.Version = (ulong)node.info.version; simpleNode.Visible = true; return(simpleNode); }
/// <summary> /// Encodes an OsmSharp-node into a PBF-node. /// </summary> /// <returns></returns> public static OsmSharp.Osm.PBF.Node EncodeNode(PrimitiveBlock block, Dictionary <string, int> reverseStringTable, OsmSharp.Osm.PBF.Node pbfNode, Osm.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.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); }
void IPBFOsmPrimitiveConsumer.ProcessNode(PrimitiveBlock block, OsmSharp.Osm.PBF.Node node) { this.QueuePrimitive(block, (object)node); }
/// <summary> /// Encodes an OsmSharp-node into a PBF-node. /// </summary> /// <returns></returns> public static OsmSharp.Osm.PBF.Node EncodeNode(PrimitiveBlock block, Dictionary<string, int> reverseStringTable, Osm.Node node) { var pbfNode = new OsmSharp.Osm.PBF.Node(); Encoder.EncodeNode(block, reverseStringTable, pbfNode, node); return pbfNode; }