Ejemplo n.º 1
0
        public void VectorTile_OverzoomComposite()
        {
            Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input"));
            Map m = new Map(256, 256);

            m.Load(@".\data\layer.xml");

            VectorTile v1 = new VectorTile(1, 0, 0, 256, 256);

            m.ZoomToBox(-20037508.34, 0, 0, 20037508.34);
            m.Render(v1);
            int v1before = v1.GetData().Length;

            VectorTile v2 = new VectorTile(0, 0, 0, 256, 256);

            m.ZoomToBox(-20037508.34, -20037508.34, 20037508.34, 20037508.34);
            m.Render(v2);

            v1.Composite(new List <VectorTile>()
            {
                v2
            });
            int v1after = v1.GetData().Length;

            //composite bytes will actually be a little bit bigger than 2* original
            //Assert.AreEqual(v1before * 2, v1after);
        }
Ejemplo n.º 2
0
        public void VectorTile_SimpleComposite()
        {
            Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input"));
            Map m = new Map(256, 256);

            m.Load(@".\data\layer.xml");
            m.ZoomAll();

            VectorTile v1 = new VectorTile(0, 0, 0, 256, 256);

            m.Render(v1);
            int v1before = v1.GetData().Length;

            VectorTile v2 = new VectorTile(0, 0, 0, 256, 256);

            m.Render(v2);

            v1.Composite(new List <VectorTile>()
            {
                v2
            });
            int v1after = v1.GetData().Length;

            Assert.AreEqual(v1before * 2, v1after);
        }
Ejemplo n.º 3
0
        public void VectorTile_GeoJSON()
        {
            Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "geojson.input"));
            string     json = @"{""type"":""FeatureCollection"",""name"":""layer"",""features"":[{""type"":""Feature"",""geometry"":{""type"":""Point"",""coordinates"":[-121.9921875,47.9899216674142]},""properties"":{""name"":""geojson data""}}]}";
            VectorTile v    = new VectorTile(0, 0, 0);

            v.AddGeoJSON(json, "layer");
            byte[] bytes = v.GetData();
            Assert.AreEqual(53, bytes.Length);
            Assert.IsFalse(v.Empty());
            Assert.IsTrue(v.Painted());
            CollectionAssert.AreEquivalent(new List <string>()
            {
                "layer"
            }, v.Names().ToList());

            //ToGeoJSON
            dynamic expected = JObject.Parse(json);
            var     results  = new List <JObject>()
            {
                JObject.Parse(v.ToGeoJSON("layer")),
                JObject.Parse(v.ToGeoJSON(0))
            };

            foreach (dynamic actual in results)
            {
                Assert.AreEqual(expected.FeatureCollection, actual.FeatureCollection);
                Assert.AreEqual(expected.features[0].properties.name, actual.features[0].properties.name);
                Assert.AreEqual(expected.features[0].geometry.type, actual.features[0].geometry.type);
                Assert.AreEqual(expected.features[0].geometry.coordinates[0], actual.features[0].geometry.coordinates[0]);
                Assert.AreEqual(expected.features[0].geometry.coordinates[1], actual.features[0].geometry.coordinates[1]);
            }
        }
Ejemplo n.º 4
0
        public void VectorTile_SimpleComposite()
        {
            Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input"));
            Map m = new Map(256, 256);
            m.Load(@".\data\layer.xml");
            m.ZoomAll();

            VectorTile v1 = new VectorTile(0, 0, 0, 256, 256);
            m.Render(v1);
            int v1before = v1.GetData().Length;

            VectorTile v2 = new VectorTile(0, 0, 0, 256, 256);
            m.Render(v2);

            v1.Composite(new List<VectorTile>() { v2 });
            int v1after = v1.GetData().Length;

            Assert.AreEqual(v1before * 2, v1after);
        }
Ejemplo n.º 5
0
 public void VectorTile_Init()
 {
     VectorTile v = new VectorTile(0, 0, 0);
     Assert.AreEqual(256, v.Width());
     Assert.AreEqual(256, v.Height());
     Assert.IsFalse(v.Painted());
     Assert.AreEqual("", v.IsSolid());
     Assert.IsTrue(v.Empty());
     Assert.AreEqual(0, v.GetData().Length);
 }
Ejemplo n.º 6
0
        public void VectorTile_Init()
        {
            VectorTile v = new VectorTile(0, 0, 0);

            Assert.AreEqual(256, v.Width());
            Assert.AreEqual(256, v.Height());
            Assert.IsFalse(v.Painted());
            Assert.AreEqual("", v.IsSolid());
            Assert.IsTrue(v.Empty());
            Assert.AreEqual(0, v.GetData().Length);
        }
Ejemplo n.º 7
0
        public void VectorTile_GetSetData()
        {
            VectorTile v = new VectorTile(9, 112, 195);

            byte[] bytes = File.ReadAllBytes(@".\data\9.112.195.pbf");
            v.SetData(bytes);
            Assert.IsFalse(v.Empty());
            Assert.IsTrue(v.Painted());
            byte[] actual = v.GetData();
            CollectionAssert.AreEquivalent(bytes, actual);
        }
Ejemplo n.º 8
0
        public void VectorTile_OverzoomComposite()
        {
            Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input"));
            Map m = new Map(256, 256);
            m.Load(@".\data\layer.xml");

            VectorTile v1 = new VectorTile(1, 0, 0, 256, 256);
            m.ZoomToBox(-20037508.34, 0, 0, 20037508.34);
            m.Render(v1);
            int v1before = v1.GetData().Length;

            VectorTile v2 = new VectorTile(0, 0, 0, 256, 256);
            m.ZoomToBox(-20037508.34, -20037508.34, 20037508.34, 20037508.34);
            m.Render(v2);

            v1.Composite(new List<VectorTile>() { v2 });
            int v1after = v1.GetData().Length;

            //composite bytes will actually be a little bit bigger than 2* original
            //Assert.AreEqual(v1before * 2, v1after);
        }
Ejemplo n.º 9
0
        public void VectorTile_Clear()
        {
            VectorTile v = new VectorTile(9, 112, 195);

            byte[] bytes = File.ReadAllBytes(@".\data\9.112.195.pbf");
            v.SetData(bytes);
            Assert.IsFalse(v.Empty());
            Assert.IsTrue(v.Painted());
            CollectionAssert.AreEquivalent(new List <string>()
            {
                "world"
            }, v.Names().ToList());
            byte[] actual = v.GetData();
            Assert.AreEqual(bytes.Length, actual.Length);

            v.Clear();
            Assert.IsTrue(v.Empty());
            Assert.IsFalse(v.Painted());
            Assert.AreEqual("", v.IsSolid());
            CollectionAssert.AreEquivalent(new List <string>(), v.Names().ToList());
            actual = v.GetData();
            Assert.AreEqual(0, actual.Length);
        }
Ejemplo n.º 10
0
        public void VectorTile_Render_Grid()
        {
            Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input"));
            Map m = new Map(256, 256);

            m.Load(@".\data\layer.xml");
            m.Extent = new double[] { -20037508.34, 0, 0, 20037508.34 };
            VectorTile v = new VectorTile(1, 0, 0);

            m.Render(v);

            VectorTile v2 = new VectorTile(1, 0, 0);

            v2.SetData(v.GetData());

            Map m2 = new Map(256, 256);

            m2.Load(@".\data\style.xml");
            Grid g       = new Grid(256, 256);
            var  options = new Dictionary <string, object>()
            {
                { "Fields", new List <string>()
                  {
                      "FIPS"
                  } },
                { "Layer", "world" }
            };

            v2.Render(m2, g, options);
            Dictionary <string, object> grid = g.Encode();

            Assert.AreEqual(grid.Keys.Count, 3);

            //Test for keys
            List <string> keyList = (List <string>)grid["keys"];

            Assert.AreNotEqual(keyList.Count, 0);

            //Test for data
            Dictionary <string, object> dataDict = (Dictionary <string, object>)grid["data"];

            Assert.AreNotEqual(dataDict.Count, 0);

            //data count should equal keys + 1
            Assert.AreEqual(keyList.Count, dataDict.Count + 1);
        }
Ejemplo n.º 11
0
        public void VectorTile_Render_Image()
        {
            Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input"));
            Map m = new Map(256, 256);

            m.Load(@".\data\layer.xml");
            m.Extent = new double[] { -20037508.34, 0, 0, 20037508.34 };
            VectorTile v = new VectorTile(1, 0, 0);

            m.Render(v);

            VectorTile v2 = new VectorTile(1, 0, 0);

            v2.SetData(v.GetData());

            Map m2 = new Map(256, 256);

            m2.Load(@".\data\style.xml");
            Image i = new Image(256, 256);

            v2.Render(m2, i);
            Assert.AreEqual(0, i.Compare(Image.Open(@".\data\world_1.0.0.png")));
        }
Ejemplo n.º 12
0
 public void VectorTile_GetSetData()
 {
     VectorTile v = new VectorTile(9,112,195);
     byte[] bytes = File.ReadAllBytes(@".\data\9.112.195.pbf");
     v.SetData(bytes);
     Assert.IsFalse(v.Empty());
     Assert.IsTrue(v.Painted());
     byte[] actual = v.GetData();
     CollectionAssert.AreEquivalent(bytes, actual);
 }
Ejemplo n.º 13
0
        public void VectorTile_Render_Grid()
        {
            Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input"));
            Map m = new Map(256, 256);
            m.Load(@".\data\layer.xml");
            m.Extent = new double[] { -20037508.34, 0, 0, 20037508.34 };
            VectorTile v = new VectorTile(1, 0, 0);
            m.Render(v);

            VectorTile v2 = new VectorTile(1, 0, 0);
            v2.SetData(v.GetData());

            Map m2 = new Map(256, 256);
            m2.Load(@".\data\style.xml");
            Grid g = new Grid(256, 256);
            var options = new Dictionary<string, object>()
            {
                {"Fields", new List<string>() { "FIPS" } },
                {"Layer", "world" }
            };
            v2.Render(m2, g, options);
            Dictionary<string, object > grid = g.Encode();
            Assert.AreEqual(grid.Keys.Count, 3);

            //Test for keys
            List<string> keyList = (List<string>)grid["keys"];
            Assert.AreNotEqual(keyList.Count, 0);

            //Test for data
            Dictionary<string, object> dataDict = (Dictionary<string, object>)grid["data"];
            Assert.AreNotEqual(dataDict.Count, 0);

            //data count should equal keys + 1
            Assert.AreEqual(keyList.Count, dataDict.Count + 1);
        }
Ejemplo n.º 14
0
        public void VectorTile_Render_Image()
        {
            Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input"));
            Map m = new Map(256, 256);
            m.Load(@".\data\layer.xml");
            m.Extent = new double[] { -20037508.34, 0, 0, 20037508.34 };
            VectorTile v = new VectorTile(1, 0, 0);
            m.Render(v);

            VectorTile v2 = new VectorTile(1, 0, 0);
            v2.SetData(v.GetData());

            Map m2 = new Map(256, 256);
            m2.Load(@".\data\style.xml");
            Image i = new Image(256, 256);
            v2.Render(m2, i);
            Assert.AreEqual(0,i.Compare(Image.Open(@".\data\world_1.0.0.png")));
        }
Ejemplo n.º 15
0
        public void VectorTile_Clear()
        {
            VectorTile v = new VectorTile(9,112,195);
            byte[] bytes = File.ReadAllBytes(@".\data\9.112.195.pbf");
            v.SetData(bytes);
            Assert.IsFalse(v.Empty());
            Assert.IsTrue(v.Painted());
            CollectionAssert.AreEquivalent(new List<string>() { "world" }, v.Names().ToList());
            byte[] actual = v.GetData();
            Assert.AreEqual(bytes.Length, actual.Length);

            v.Clear();
            Assert.IsTrue(v.Empty());
            Assert.IsFalse(v.Painted());
            Assert.AreEqual("",v.IsSolid());
            CollectionAssert.AreEquivalent(new List<string>(), v.Names().ToList());
            actual = v.GetData();
            Assert.AreEqual(0, actual.Length);
        }
Ejemplo n.º 16
0
        public void VectorTile_GeoJSON()
        {
            Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "geojson.input"));
            string json = @"{""type"":""FeatureCollection"",""name"":""layer"",""features"":[{""type"":""Feature"",""geometry"":{""type"":""Point"",""coordinates"":[-121.9921875,47.9899216674142]},""properties"":{""name"":""geojson data""}}]}";
            VectorTile v = new VectorTile(0, 0, 0);
            v.AddGeoJSON(json, "layer");
            byte[] bytes = v.GetData();
            Assert.AreEqual(53, bytes.Length);
            Assert.IsFalse(v.Empty());
            Assert.IsTrue(v.Painted());
            CollectionAssert.AreEquivalent(new List<string>() { "layer" }, v.Names().ToList());

            //ToGeoJSON
            dynamic expected = JObject.Parse(json);
            var results = new List<JObject>()
            {
                JObject.Parse(v.ToGeoJSON("layer")),
                JObject.Parse(v.ToGeoJSON(0))
            };
            foreach (dynamic actual in results)
            {
                Assert.AreEqual(expected.FeatureCollection, actual.FeatureCollection);
                Assert.AreEqual(expected.features[0].properties.name, actual.features[0].properties.name);
                Assert.AreEqual(expected.features[0].geometry.type, actual.features[0].geometry.type);
                Assert.AreEqual(expected.features[0].geometry.coordinates[0], actual.features[0].geometry.coordinates[0]);
                Assert.AreEqual(expected.features[0].geometry.coordinates[1], actual.features[0].geometry.coordinates[1]);
            }
        }