public void VectorTile_Overzoom_Render() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Map m = new Map(256, 256); m.Load(@".\data\layer.xml"); m.ZoomToBox(-20037508.34, -20037508.34, 20037508.34, 20037508.34); VectorTile v1 = new VectorTile(0, 0, 0, 256, 256); m.Render(v1); m.ZoomToBox(-20037508.34, 0, 0, 20037508.34); VectorTile v2 = new VectorTile(1, 0, 0, 256, 256); m.Render(v2); Map renderMap = new Map(256, 256); renderMap.Load(@".\data\style.xml"); Image i1 = new Image(256, 256); Image i2 = new Image(256, 256); Dictionary <string, object> options = new Dictionary <string, object>(); options["Z"] = 1; v1.Render(renderMap, i1, options); v2.Render(renderMap, i2); //Small diff showing up between images Assert.IsTrue(i1.Compare(i2) - 500 < 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); }
public void VectorTile_AddImage() { VectorTile v = new VectorTile(1, 0, 0); byte[] bytes = File.ReadAllBytes(@".\data\world_1.0.0.png"); v.AddImage(bytes, "raster"); Assert.IsFalse(v.Empty()); Assert.IsTrue(v.Painted()); CollectionAssert.AreEquivalent(new List <string>() { "raster" }, v.Names().ToList()); Map m = new Map(256, 256); m.Load(@".\data\raster_style.xml"); Image i = new Image(256, 256); v.Render(m, i); Assert.AreEqual(0, i.Compare(Image.FromBytes(bytes))); }
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"))); }
public void VectorTile_Overzoom_Render() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Map m = new Map(256, 256); m.Load(@".\data\layer.xml"); m.ZoomToBox(-20037508.34, -20037508.34, 20037508.34, 20037508.34); VectorTile v1 = new VectorTile(0, 0, 0, 256, 256); m.Render(v1); m.ZoomToBox(-20037508.34, 0, 0, 20037508.34); VectorTile v2 = new VectorTile(1, 0, 0, 256, 256); m.Render(v2); Map renderMap = new Map(256, 256); renderMap.Load(@".\data\style.xml"); Image i1 = new Image(256, 256); Image i2 = new Image(256, 256); Dictionary<string, object> options = new Dictionary<string, object>(); options["Z"] = 1; v1.Render(renderMap, i1, options); v2.Render(renderMap, i2); //Small diff showing up between images Assert.IsTrue(i1.Compare(i2)-500 < 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); }
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"))); }
public void VectorTile_AddImage() { VectorTile v = new VectorTile(1, 0, 0); byte[] bytes = File.ReadAllBytes(@".\data\world_1.0.0.png"); v.AddImage(bytes, "raster"); Assert.IsFalse(v.Empty()); Assert.IsTrue(v.Painted()); CollectionAssert.AreEquivalent(new List<string>() { "raster" }, v.Names().ToList()); Map m = new Map(256, 256); m.Load(@".\data\raster_style.xml"); Image i = new Image(256, 256); v.Render(m, i); Assert.AreEqual(0,i.Compare(Image.FromBytes(bytes))); }
public byte[] Render(Coord coord, string format, int tileWidth, int tileHeight) { byte[] tileBytes = this._tileSource.GetTile(coord, "pbf"); // Uncompress bytes if (tileBytes.Length > 0) { tileBytes = Decompress(tileBytes); } // Set vector tile bytes // mapnik vector tile assumes top left origin int y = coord.Y; if (!coord.TopOrigin) y = this._tileSource.GridSet.GridHeight(coord.Z) - coord.Y - 1; VectorTile vTile = new VectorTile(coord.Z, coord.X, y, Convert.ToUInt32(tileWidth), Convert.ToUInt32(tileHeight)); vTile.SetBytes(tileBytes); // Get coord envelope Envelope envelope = this._tileSource.GridSet.CoordToEnvelope(coord); // Lock map object for rendering // TO DO: better strategy is to create a pool of map objects lock (mapLock) { _map.Width = Convert.ToUInt32(tileWidth); _map.Height = Convert.ToUInt32(tileHeight); _map.ZoomToBox(envelope.Minx, envelope.Miny, envelope.Maxx, envelope.Maxy); Image img = new Image(Convert.ToInt32(_map.Width), Convert.ToInt32(_map.Height)); vTile.Render(_map, img); format = format.ToLower(); if (format == "png" || format == "jpg") { if (format == "png") { format = this._pngOptions; } if (format == "jpg") { format = this._jpegOptions; } return img.Encode(format); } // Format not expected so throw exception throw new InvalidTileFormatException( string.Format("Invalid tile FORMAT {0}", format) ); } }