コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: EncoderTests.cs プロジェクト: tigrehuang/core
        public void TestDecodeNode()
        {
            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 pbfNode = new OsmSharp.IO.PBF.Node()
            {
                id   = 1,
                info = new Info()
                {
                    changeset = 10,
                    timestamp = 10,
                    uid       = 100,
                    user_sid  = 3,
                    version   = 2
                },
                lat = Encoder.EncodeLatLon(10.9f, block.lat_offset, block.granularity),
                lon = Encoder.EncodeLatLon(11.0f, block.lat_offset, block.granularity)
            };

            pbfNode.keys.Add(1);
            pbfNode.vals.Add(2);

            var node = Encoder.DecodeNode(block, pbfNode);

            Assert.IsNotNull(node);
            Assert.AreEqual(1, node.Id);
            Assert.AreEqual(10, node.ChangeSetId);
            Assert.AreEqual(10.9f, node.Latitude);
            Assert.AreEqual(11.0f, node.Longitude);
            Assert.AreEqual(PBFExtensions.FromUnixTime(10000), node.TimeStamp);
            Assert.AreEqual(OsmSharp.OsmGeoType.Node, node.Type);
            Assert.AreEqual(100, node.UserId);
            Assert.AreEqual("Ben", node.UserName);
            Assert.AreEqual(2, node.Version);
        }
コード例 #3
0
ファイル: EncoderTests.cs プロジェクト: tigrehuang/core
        public void TestDecodeBlockWithNode()
        {
            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 node = new OsmSharp.IO.PBF.Node()
            {
                id   = 1,
                info = new Info()
                {
                    changeset = 10,
                    timestamp = 10,
                    uid       = 100,
                    user_sid  = 2,
                    version   = 2
                },
                lat = Encoder.EncodeLatLon(10.9f, block.lat_offset, block.granularity),
                lon = Encoder.EncodeLatLon(11.0f, block.lat_offset, block.granularity)
            };

            node.keys.Add(0);
            node.vals.Add(1);

            var primitiveGroup = new PrimitiveGroup();

            primitiveGroup.nodes.Add(node);
            block.primitivegroup.Add(primitiveGroup);

            var primitivesConsumer = new PrimitivesConsumerMock();

            block.Decode(primitivesConsumer, false, false, false);

            Assert.AreEqual(1, primitivesConsumer.Nodes.Count);
            Assert.AreEqual(0, primitivesConsumer.Ways.Count);
            Assert.AreEqual(0, primitivesConsumer.Relations.Count);
        }
コード例 #4
0
ファイル: PBFOsmStreamSource.cs プロジェクト: OsmSharp/core
 /// <summary>
 /// Processes a node.
 /// </summary>
 /// <param name="block"></param>
 /// <param name="node"></param>
 void IPBFOsmPrimitiveConsumer.ProcessNode(PrimitiveBlock block, OsmSharp.IO.PBF.Node node)
 {
     this.QueuePrimitive(block, node);
 }
コード例 #5
0
 public void ProcessNode(PrimitiveBlock block, OsmSharp.IO.PBF.Node node)
 {
     this.Nodes.Add(node);
 }