diff --git a/.gitignore b/.gitignore index 913dca7..8f2ffe2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ TestResults/ StyleCop.Cache nuget.exe .vscode/ +.vs/ tools/ # globs diff --git a/src/DemoConsoleApp/program.cs b/src/DemoConsoleApp/program.cs index 8f74b8f..03af6b7 100644 --- a/src/DemoConsoleApp/program.cs +++ b/src/DemoConsoleApp/program.cs @@ -16,6 +16,7 @@ public static int Main(string[] args) { string vtIn = string.Empty; + bool validate = true; uint? clipBuffer = null; bool outGeoJson = false; ulong? zoom = null; @@ -41,6 +42,10 @@ public static int Main(string[] args) { parseArg(argLow.Replace("tileid:", ""), out zoom, out tileCol, out tileRow); } + else if (argLow.Contains("validate:")) + { + validate = argLow.Replace("validate:", "").Equals("true"); + } } if (!File.Exists(vtIn)) @@ -62,7 +67,7 @@ public static int Main(string[] args) var bufferedData = File.ReadAllBytes(vtIn); - VectorTile tile = new VectorTile(bufferedData); + VectorTile tile = new VectorTile(bufferedData, validate); if (outGeoJson) { @@ -79,7 +84,7 @@ public static int Main(string[] args) for (int i = 0; i < featCnt; i++) { VectorTileFeature feat = lyr.GetFeature(i, clipBuffer); - Console.WriteLine(string.Format("feature {0}: {1}", i, feat.GeometryType)); + Console.WriteLine(string.Format("feature[{0}] id:{1} geomtype:{2}", i, feat.Id, feat.GeometryType)); Dictionary props = feat.GetProperties(); foreach (var prop in props) { @@ -99,6 +104,7 @@ private static void usage() Console.WriteLine("DemoConsoleApp.exe vt: "); Console.WriteLine(""); Console.WriteLine("- vt: or vt:--.tile.mvt>"); + Console.WriteLine("- validate: validate vt contents, default:true"); Console.WriteLine("- clip: to clip geometries extending beyong the tile border"); Console.WriteLine("- out: to ouput either GeoJson or some metadata"); Console.WriteLine("- tileid:-- to pass tile id if not contained within the file name"); diff --git a/src/VectorTileReader/VectorTileFeature.cs b/src/VectorTileReader/VectorTileFeature.cs index 4fb500d..230f101 100644 --- a/src/VectorTileReader/VectorTileFeature.cs +++ b/src/VectorTileReader/VectorTileFeature.cs @@ -17,6 +17,10 @@ public class VectorTileFeature /// Parent public VectorTileFeature(VectorTileLayer layer, uint? clipBuffer = null, float scale = 1.0f) { + //set some defaults according to the spec: https://github.com/mapbox/vector-tile-spec/blob/master/2.1/vector_tile.proto + Id = 0; + GeometryType = GeomType.UNKNOWN; + _layer = layer; _clipBuffer = clipBuffer; _scale = scale; diff --git a/src/VectorTileReader/VectorTileLayer.cs b/src/VectorTileReader/VectorTileLayer.cs index 87b58fe..4188cf3 100644 --- a/src/VectorTileReader/VectorTileLayer.cs +++ b/src/VectorTileReader/VectorTileLayer.cs @@ -19,6 +19,10 @@ public class VectorTileLayer /// public VectorTileLayer() { + //set some defaults according to the spec: https://github.com/mapbox/vector-tile-spec/blob/master/2.1/vector_tile.proto + Version = 1; + Extent = 4096; + _FeaturesData = new List(); Keys = new List(); Values = new List(); diff --git a/src/VectorTileReader/VectorTileReader.cs b/src/VectorTileReader/VectorTileReader.cs index b2f8d86..6a5e76a 100644 --- a/src/VectorTileReader/VectorTileReader.cs +++ b/src/VectorTileReader/VectorTileReader.cs @@ -38,7 +38,11 @@ public VectorTileReader(byte[] data, bool validate = true) } if (data[0] == 0x1f && data[1] == 0x8b) { - throw new System.Exception("Tile data is zipped"); + throw new System.Exception("Tile data is gzipped"); + } + if (data[0] == 0x78 && (data[1] == 0x9C || data[1] == 0x01 || data[1] == 0xDA || data[1] == 0x5E)) + { + throw new System.Exception("Tile data is zlib compressed"); } _Validate = validate; @@ -239,13 +243,21 @@ private VectorTileLayer getLayer(byte[] data) { throw new System.Exception(string.Format("Layer [{0}] has no extent.", layer.Name)); } + + //commenting following check as per + //"Layer has no features, encoders should not create this, but decoders should read this still" + //https://github.com/mapbox/mvt-fixtures/blob/7e0e67ba67478fd8af63509077b000ee5cee2d6d/fixtures/025/info.json#L2 + /* if (0 == layer.FeatureCount()) { throw new System.Exception(string.Format("Layer [{0}] has no features.", layer.Name)); } + */ + //TODO: find equivalent of 'Distinct()' for NET20 #if !NET20 - if (layer.Values.Count != layer.Values.Distinct().Count()) { + if (layer.Values.Count != layer.Values.Distinct().Count()) + { throw new System.Exception(string.Format("Layer [{0}]: duplicate attribute values found", layer.Name)); } #endif diff --git a/src/VectorTiles.Tests/TestAllMVTs.cs b/src/VectorTiles.Tests/TestAllMVTs.cs new file mode 100644 index 0000000..ae1806b --- /dev/null +++ b/src/VectorTiles.Tests/TestAllMVTs.cs @@ -0,0 +1,136 @@ +using System; +using System.IO; +using Mapbox.VectorTile; +using System.Collections; +using Newtonsoft.Json.Linq; +#if WINDOWS_UWP +using Microsoft.VisualStudio.TestPlatform.UnitTestFramework; +using ATestClass = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute; +using ATestMethod = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute; +using ATestClassSetup = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.ClassInitializeAttribute; //run once per class +using ATestSetup = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestInitializeAttribute; //run before every test +using ATestDataSource = Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute; +#else +using NUnit.Framework; +using ATestClass = NUnit.Framework.TestFixtureAttribute; +using ATestMethod = NUnit.Framework.TestAttribute; +using ATestClassSetup = NUnit.Framework.OneTimeSetUpAttribute; +using ATestDataSource = NUnit.Framework.TestCaseSourceAttribute; +#endif + + +namespace VectorTiles.Tests +{ + + + [ATestClass] + public class BulkMvtTests + { + + private string _fixturesPath; + public static string _executingFolder = AppDomain.CurrentDomain.BaseDirectory; + + + [ATestClassSetup] + protected void SetUp() + { + _fixturesPath = Path.Combine(_executingFolder, "..", "test", "mvt-fixtures", "fixtures"); + } + + [ATestMethod, Order(1)] + public void FixturesPathExists() + { + Assert.True(Directory.Exists(_fixturesPath), "MVT fixtures directory exists"); + } + + + [ATestMethod, ATestDataSource(typeof(GetMVTs), "GetValidFixtureFileNames")] + public void ValidMvt(string fileName) + { + Assert.True(File.Exists(fileName), "Vector tile exists"); + byte[] data = File.ReadAllBytes(fileName); + Assert.DoesNotThrow(() => + { + VectorTile vt = new VectorTile(data); + foreach (var layerName in vt.LayerNames()) + { + var layer = vt.GetLayer(layerName); + for (int i = 0; i < layer.FeatureCount(); i++) + { + var feat = layer.GetFeature(i); + feat.GetProperties(); + } + } + }); + } + + + [ATestMethod, ATestDataSource(typeof(GetMVTs), "GetInvalidFixtureFileNames")] + public void InvalidMvt(string fileName) + { + Assert.True(File.Exists(fileName), "Vector tile exists"); + byte[] data = File.ReadAllBytes(fileName); + bool didThrow = true; + Assert.Throws(Is.InstanceOf(), () => + { + VectorTile vt = new VectorTile(data); + foreach (var layerName in vt.LayerNames()) + { + var layer = vt.GetLayer(layerName); + for (int i = 0; i < layer.FeatureCount(); i++) + { + var feat = layer.GetFeature(i); + feat.GetProperties(); + } + } + didThrow = false; + }); + Assert.True(didThrow); + } + + + } + + + + + public partial class GetMVTs + { + public static IEnumerable GetValidFixtureFileNames() + { + foreach (var testCase in getFixtureFileNames(true)) + { + yield return testCase; + } + } + + public static IEnumerable GetInvalidFixtureFileNames() + { + foreach (var testCase in getFixtureFileNames(false)) + { + yield return testCase; + } + } + + private static IEnumerable getFixtureFileNames(bool valid) + { + string path = Path.Combine(BulkMvtTests._executingFolder, "..", "test", "mvt-fixtures", "fixtures"); + + foreach (var fixtureDir in Directory.GetDirectories(path)) + { + string infoJson = Path.Combine(fixtureDir, "info.json"); + if (!File.Exists(infoJson)) { continue; } + dynamic info = JObject.Parse(File.ReadAllText(infoJson)); + if (info.validity.v2 != valid) { continue; } + yield return new TestCaseData(Path.Combine(fixtureDir, "tile.mvt")); + } + } + + + } + + + + + +} \ No newline at end of file diff --git a/src/VectorTiles.Tests/TestGeometry.cs b/src/VectorTiles.Tests/TestGeometry.cs deleted file mode 100644 index f822ca1..0000000 --- a/src/VectorTiles.Tests/TestGeometry.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Mapbox.VectorTile; -using Mapbox.VectorTile.Geometry; -using System; -using System.IO; -#if WINDOWS_UWP -using Microsoft.VisualStudio.TestPlatform.UnitTestFramework; -using ATestClass = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute; -using ATestMethod = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute; -#else -using NUnit.Framework; -using ATestClass = NUnit.Framework.TestFixtureAttribute; -using ATestMethod = NUnit.Framework.TestAttribute; -#endif - -namespace VectorTiles.Tests -{ - - - [ATestClass] - public class GeometryTests - { - - - // [ATestMethod] - // public void GeometryObjects() { - // LatLng ll = new LatLng() { Lng = 15, Lat = 48 }; - // Assert.AreEqual("48.000000/15.000000", ll.ToString(), "LatLng.ToString()"); - - // Point2d ptSE = new Point2d(4096, 4096); - // Assert.AreEqual("4096/4096", ptSE.ToString(), "Point2d.ToString()"); - - // LatLng fromPtSE = ptSE.ToLngLat(0, 0, 0, 4096); - // Assert.AreEqual(180, fromPtSE.Lng, "correct longitude"); - // Assert.AreEqual(-85.051128779806589, fromPtSE.Lat, "correct latitude"); - - // ptSE.X = 4210; - // fromPtSE = ptSE.ToLngLat(0, 0, 0, 4096); - // Assert.AreEqual(190, fromPtSE.Lng, 0.02, "correct longitude - out of bounds"); - //#if WINDOWS_UWP - // Assert.ThrowsException(() => { ptSE.ToLngLat(0, 0, 0, 04096, true); }); - //#else - // Assert.Throws(Is.InstanceOf(), () => { ptSE.ToLngLat(0, 0, 0, 04096, true); }); - //#endif - - // ptSE.X = 4096; - // ptSE.Y = 4210; - // fromPtSE = ptSE.ToLngLat(0, 0, 0, 4096); - // Assert.AreEqual(-85.844, fromPtSE.Lat, 0.02, "correct latitude - out of bounds"); - //#if WINDOWS_UWP - // Assert.ThrowsException(() => { ptSE.ToLngLat(0, 0, 0, 04096, true); }); - //#else - // Assert.Throws(Is.InstanceOf(), () => { ptSE.ToLngLat(0, 0, 0, 04096, true); }); - //#endif - // } - - - - - - } - -} \ No newline at end of file diff --git a/src/VectorTiles.Tests/TestInvalidMvtInBulk.cs b/src/VectorTiles.Tests/TestInvalidMvtInBulk.cs deleted file mode 100644 index 91a213e..0000000 --- a/src/VectorTiles.Tests/TestInvalidMvtInBulk.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.IO; -using Mapbox.VectorTile; -using System.Collections; -#if WINDOWS_UWP -using Microsoft.VisualStudio.TestPlatform.UnitTestFramework; -using ATestClass = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute; -using ATestMethod = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute; -using ATestClassSetup = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.ClassInitializeAttribute; //run once per class -using ATestSetup = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestInitializeAttribute; //run before every test -using ATestDataSource = Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute; -#else -using NUnit.Framework; -using ATestClass = NUnit.Framework.TestFixtureAttribute; -using ATestMethod = NUnit.Framework.TestAttribute; -using ATestClassSetup = NUnit.Framework.OneTimeSetUpAttribute; -using ATestDataSource = NUnit.Framework.TestCaseSourceAttribute; -#endif - - -namespace VectorTiles.Tests -{ - - - [ATestClass] - public class BulkInvalidMvtTests - { - - private string _fixturesPath; - public static string _executingFolder = AppDomain.CurrentDomain.BaseDirectory; - - - [ATestClassSetup] - protected void SetUp() - { - _fixturesPath = Path.Combine(_executingFolder, "..", "..", "..", "test", "mvt-fixtures", "fixtures", "invalid"); - } - - [ATestMethod, Order(1)] - public void FixturesPathExists() - { - Assert.True(Directory.Exists(_fixturesPath), "MVT fixtures directory exists"); - } - - - [ATestMethod, ATestDataSource(typeof(GetMVTs), "GetInValidFixtureFileName")] - public void Validate(string fileName) - { - string fullFileName = Path.Combine(_fixturesPath, fileName); - Assert.True(File.Exists(fullFileName), "Vector tile exists"); - byte[] data = File.ReadAllBytes(fullFileName); - Assert.Throws(Is.InstanceOf(), () => - { - VectorTile vt = new VectorTile(data); - foreach (var layerName in vt.LayerNames()) - { - var layer = vt.GetLayer(layerName); - for (int i = 0; i < layer.FeatureCount(); i++) - { - var feat = layer.GetFeature(i); - feat.GetProperties(); - } - } - }); - } - } - - public partial class GetMVTs - { - public static IEnumerable GetInValidFixtureFileName() - { - string path = Path.Combine(BulkInvalidMvtTests._executingFolder, "..", "..", "..", "test", "mvt-fixtures", "fixtures", "invalid"); - - foreach (var file in Directory.GetFiles(path)) - { - //return file basename only to make test description more readable - yield return new TestCaseData(Path.GetFileName(file)); - } - } - } - - - - - -} \ No newline at end of file diff --git a/src/VectorTiles.Tests/TestMvtInBulk.cs b/src/VectorTiles.Tests/TestMvtInBulk.cs deleted file mode 100644 index 36d5e89..0000000 --- a/src/VectorTiles.Tests/TestMvtInBulk.cs +++ /dev/null @@ -1,321 +0,0 @@ -using System; -using NUnit.Framework; -using System.IO; -using System.Linq; -using System.Diagnostics; -using System.Collections.Generic; -using Mapbox.VectorTile; -using System.Collections; -using Mapbox.VectorTile.Geometry; -using Mapbox.VectorTile.ExtensionMethods; - - - -namespace VectorTiles.Tests -{ - - - [TestFixture] - public class BulkMvtTests - { - - - private string fixturesPath; - - - [OneTimeSetUp] - protected void SetUp() - { - fixturesPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "test", "mvt-fixtures", "fixtures", "valid"); - } - - - [Test, Order(1)] - public void FixturesPathExists() - { - Assert.True(Directory.Exists(fixturesPath), "MVT fixtures directory exists"); - } - - - [Test, TestCaseSource(typeof(GetMVTs), "GetFixtureFileName")] - public void LazyDecoding(string fileName) - { - string fullFileName = Path.Combine(fixturesPath, fileName); - Assert.True(File.Exists(fullFileName), "Vector tile exists"); - byte[] data = File.ReadAllBytes(fullFileName); - VectorTile vt = new VectorTile(data); - foreach (var layerName in vt.LayerNames()) - { - VectorTileLayer layer = vt.GetLayer(layerName); - for (int i = 0; i < layer.FeatureCount(); i++) - { - VectorTileFeature feat = layer.GetFeature(i); - var properties = feat.GetProperties(); - foreach (var prop in properties) - { - Assert.AreEqual(prop.Value, feat.GetValue(prop.Key), "Property values match"); - } - foreach (var geomPart in feat.Geometry()) - { - foreach (var coord in geomPart) - { - //TODO add Assert - } - } - } - } - string geojson = vt.ToGeoJson(0, 0, 0); - Assert.GreaterOrEqual(geojson.Length, 30, "geojson >= 30 chars"); - } - - - [Test] - public void DifferentPoint2dTypesAndScaling() - { - string fullFileName = Path.Combine(fixturesPath, "Feature-single-linestring.mvt"); - byte[] data = File.ReadAllBytes(fullFileName); - VectorTile vt = new VectorTile(data); - foreach (var layerName in vt.LayerNames()) - { - VectorTileLayer layer = vt.GetLayer(layerName); - for (int i = 0; i < layer.FeatureCount(); i++) - { - - VectorTileFeature featLong = layer.GetFeature(i); - foreach (var geomPart in featLong.Geometry()) - { - foreach (var coord in geomPart) - { - Debug.WriteLine("long: {0}/{1}", coord.X, coord.Y); - } - Assert.AreEqual(2L, geomPart[0].X); - Assert.AreEqual(2L, geomPart[0].Y); - Assert.AreEqual(2L, geomPart[1].X); - Assert.AreEqual(10L, geomPart[1].Y); - Assert.AreEqual(10L, geomPart[2].X); - Assert.AreEqual(10L, geomPart[2].Y); - } - - // don't clip, as this might change order of vertices - // test 'scale' on the VectorTileFeature constructor - VectorTileFeature featInt = layer.GetFeature(i, null, 1.5f); - foreach (var geomPart in featInt.Geometry()) - { - foreach (var coord in geomPart) - { - Debug.WriteLine("integer: {0}/{1}", coord.X, coord.Y); - } - Assert.AreEqual(3, geomPart[0].X); - Assert.AreEqual(3, geomPart[0].Y); - Assert.AreEqual(3, geomPart[1].X); - Assert.AreEqual(15, geomPart[1].Y); - Assert.AreEqual(15, geomPart[2].X); - Assert.AreEqual(15, geomPart[2].Y); - } - - // don't clip, as this might change order of vertices - VectorTileFeature featFloat = layer.GetFeature(i); - // test 'scale' on the Geometry method - foreach (var geomPart in featFloat.Geometry(null, 2.0f)) - { - foreach (var coord in geomPart) - { - Debug.WriteLine("float: {0}/{1}", coord.X, coord.Y); - } - Assert.AreEqual(4f, geomPart[0].X); - Assert.AreEqual(4f, geomPart[0].Y); - Assert.AreEqual(4f, geomPart[1].X); - Assert.AreEqual(20f, geomPart[1].Y); - Assert.AreEqual(20f, geomPart[2].X); - Assert.AreEqual(20f, geomPart[2].Y); - } - - } - } - string geojson = vt.ToGeoJson(0, 0, 0); - Assert.GreaterOrEqual(geojson.Length, 30, "geojson >= 30 chars"); - } - - - - [Test, TestCaseSource(typeof(GetMVTs), "GetFixtureFileName")] - public void Scaling(string fileName) - { - float[] scales = new float[] { 1.5f, 2.25f, 5.75f, 197.3f }; - string fullFileName = Path.Combine(fixturesPath, fileName); - byte[] data = File.ReadAllBytes(fullFileName); - VectorTile vt = new VectorTile(data); - foreach (var lyrName in vt.LayerNames()) - { - VectorTileLayer lyr = vt.GetLayer(lyrName); - int featCnt = lyr.FeatureCount(); - for (int idxFeat = 0; idxFeat < featCnt; idxFeat++) - { - VectorTileFeature feat = lyr.GetFeature(idxFeat); - List>> rawParts = feat.Geometry(); - for (int idxPart = 0; idxPart < rawParts.Count; idxPart++) - { - List> rawGeom = rawParts[idxPart]; - foreach (var scale in scales) - { - List>> scaledParts = feat.Geometry(null, scale); - List> scaledGeom = scaledParts[idxPart]; - for (int idxVertex = 0; idxVertex < rawGeom.Count; idxVertex++) - { - Point2d rawVertex = rawGeom[idxVertex]; - Point2d scaledVertex = scaledGeom[idxVertex]; - Assert.AreEqual(scale * (float)rawVertex.X, scaledVertex.X, $"{fileName}, feature[{idxFeat}], geometry part[{idxPart}], vertex[{idxVertex}], scale[{scale}]: X does not match"); - Assert.AreEqual(scale * (float)rawVertex.Y, scaledVertex.Y, $"{fileName}, feature[{idxFeat}], geometry part[{idxPart}], vertex[{idxVertex}], scale[{scale}]: Y does not match"); - } - } - } - } - - } - } - - /// - /// This test assumes that the features do *NOT* extend beyong the tile extent!!! - /// It will fail otherwise. - /// - /// - [Test, TestCaseSource(typeof(GetMVTs), "GetFixtureFileName")] - public void Clipping(string fileName) - { - string fullFileName = Path.Combine(fixturesPath, fileName); - Assert.True(File.Exists(fullFileName), "Vector tile exists"); - byte[] data = File.ReadAllBytes(fullFileName); - VectorTile vt = new VectorTile(data); - foreach (var lyrName in vt.LayerNames()) - { - VectorTileLayer lyr = vt.GetLayer(lyrName); - for (int i = 0; i < lyr.FeatureCount(); i++) - { - VectorTileFeature feat = lyr.GetFeature(i); - //skip features with unknown geometry type - if (feat.GeometryType == GeomType.UNKNOWN) { continue; } - List>> geomRaw = feat.Geometry(); - List>> geomClipped = feat.Geometry(0); - for (int j = 0; j < geomRaw.Count; j++) - { - List> part = geomRaw[j]; - List> partClipped = geomClipped[j]; - // Workaround to compare parts as clipping may or may not change the order of vertices - // This only works if no actual clipping is done - Assert.False(part.Except(partClipped).Any(), $"{fileName}, feature[{i}], geometry part[{j}]: geometry parts don't match after clipping"); - } - } - } - } - - - [Test, TestCaseSource(typeof(GetMVTs), "GetFixtureFileName")] - public void AtLeastOneLayer(string fileName) - { - string fullFileName = Path.Combine(fixturesPath, fileName); - Assert.True(File.Exists(fullFileName), "Vector tile exists"); - byte[] data = File.ReadAllBytes(fullFileName); - VectorTile vt = new VectorTile(data); - Assert.GreaterOrEqual(vt.LayerNames().Count, 1, "At least one layer"); - string geojson = vt.ToGeoJson(0, 0, 0); - Assert.GreaterOrEqual(geojson.Length, 30, "geojson >= 30 chars"); - foreach (var lyrName in vt.LayerNames()) - { - VectorTileLayer lyr = vt.GetLayer(lyrName); - for (int i = 0; i < lyr.FeatureCount(); i++) - { - Debug.WriteLine("{0} lyr:{1} feat:{2}", fileName, lyr.Name, i); - VectorTileFeature feat = lyr.GetFeature(i); - long extent = (long)lyr.Extent; - foreach (var part in feat.Geometry()) - { - foreach (var geom in part) - { - if (geom.X < 0 || geom.Y < 0 || geom.X > extent || geom.Y > extent) - { - Debug.WriteLine("{0} lyr:{1} feat:{2} x:{3} y:{4}", fileName, lyr.Name, i, geom.X, geom.Y); - } - } - } - } - } - } - - - [Test, TestCaseSource(typeof(GetMVTs), "GetFixtureFileName")] - public void ClipHardAtTileBoundary(string fileName) - { - string fullFileName = Path.Combine(fixturesPath, fileName); - Assert.True(File.Exists(fullFileName), "Vector tile exists"); - byte[] data = File.ReadAllBytes(fullFileName); - VectorTile vt = new VectorTile(data); - Assert.GreaterOrEqual(vt.LayerNames().Count, 1, "At least one layer"); - string geojson = vt.ToGeoJson(0, 0, 0); - Assert.GreaterOrEqual(geojson.Length, 30, "geojson >= 30 chars"); - foreach (var lyrName in vt.LayerNames()) - { - VectorTileLayer lyr = vt.GetLayer(lyrName); - for (int i = 0; i < lyr.FeatureCount(); i++) - { - Debug.WriteLine("{0} lyr:{1} feat:{2}", fileName, lyr.Name, i); - VectorTileFeature feat = lyr.GetFeature(i, 0); - long extent = (long)lyr.Extent; - foreach (var part in feat.Geometry()) - { - foreach (var geom in part) - { - Assert.GreaterOrEqual(geom.X, 0, "geom.X equal or greater 0"); - Assert.GreaterOrEqual(geom.Y, 0, "geom.Y eqaul or greater 0"); - Assert.LessOrEqual(geom.X, extent, "geom.X less or equal extent"); - Assert.LessOrEqual(geom.Y, extent, "geom.Y less or equal extent"); - } - } - } - } - } - - - [Test, TestCaseSource(typeof(GetMVTs), "GetFixtureFileName")] - public void IterateAllProperties(string fileName) - { - string fullFileName = Path.Combine(fixturesPath, fileName); - Assert.True(File.Exists(fullFileName), "Vector tile exists"); - byte[] data = File.ReadAllBytes(fullFileName); - VectorTile vt = new VectorTile(data); - foreach (var layerName in vt.LayerNames()) - { - var layer = vt.GetLayer(layerName); - for (int i = 0; i < layer.FeatureCount(); i++) - { - var feat = layer.GetFeature(i); - var properties = feat.GetProperties(); - foreach (var prop in properties) - { - Assert.IsInstanceOf(prop.Key); - } - } - } - } - } - - - - public partial class GetMVTs - { - public static IEnumerable GetFixtureFileName() - { - string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "test", "mvt-fixtures", "fixtures", "valid"); - - foreach (var file in Directory.GetFiles(path)) - { - //return file basename only to make test description more readable - yield return new TestCaseData(Path.GetFileName(file)); - } - } - } - - - - - -} \ No newline at end of file diff --git a/src/VectorTiles.Tests/TestMvtSingle.cs b/src/VectorTiles.Tests/TestMvtSingle.cs deleted file mode 100644 index d721400..0000000 --- a/src/VectorTiles.Tests/TestMvtSingle.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Mapbox.VectorTile; -using Mapbox.VectorTile.Geometry; -using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.IO; - -namespace VectorTiles.Tests -{ - - - [TestFixture] - public class SingleMvtTests - { - - private string fixturesPath; - - [OneTimeSetUp] - protected void SetUp() - { - fixturesPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "test", "mvt-fixtures", "fixtures", "valid"); - } - - - [Test] - public void FeatureSinglePoint() - { - - byte[] data = File.ReadAllBytes(Path.Combine(fixturesPath, "Feature-single-point.mvt")); - VectorTile vt = new VectorTile(data); - Assert.AreEqual(1, vt.LayerNames().Count, "one layer"); - VectorTileLayer lyr = vt.GetLayer(vt.LayerNames()[0]); - Assert.AreEqual("layer_name", lyr.Name, "Layer name"); - Assert.AreEqual(1, lyr.FeatureCount(), "Feature count"); - VectorTileFeature feat = lyr.GetFeature(0); - Assert.AreEqual(GeomType.POINT, feat.GeometryType, "Geometry type"); - Assert.AreEqual(123, feat.Id, "id"); - Dictionary properties = feat.GetProperties(); - Assert.AreEqual("world", properties["hello"]); - Assert.AreEqual("world", feat.GetValue("hello")); - } - - - - } -} diff --git a/src/VectorTiles.Tests/VectorTiles.Tests.csproj b/src/VectorTiles.Tests/VectorTiles.Tests.csproj index 404fff3..160a76a 100644 --- a/src/VectorTiles.Tests/VectorTiles.Tests.csproj +++ b/src/VectorTiles.Tests/VectorTiles.Tests.csproj @@ -1,5 +1,6 @@  + Debug AnyCPU @@ -8,10 +9,12 @@ Properties VectorTiles.Tests VectorTiles.Tests - v4.6.2 + v4.7 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + true @@ -78,12 +81,15 @@ false + False - - ..\..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll - True + + ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll @@ -91,15 +97,9 @@ Properties\AssemblyInfoVersion.cs - - - - - + - - - + @@ -119,7 +119,16 @@ VectorTileReader + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + +