Esempio n. 1
0
        public void TestDecodeBlockWithRelation()
        {
            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 pbfRelation = new OsmSharp.IO.PBF.Relation()
            {
                id   = 1,
                info = new Info()
                {
                    changeset = 10,
                    timestamp = 10,
                    uid       = 100,
                    user_sid  = 2,
                    version   = 2
                }
            };

            pbfRelation.keys.Add(0);
            pbfRelation.vals.Add(1);
            pbfRelation.memids.Add(10);
            pbfRelation.memids.Add(1); // delta-encoding.
            pbfRelation.roles_sid.Add(3);
            pbfRelation.roles_sid.Add(3);
            pbfRelation.types.Add(OsmSharp.IO.PBF.Relation.MemberType.NODE);
            pbfRelation.types.Add(OsmSharp.IO.PBF.Relation.MemberType.WAY);

            var primitiveGroup = new PrimitiveGroup();

            primitiveGroup.relations.Add(pbfRelation);
            block.primitivegroup.Add(primitiveGroup);

            var primitivesConsumer = new PrimitivesConsumerMock();

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

            Assert.AreEqual(0, primitivesConsumer.Nodes.Count);
            Assert.AreEqual(0, primitivesConsumer.Ways.Count);
            Assert.AreEqual(1, primitivesConsumer.Relations.Count);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void TestDecodeBlockWithDenseNodes()
        {
            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"));     // 1
            block.stringtable.s.Add(System.Text.Encoding.UTF8.GetBytes("residential")); // 2
            block.stringtable.s.Add(System.Text.Encoding.UTF8.GetBytes("Ben"));         // 3
            block.stringtable.s.Add(System.Text.Encoding.UTF8.GetBytes("track"));       // 4
            block.stringtable.s.Add(System.Text.Encoding.UTF8.GetBytes("trunk"));       // 5

            var primitiveGroup = new PrimitiveGroup();

            primitiveGroup.dense           = new DenseNodes();
            primitiveGroup.dense.denseinfo = new DenseInfo();
            primitiveGroup.dense.denseinfo.changeset.Add(10);
            primitiveGroup.dense.denseinfo.changeset.Add(1);
            primitiveGroup.dense.denseinfo.changeset.Add(1);

            primitiveGroup.dense.denseinfo.timestamp.Add(10);
            primitiveGroup.dense.denseinfo.timestamp.Add(1);
            primitiveGroup.dense.denseinfo.timestamp.Add(1);

            primitiveGroup.dense.denseinfo.uid.Add(1);
            primitiveGroup.dense.denseinfo.uid.Add(0);
            primitiveGroup.dense.denseinfo.uid.Add(0);

            primitiveGroup.dense.denseinfo.user_sid.Add(3);
            primitiveGroup.dense.denseinfo.user_sid.Add(0);
            primitiveGroup.dense.denseinfo.user_sid.Add(0);

            primitiveGroup.dense.denseinfo.version.Add(1);
            primitiveGroup.dense.denseinfo.version.Add(1);
            primitiveGroup.dense.denseinfo.version.Add(1);

            primitiveGroup.dense.id.Add(1);
            primitiveGroup.dense.id.Add(1);
            primitiveGroup.dense.id.Add(1);

            primitiveGroup.dense.keys_vals.Add(1);
            primitiveGroup.dense.keys_vals.Add(2);
            primitiveGroup.dense.keys_vals.Add(0); // highway=residential.
            primitiveGroup.dense.keys_vals.Add(1);
            primitiveGroup.dense.keys_vals.Add(4);
            primitiveGroup.dense.keys_vals.Add(0); // highway=track.
            primitiveGroup.dense.keys_vals.Add(0); // empty.

            primitiveGroup.dense.lat.Add(Encoder.EncodeLatLon(10.0f, block.lat_offset, block.granularity));
            primitiveGroup.dense.lat.Add(Encoder.EncodeLatLon(11.0f, block.lat_offset, block.granularity)
                                         - primitiveGroup.dense.lat[primitiveGroup.dense.lat.Count - 1]);
            primitiveGroup.dense.lat.Add(Encoder.EncodeLatLon(12.0f, block.lat_offset, block.granularity)
                                         - primitiveGroup.dense.lat[primitiveGroup.dense.lat.Count - 1]);

            primitiveGroup.dense.lon.Add(Encoder.EncodeLatLon(100.0f, block.lon_offset, block.granularity));
            primitiveGroup.dense.lon.Add(Encoder.EncodeLatLon(110.0f, block.lon_offset, block.granularity)
                                         - primitiveGroup.dense.lon[primitiveGroup.dense.lon.Count - 1]);
            primitiveGroup.dense.lon.Add(Encoder.EncodeLatLon(120.0f, block.lon_offset, block.granularity)
                                         - primitiveGroup.dense.lon[primitiveGroup.dense.lon.Count - 1]);

            block.primitivegroup.Add(primitiveGroup);

            var primitivesConsumer = new PrimitivesConsumerMock();

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

            Assert.AreEqual(3, primitivesConsumer.Nodes.Count);
            Assert.AreEqual(0, primitivesConsumer.Ways.Count);
            Assert.AreEqual(0, primitivesConsumer.Relations.Count);

            var node = primitivesConsumer.Nodes[0];

            Assert.IsNotNull(node);
            Assert.AreEqual(1, node.id);
            Assert.AreEqual(10, node.info.changeset);
            Assert.AreEqual(10, node.info.timestamp);
            Assert.AreEqual(1, node.info.uid);
            Assert.AreEqual(3, node.info.user_sid);
            Assert.AreEqual(1, node.info.version);
            Assert.AreEqual(1, node.keys.Count);
            Assert.AreEqual(1, node.keys[0]);
            Assert.AreEqual(1, node.vals.Count);
            Assert.AreEqual(2, node.vals[0]);

            node = primitivesConsumer.Nodes[1];
            Assert.IsNotNull(node);
            Assert.AreEqual(2, node.id);
            Assert.AreEqual(11, node.info.changeset);
            Assert.AreEqual(11, node.info.timestamp);
            Assert.AreEqual(1, node.info.uid);
            Assert.AreEqual(3, node.info.user_sid);
            Assert.AreEqual(2, node.info.version);
            Assert.AreEqual(1, node.keys.Count);
            Assert.AreEqual(1, node.keys[0]);
            Assert.AreEqual(1, node.vals.Count);
            Assert.AreEqual(4, node.vals[0]);

            node = primitivesConsumer.Nodes[2];
            Assert.IsNotNull(node);
            Assert.AreEqual(3, node.id);
            Assert.AreEqual(12, node.info.changeset);
            Assert.AreEqual(12, node.info.timestamp);
            Assert.AreEqual(1, node.info.uid);
            Assert.AreEqual(3, node.info.user_sid);
            Assert.AreEqual(3, node.info.version);
            Assert.AreEqual(0, node.keys.Count);
            Assert.AreEqual(0, node.vals.Count);
        }