/// <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) { if (!_initialized) { this.Initialize(); _initialized = true; } var nextPBFPrimitive = this.MoveToNextPrimitive(ignoreNodes, ignoreWays, ignoreRelations); while (nextPBFPrimitive.Value != null) { OsmSharp.IO.PBF.Node node = (nextPBFPrimitive.Value as OsmSharp.IO.PBF.Node); if (node != null && !ignoreNodes) { // next primitve is a node. _current = Encoder.DecodeNode(nextPBFPrimitive.Key, node); return(true); } OsmSharp.IO.PBF.Way way = (nextPBFPrimitive.Value as OsmSharp.IO.PBF.Way); if (way != null && !ignoreWays) { // next primitive is a way. _current = Encoder.DecodeWay(nextPBFPrimitive.Key, way); return(true); } OsmSharp.IO.PBF.Relation relation = (nextPBFPrimitive.Value as OsmSharp.IO.PBF.Relation); if (relation != null && !ignoreRelations) { // next primitive is a relation. _current = Encoder.DecodeRelation(nextPBFPrimitive.Key, relation); return(true); } nextPBFPrimitive = this.MoveToNextPrimitive(ignoreNodes, ignoreWays, ignoreRelations); } return(false); }
public void TestDecodeWay() { var block = new PrimitiveBlock(); block.date_granularity = 1000; block.granularity = 100; block.lat_offset = 0; block.lon_offset = 0; block.stringtable = new StringTable(); block.stringtable.s.Add(System.Text.Encoding.UTF8.GetBytes(string.Empty)); // always encode empty string as '0'. block.stringtable.s.Add(System.Text.Encoding.UTF8.GetBytes("highway")); block.stringtable.s.Add(System.Text.Encoding.UTF8.GetBytes("residential")); block.stringtable.s.Add(System.Text.Encoding.UTF8.GetBytes("Ben")); var pbfWay = new OsmSharp.IO.PBF.Way() { id = 1, info = new Info() { changeset = 10, timestamp = 10, uid = 100, user_sid = 3, version = 2 } }; pbfWay.keys.Add(1); pbfWay.vals.Add(2); pbfWay.refs.Add(0); pbfWay.refs.Add(1); var way = Encoder.DecodeWay(block, pbfWay); Assert.IsNotNull(way); Assert.AreEqual(1, way.Id); Assert.AreEqual(10, way.ChangeSetId); Assert.AreEqual(PBFExtensions.FromUnixTime(10000), way.TimeStamp); Assert.AreEqual(OsmSharp.OsmGeoType.Way, way.Type); Assert.AreEqual(100, way.UserId); Assert.AreEqual("Ben", way.UserName); Assert.AreEqual(2, way.Version); Assert.AreEqual(2, way.Nodes.Length); Assert.AreEqual(0, way.Nodes[0]); Assert.AreEqual(1, way.Nodes[1]); }
public void TestDecodeBlockWithWay() { var block = new PrimitiveBlock(); block.date_granularity = 1000; block.granularity = 100; block.lat_offset = 0; block.lon_offset = 0; block.stringtable = new StringTable(); block.stringtable.s.Add(System.Text.Encoding.UTF8.GetBytes("highway")); block.stringtable.s.Add(System.Text.Encoding.UTF8.GetBytes("residential")); block.stringtable.s.Add(System.Text.Encoding.UTF8.GetBytes("Ben")); var pbfWay = new OsmSharp.IO.PBF.Way() { id = 1, info = new Info() { changeset = 10, timestamp = 10, uid = 100, user_sid = 2, version = 2 } }; pbfWay.keys.Add(0); pbfWay.vals.Add(1); pbfWay.refs.Add(0); pbfWay.refs.Add(1); var primitiveGroup = new PrimitiveGroup(); primitiveGroup.ways.Add(pbfWay); block.primitivegroup.Add(primitiveGroup); var primitivesConsumer = new PrimitivesConsumerMock(); block.Decode(primitivesConsumer, false, false, false); Assert.AreEqual(0, primitivesConsumer.Nodes.Count); Assert.AreEqual(1, primitivesConsumer.Ways.Count); Assert.AreEqual(0, primitivesConsumer.Relations.Count); }
/// <summary> /// Processes a way. /// </summary> /// <param name="block"></param> /// <param name="way"></param> void IPBFOsmPrimitiveConsumer.ProcessWay(PrimitiveBlock block, OsmSharp.IO.PBF.Way way) { this.QueuePrimitive(block, way); }
public void ProcessWay(PrimitiveBlock block, OsmSharp.IO.PBF.Way way) { this.Ways.Add(way); }