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 Geometry_ToWKT() { string input = @"{ type: ""Feature"", properties: {}, geometry: { type: ""Polygon"", coordinates: [[[1,1],[1,2],[2,2],[2,1],[1,1]]] } }"; JObject feature = JObject.Parse(input); Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "csv.input")); Dictionary <string, object> options = new Dictionary <string, object>() { { "type", "csv" }, { "inline", "geojson\n'" + feature["geometry"].ToString(Formatting.None) + "'" } }; Datasource ds = new Datasource(options); Feature f = ds.Featureset().Next(); string expected = "POLYGON((1 1,1 2,2 2,2 1,1 1))"; Assert.AreEqual(expected, f.Geometry().ToWKT()); }
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]); } }
public void Geometry_ToWKB() { string input = @"{ type: ""Feature"", properties: {}, geometry: { type: ""Polygon"", coordinates: [[[1,1],[1,2],[2,2],[2,1],[1,1]]] } }"; JObject feature = JObject.Parse(input); Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "csv.input")); Dictionary <string, object> options = new Dictionary <string, object>() { { "type", "csv" }, { "inline", "geojson\n'" + feature["geometry"].ToString(Formatting.None) + "'" } }; Datasource ds = new Datasource(options); Feature f = ds.Featureset().Next(); string hex = "01030000000100000005000000000000000000f03f000000000000f03f000000000000f03f0000000000000040000000000000004000000000000000400000000000000040000000000000f03f000000000000f03f000000000000f03f"; byte[] expected = Enumerable.Range(0, hex.Length) .Where(x => x % 2 == 0) .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) .ToArray(); byte[] actual = f.Geometry().ToWKB(); CollectionAssert.AreEqual(expected, actual); }
public void Grid_Encode_Resolution() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Map m = new Map(256, 256); m.Load(@".\data\test.xml"); m.ZoomAll(); Grid g1 = new Grid(256, 256); m.Render(g1); List <string> data = (List <string>)g1.Encode()["grid"]; Assert.AreEqual(64, data.Count()); Assert.AreEqual(64, data[0].Length); Grid g2 = new Grid(256, 256); m.Render(g2); var options = new Dictionary <string, object>() { { "Resolution", 1 } }; data = (List <string>)g1.Encode(options)["grid"]; Assert.AreEqual(256, data.Count()); Assert.AreEqual(256, data[0].Length); }
public void Grid_Painted() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Grid g = new Grid(256, 256); Assert.IsFalse(g.Painted()); Map m = new Map(256, 256); Layer l = new Layer("test"); m.AddLayer(l); m.Render(g); Assert.IsFalse(g.Painted()); m.Clear(); m.Load(@".\data\test.xml"); m.ZoomAll(); var options = new Dictionary <string, object>() { { "Fields", new List <string>() { "FIPS" } }, { "Layer", "world" } }; m.Render(g); Assert.IsTrue(g.Painted()); }
public void Grid_Encode() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Map m = new Map(256, 256); m.Load(@".\data\test.xml"); m.ZoomAll(); Grid g = new Grid(256, 256); var options = new Dictionary <string, object>() { { "Fields", new List <string>() { "FIPS" } }, { "Layer", "world" } }; m.Render(g, options); Dictionary <string, object> UTFGridDict = g.Encode(); Assert.AreEqual(UTFGridDict.Keys.Count, 3); //Test for keys List <string> keyList = (List <string>)UTFGridDict["keys"]; Assert.AreNotEqual(keyList.Count, 0); //Test for data Dictionary <string, object> dataDict = (Dictionary <string, object>)UTFGridDict["data"]; Assert.AreNotEqual(dataDict.Count, 0); //data count should equal keys + 1 Assert.AreEqual(keyList.Count, dataDict.Count + 1); }
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); }
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); }
public void Plugins_Init() { Mapnik.RegisterDefaultInputPlugins(); List <string> ds = Mapnik.Datasources().ToList(); Assert.IsTrue(ds.Count > 0); //Should return false if we try to re-register plugins Assert.IsFalse(Mapnik.RegisterDatasources(Mapnik.Paths["InputPlugins"])); }
public void Map_QueryMapPoint_SingleLayer() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Map m = new Map(256, 256); m.Load(@".\data\test.xml"); m.ZoomAll(); Dictionary <string, object> expected = new Dictionary <string, object>() { { "AREA", 915896L }, { "FIPS", "US" }, { "ISO2", "US" }, { "ISO3", "USA" }, { "LAT", 39.622 }, { "LON", -98.606 }, { "NAME", "United States" }, { "POP2005", 299846449L }, { "REGION", 19L }, { "SUBREGION", 21L }, { "UN", 840L } }; IEnumerable <MapQueryResult> r; MapQueryResult mqr; Dictionary <string, object> actual; //query by layer name r = m.QueryMapPoint(55, 130, "world"); Assert.AreEqual(r.Count(), 1); mqr = r.ToList()[0]; Assert.AreEqual(mqr.Layer, "world"); actual = new Dictionary <string, object>(mqr.Featureset.Next().Attributes()); CollectionAssert.AreEquivalent(expected, actual); //query by layer index r = m.QueryMapPoint(55, 130, 0); Assert.AreEqual(r.Count(), 1); mqr = r.ToList()[0]; Assert.AreEqual(mqr.Layer, "world"); actual = new Dictionary <string, object>(mqr.Featureset.Next().Attributes()); CollectionAssert.AreEquivalent(expected, actual); //query all //query by layer name r = r = m.QueryMapPoint(55, 130); Assert.AreEqual(r.Count(), 1); mqr = r.ToList()[0]; Assert.AreEqual(mqr.Layer, "world"); actual = new Dictionary <string, object>(mqr.Featureset.Next().Attributes()); CollectionAssert.AreEquivalent(expected, actual); }
public void VectorTile_IsSolid() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Map m = new Map(256, 256); m.Load(@".\data\layer.xml"); m.Extent = new double[] { -11271098.442818949, 4696291.017841229, -11192826.925854929, 4774562.534805249 }; VectorTile v = new VectorTile(9, 112, 195); m.Render(v); Assert.IsTrue(v.Painted()); Assert.AreEqual("world", v.IsSolid()); }
public void Datasource_Creation() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Dictionary <string, object> options = new Dictionary <string, object>() { { "type", "shape" }, { "file", @".\data\world_merc.shp" } }; Datasource d = new Datasource(options); string expectedType = "vector"; string expectedEncoding = "utf-8"; string expectedGeomType = "polygon"; Dictionary <string, string> expectedFields = new Dictionary <string, string>() { { "FIPS", "String" }, { "ISO2", "String" }, { "ISO3", "String" }, { "UN", "Number" }, { "NAME", "String" }, { "AREA", "Number" }, { "POP2005", "Number" }, { "REGION", "Number" }, { "SUBREGION", "Number" }, { "LON", "Number" }, { "LAT", "Number" } }; double[] expectedExtent = new double[] { -20037508.342789248, -8283343.6938826973, 20037508.342789244, 18365151.363070473 }; Dictionary <string, object> p = new Dictionary <string, object>(d.Paramemters()); CollectionAssert.AreEquivalent(p, options); double[] e = d.Extent(); CollectionAssert.AreEqual(e, expectedExtent); IDictionary <string, object> desc = d.Describe(); Assert.AreEqual(desc["type"], expectedType); Assert.AreEqual(desc["encoding"], expectedEncoding); Assert.AreEqual(desc["geometry_type"], expectedGeomType); CollectionAssert.AreEquivalent((Dictionary <string, string>)desc["fields"], expectedFields); }
public void Font_GlobalFonts() { Mapnik.RegisterDefaultFonts(); Mapnik.RegisterSystemFonts(); IDictionary <string, string> files = Mapnik.FontFiles(); IEnumerable <string> fonts = Mapnik.Fonts(); Assert.IsTrue(fonts.Count() > 0); Assert.IsTrue(files.Count() > 0); CollectionAssert.AreEquivalent(files.Keys.ToList(), fonts.ToList()); // Registering system fonts should always fail on retry Assert.IsFalse(Mapnik.RegisterSystemFonts()); }
public void GridView_GetPixel() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Map m = new Map(256, 256); m.Load(@".\data\test.xml"); m.ZoomAll(); Grid g = new Grid(256, 256); m.Render(g); GridView v = g.View(0, 0, 256, 256); long pixel = v.GetPixel(25, 100); Assert.AreEqual(207, pixel); }
public void Geometry_ToJSON() { string expected = @"{""type"":""Polygon"",""coordinates"":[[[1,1],[1,2],[2,2],[2,1],[1,1]]]}"; Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "csv.input")); var options = new Dictionary <string, object>() { { "type", "csv" }, { "inline", "geojson\n'" + expected + "'" } }; Datasource ds = new Datasource(options); Feature f = ds.Featureset().Next(); string actual = f.Geometry().ToJSON(); Assert.AreEqual(expected, actual); }
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 Image_Painted() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Image i = new Image(256, 256); Assert.IsFalse(i.Painted()); Map m = new Map(256, 256); m.ZoomAll(); m.Render(i); Assert.IsFalse(i.Painted()); m.Load(@".\data\test.xml"); m.ZoomAll(); m.Render(i); Assert.IsTrue(i.Painted()); }
public void Grid_Fields() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Map m = new Map(256, 256); m.Load(@".\data\test.xml"); m.ZoomAll(); Grid g = new Grid(256, 256); List <string> expected = new List <string>() { "FIPS" }; var options = new Dictionary <string, object>() { { "Fields", expected } }; m.Render(g, options); CollectionAssert.AreEquivalent(expected, g.Fields().ToList()); }
public void Layer_Describe() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Dictionary <string, object> options = new Dictionary <string, object>() { { "type", "shape" }, { "file", @".\data\world_merc.shp" } }; Datasource ds = new Datasource(options); Layer l = new Layer("layer", "+init=epsg:4326"); l.Datasource = ds; IDictionary <string, object> d = l.Describe(); Assert.AreEqual((string)d["name"], "layer"); Assert.AreEqual((string)d["srs"], "+init=epsg:4326"); CollectionAssert.AreEquivalent(((List <string>)d["styles"]), new List <string>()); CollectionAssert.AreEquivalent((Dictionary <string, object>)d["datasource"], options); }
public void Map_QueryMapPoint_MultipleLayers() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Map m = new Map(256, 256); m.Load(@".\data\test.xml"); Layer l = new Layer("world2"); Datasource d = new Datasource( new Dictionary <string, object>() { { "type", "shape" }, { "file", @".\data\world_merc.shp" } } ); l.Datasource = d; m.AddLayer(l); m.ZoomAll(); IEnumerable <MapQueryResult> r; //query single layer r = m.QueryMapPoint(55, 130, "world2"); Assert.AreEqual(r.Count(), 1); MapQueryResult mqr = r.ToList()[0]; Assert.AreEqual(mqr.Layer, "world2"); //query all r = m.QueryMapPoint(55, 130); Assert.AreEqual(r.Count(), 2); MapQueryResult mqr1 = r.ToList()[0]; Assert.AreEqual(mqr1.Layer, "world"); MapQueryResult mqr2 = r.ToList()[1]; Assert.AreEqual(mqr2.Layer, "world2"); }
public void Featureset_Creation() { Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); Dictionary <string, object> options = new Dictionary <string, object>() { { "type", "shape" }, { "file", @".\data\world_merc.shp" } }; Datasource d = new Datasource(options); Featureset fs = d.Featureset(); Feature feature = fs.Next(); Dictionary <string, object> attr = new Dictionary <string, object>(feature.Attributes()); Dictionary <string, object> expectedAttr = new Dictionary <string, object>() { { "AREA", 44L }, { "FIPS", "AC" }, { "ISO2", "AG" }, { "ISO3", "ATG" }, { "LAT", 17.078 }, { "LON", -61.783 }, { "NAME", "Antigua and Barbuda" }, { "POP2005", 83039L }, { "REGION", 19L }, { "SUBREGION", 29L }, { "UN", 28L } }; CollectionAssert.AreEquivalent(attr, expectedAttr); int count = 1; while (fs.Next() != null) { count++; } Assert.AreEqual(count, 245); }
public void Geometry_ToJSON_ProjTransform() { string expected = @"{""type"":""Polygon"",""coordinates"":[[[1,1],[1,2],[2,2],[2,1],[1,1]]]}"; Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "csv.input")); var options = new Dictionary <string, object>() { { "type", "csv" }, { "inline", "geojson\n'" + expected + "'" } }; Datasource ds = new Datasource(options); Feature f = ds.Featureset().Next(); string actual = f.Geometry().ToJSON(); Assert.AreEqual(expected, actual); Projection src = new Projection("+init=epsg:4326"); Projection dest = new Projection("+init=epsg:3857"); ProjTransform tran = new ProjTransform(src, dest); string transformed = f.Geometry().ToJSON(tran); Assert.AreNotEqual(expected, transformed); }
public void GridView_IsSolid() { Map m = new Map(256, 256); m.AddLayer(new Layer("test")); m.ZoomAll(); Grid g = new Grid(256, 256); m.Render(g); GridView v1 = g.View(0, 0, 256, 256); Assert.IsTrue(v1.IsSolid()); m.Clear(); g.Clear(); Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "shape.input")); m.Load(@".\data\test.xml"); m.ZoomAll(); m.Render(g); GridView v2 = g.View(0, 0, 256, 256); Assert.IsFalse(v2.IsSolid()); }
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 Feature_ToJSON() { string input = @"{ type: ""Feature"", properties: {}, geometry: { type: ""Polygon"", coordinates: [[[1,1],[1,2],[2,2],[2,1],[1,1]]] } }"; JObject expected = JObject.Parse(input); Mapnik.RegisterDatasource(Path.Combine(Mapnik.Paths["InputPlugins"], "csv.input")); Dictionary <string, object> options = new Dictionary <string, object>() { { "type", "csv" }, { "inline", "geojson\n'" + expected["geometry"].ToString(Formatting.None) + "'" } }; Datasource ds = new Datasource(options); Feature f = ds.Featureset().Next(); JObject feature = JObject.Parse(f.ToJSON()); Assert.AreEqual(expected["type"], feature["type"]); Assert.AreEqual(((JObject)expected["properties"]).Count, ((JObject)feature["properties"]).Count); Assert.AreEqual(expected["geometry"]["type"], feature["geometry"]["type"]); JArray coords = (JArray)expected["geometry"]["coordinates"][0]; for (int i = 0; i < coords.Count; i++) { JArray coord1 = (JArray)expected["geometry"]["coordinates"][0][i]; JArray coord2 = (JArray)feature["geometry"]["coordinates"][0][i]; CollectionAssert.AreEquivalent(coord1.ToObject <List <double> >(), coord2.ToObject <List <double> >()); } }