Esempio n. 1
0
        public void VectorTile_Names()
        {
            VectorTile v = new VectorTile(9, 112, 195);

            v.SetData(File.ReadAllBytes(@".\data\9.112.195.pbf"));
            CollectionAssert.AreEquivalent(new List <string>()
            {
                "world"
            }, v.Names().ToList());
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public void VectorTile_Query()
        {
            VectorTile v = new VectorTile(9, 112, 195);

            byte[] bytes = File.ReadAllBytes(@".\data\9.112.195.pbf");
            v.SetData(bytes);
            IEnumerable <VectorQueryResult> results = v.Query(-100.8576, 39.1181);
            VectorQueryResult result = results.ToList()[0];

            Assert.AreEqual("world", result.Layer);
            Assert.AreEqual(0, result.Distance);
            Assert.AreEqual(207, result.Feature.Id());
            IDictionary <string, object> attributes = result.Feature.Attributes();

            Assert.AreEqual("United States", (string)attributes["NAME"]);
        }
Esempio n. 4
0
        public void VectorTile_ToJSON()
        {
            VectorTile v = new VectorTile(9, 112, 195);

            byte[] bytes = File.ReadAllBytes(@".\data\9.112.195.pbf");
            v.SetData(bytes);
            IEnumerable <VectorTileLayer> vtJSON = v.ToJSON();
            string json = JsonConvert.SerializeObject(
                vtJSON,
                new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });
            string expected = @"[{""Features"":[{""Properties"":{""AREA"":915896,""FIPS"":""US"",""ISO2"":""US"",""ISO3"":""USA"",""LAT"":39.622,""LON"":-98.606,""NAME"":""United States"",""POP2005"":299846449,""REGION"":19,""SUBREGION"":21,""UN"":840},""Geometry"":[9,8192,0,58,0,0,0,8192,0,8191,0,8192,0,0,8191,0,0,8191,15],""Type"":3,""Id"":207}],""Version"":1,""Extent"":4096,""Name"":""world""}]";

            Assert.AreEqual(expected, json);
        }
Esempio n. 5
0
        public void VectorTile_AddData()
        {
            VectorTile v = new VectorTile(9, 112, 195);

            byte[] bytes = File.ReadAllBytes(@".\data\9.112.195.pbf");
            v.SetData(bytes);
            v.AddData(bytes);
            Assert.IsFalse(v.Empty());
            Assert.IsTrue(v.Painted());
            CollectionAssert.AreEquivalent(new List <string>()
            {
                "world", "world"
            }, v.Names().ToList());
            byte[] actual = v.GetData();
            Assert.AreEqual(bytes.Length * 2, actual.Length);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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")));
        }
Esempio n. 8
0
 public void VectorTile_Names()
 {
     VectorTile v = new VectorTile(9,112,195);
     v.SetData(File.ReadAllBytes(@".\data\9.112.195.pbf"));
     CollectionAssert.AreEquivalent(new List<string>() { "world" }, v.Names().ToList());
 }
Esempio n. 9
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);
 }
Esempio 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);
        }
Esempio 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")));
        }
Esempio n. 12
0
 public void VectorTile_Query()
 {
     VectorTile v = new VectorTile(9, 112, 195);
     byte[] bytes = File.ReadAllBytes(@".\data\9.112.195.pbf");
     v.SetData(bytes);
     IEnumerable<VectorQueryResult> results = v.Query(-100.8576, 39.1181);
     VectorQueryResult result = results.ToList()[0];
     Assert.AreEqual("world", result.Layer);
     Assert.AreEqual(0, result.Distance);
     Assert.AreEqual(207, result.Feature.Id());
     IDictionary<string, object> attributes = result.Feature.Attributes();
     Assert.AreEqual("United States", (string)attributes["NAME"]);
 }
Esempio n. 13
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);
        }
Esempio n. 14
0
 public void VectorTile_ToJSON()
 {
     VectorTile v = new VectorTile(9, 112, 195);
     byte[] bytes = File.ReadAllBytes(@".\data\9.112.195.pbf");
     v.SetData(bytes);
     IEnumerable<VectorTileLayer> vtJSON = v.ToJSON();
     string json = JsonConvert.SerializeObject(
         vtJSON,
         new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
     string expected = @"[{""Features"":[{""Properties"":{""AREA"":915896,""FIPS"":""US"",""ISO2"":""US"",""ISO3"":""USA"",""LAT"":39.622,""LON"":-98.606,""NAME"":""United States"",""POP2005"":299846449,""REGION"":19,""SUBREGION"":21,""UN"":840},""Geometry"":[9,8192,0,58,0,0,0,8192,0,8191,0,8192,0,0,8191,0,0,8191,15],""Type"":3,""Id"":207}],""Version"":1,""Extent"":4096,""Name"":""world""}]";
     Assert.AreEqual(expected, json);
 }