/// <summary> /// Converts a PBF-way into an OsmSharp-way. /// </summary> public static void DecodeWay(PrimitiveBlock block, OsmSharp.Osm.PBF.Way pbfWay, OsmSharp.Osm.Way way) { // make sure old data is gone. if (way.Nodes != null && way.Nodes.Count > 0) { // clear nodes list. way.Nodes.Clear(); } if (way.Tags != null) { // clear the tags collection. way.Tags.Clear(); } if (way.Nodes == null) { // create nodes list. way.Nodes = new List <long>(pbfWay.refs.Count); } if (way.Tags == null) { // create tags collection. way.Tags = new TagsCollection(pbfWay.keys.Count); } // set new stuff. way.Id = pbfWay.id; if (pbfWay.refs.Count > 0) { // fill nodes-list. long nodeId = 0; for (int i = 0; i < pbfWay.refs.Count; i++) { nodeId = nodeId + pbfWay.refs[i]; way.Nodes.Add(nodeId); } } if (pbfWay.keys.Count > 0) { for (var i = 0; i < pbfWay.keys.Count; i++) { var key = System.Text.Encoding.UTF8.GetString(block.stringtable.s[(int)pbfWay.keys[i]]); var value = System.Text.Encoding.UTF8.GetString(block.stringtable.s[(int)pbfWay.vals[i]]); way.Tags.Add(new Tag(key, value)); } } if (pbfWay.info != null) { // add the metadata if any. way.ChangeSetId = pbfWay.info.changeset; way.TimeStamp = Encoder.DecodeTimestamp(pbfWay.info.timestamp, block.date_granularity); way.UserId = pbfWay.info.uid; way.UserName = null; if (block.stringtable != null) { way.UserName = System.Text.Encoding.UTF8.GetString(block.stringtable.s[pbfWay.info.user_sid]); } way.Version = (ulong)pbfWay.info.version; } way.Visible = true; }
public static void DecodeWay(PrimitiveBlock block, Way pbfWay, OsmSharp.Osm.Way way) { if (way.Nodes != null && way.Nodes.Count > 0) { way.Nodes.Clear(); } if (way.Tags != null) { way.Tags.Clear(); } if (way.Nodes == null) { way.Nodes = new List <long>(pbfWay.refs.Count); } if (way.Tags == null) { way.Tags = (TagsCollectionBase) new TagsCollection(pbfWay.keys.Count); } way.Id = new long?(pbfWay.id); if (pbfWay.refs.Count > 0) { long num = 0; for (int index = 0; index < pbfWay.refs.Count; ++index) { num += pbfWay.refs[index]; way.Nodes.Add(num); } } if (pbfWay.keys.Count > 0) { for (int index = 0; index < pbfWay.keys.Count; ++index) { string key = Encoding.UTF8.GetString(block.stringtable.s[(int)pbfWay.keys[index]]); string str = Encoding.UTF8.GetString(block.stringtable.s[(int)pbfWay.vals[index]]); way.Tags.Add(new Tag(key, str)); } } if (pbfWay.info != null) { way.ChangeSetId = new long?(pbfWay.info.changeset); way.TimeStamp = new DateTime?(Encoder.DecodeTimestamp(pbfWay.info.timestamp, (long)block.date_granularity)); way.UserId = new long?((long)pbfWay.info.uid); way.UserName = (string)null; if (block.stringtable != null) { way.UserName = Encoding.UTF8.GetString(block.stringtable.s[pbfWay.info.user_sid]); } way.Version = new ulong?((ulong)pbfWay.info.version); } way.Visible = new bool?(true); }
/// <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); }
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); }
/// <summary> /// Converts a PBF way into an OsmSharp-relation. /// </summary> /// <returns></returns> public static OsmSharp.Osm.Relation DecodeRelation(PrimitiveBlock block, OsmSharp.Osm.PBF.Relation pbfRelation, OsmSharp.Osm.Relation relation) { // make sure old data is gone. if (relation.Members != null && relation.Members.Count > 0) { // clear nodes list. relation.Members.Clear(); } if (relation.Tags != null) { // clear the tags collection. relation.Tags.Clear(); } if (relation.Members == null) { // create nodes list. relation.Members = new List <OsmSharp.Osm.RelationMember>(pbfRelation.memids.Count); } if (relation.Tags == null) { // create tags collection. relation.Tags = new TagsCollection(pbfRelation.keys.Count); } // add nex stuff. relation.Id = pbfRelation.id; long memberId = 0; for (var i = 0; i < pbfRelation.types.Count; i++) { memberId = memberId + pbfRelation.memids[i]; var role = System.Text.Encoding.UTF8.GetString( block.stringtable.s[pbfRelation.roles_sid[i]]); var member = new OsmSharp.Osm.RelationMember(); member.MemberId = memberId; member.MemberRole = role; switch (pbfRelation.types[i]) { case Relation.MemberType.NODE: member.MemberType = OsmSharp.Osm.OsmGeoType.Node; break; case Relation.MemberType.WAY: member.MemberType = OsmSharp.Osm.OsmGeoType.Way; break; case Relation.MemberType.RELATION: member.MemberType = OsmSharp.Osm.OsmGeoType.Relation; break; } relation.Members.Add(member); } for (int i = 0; i < pbfRelation.keys.Count; i++) { string key = System.Text.Encoding.UTF8.GetString(block.stringtable.s[(int)pbfRelation.keys[i]]); string value = System.Text.Encoding.UTF8.GetString(block.stringtable.s[(int)pbfRelation.vals[i]]); relation.Tags.Add(new Tag(key, value)); } if (pbfRelation.info != null) { // read metadata if any. relation.ChangeSetId = pbfRelation.info.changeset; relation.TimeStamp = Encoder.DecodeTimestamp(pbfRelation.info.timestamp, block.date_granularity); relation.UserId = pbfRelation.info.uid; relation.UserName = null; if (block.stringtable != null) { relation.UserName = System.Text.Encoding.UTF8.GetString(block.stringtable.s[pbfRelation.info.user_sid]); } relation.Version = (ulong)pbfRelation.info.version; } relation.Visible = true; return(relation); }
public static OsmSharp.Osm.Relation DecodeRelation(PrimitiveBlock block, Relation pbfRelation, OsmSharp.Osm.Relation relation) { if (relation.Members != null && relation.Members.Count > 0) { relation.Members.Clear(); } if (relation.Tags != null) { relation.Tags.Clear(); } if (relation.Members == null) { relation.Members = new List <RelationMember>(pbfRelation.memids.Count); } if (relation.Tags == null) { relation.Tags = (TagsCollectionBase) new TagsCollection(pbfRelation.keys.Count); } relation.Id = new long?(pbfRelation.id); long num = 0; for (int index = 0; index < pbfRelation.types.Count; ++index) { num += pbfRelation.memids[index]; string str = Encoding.UTF8.GetString(block.stringtable.s[pbfRelation.roles_sid[index]]); RelationMember relationMember = new RelationMember(); relationMember.MemberId = new long?(num); relationMember.MemberRole = str; switch (pbfRelation.types[index]) { case Relation.MemberType.NODE: relationMember.MemberType = new OsmGeoType?(OsmGeoType.Node); break; case Relation.MemberType.WAY: relationMember.MemberType = new OsmGeoType?(OsmGeoType.Way); break; case Relation.MemberType.RELATION: relationMember.MemberType = new OsmGeoType?(OsmGeoType.Relation); break; } relation.Members.Add(relationMember); } for (int index = 0; index < pbfRelation.keys.Count; ++index) { string key = Encoding.UTF8.GetString(block.stringtable.s[(int)pbfRelation.keys[index]]); string str = Encoding.UTF8.GetString(block.stringtable.s[(int)pbfRelation.vals[index]]); relation.Tags.Add(new Tag(key, str)); } if (pbfRelation.info != null) { relation.ChangeSetId = new long?(pbfRelation.info.changeset); relation.TimeStamp = new DateTime?(Encoder.DecodeTimestamp(pbfRelation.info.timestamp, (long)block.date_granularity)); relation.UserId = new long?((long)pbfRelation.info.uid); relation.UserName = (string)null; if (block.stringtable != null) { relation.UserName = Encoding.UTF8.GetString(block.stringtable.s[pbfRelation.info.user_sid]); } relation.Version = new ulong?((ulong)pbfRelation.info.version); } relation.Visible = new bool?(true); return(relation); }