├── src
├── Bench
│ ├── app.config
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Bench.csproj
│ └── Program.cs
├── AssemblyInfoVersion.cs
├── DemoConsoleApp
│ ├── App.config
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── program.cs
│ └── DemoConsoleApp.csproj
├── VerifyNetFrameworkVersion
│ ├── App.config
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Program.cs
│ └── VerifyNetFrameworkVersion.csproj
├── VectorTiles.Tests
│ ├── packages.config
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── TestMvtSingle.cs
│ ├── TestGeometry.cs
│ ├── TestPbfReader.cs
│ ├── TestInvalidMvtInBulk.cs
│ ├── VectorTiles.Tests.csproj
│ └── TestMvtInBulk.cs
├── ExtensionMethods
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Enums.cs
│ ├── VectorTileFeature.cs
│ ├── ExtensionMethodsPortable.csproj
│ ├── ExtensionMethods.csproj
│ └── VectorTile.cs
├── Geometry
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── GeometryPortable.csproj
│ ├── Geometry.cs
│ ├── Util.cs
│ ├── DecodeGeometry.cs
│ └── Geometry.csproj
├── PbfReader
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── PbfReaderPortable.csproj
│ ├── Constants.cs
│ ├── PbfReader.csproj
│ └── PbfReader.cs
└── VectorTileReader
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── VectorTile.cs
│ ├── VectorTileLayer.cs
│ ├── VectorTileReaderPortable.csproj
│ ├── VectorTileReader.csproj
│ ├── VectorTileFeature.cs
│ └── VectorTileReader.cs
├── .gitmodules
├── .travis.yml
├── .gitignore
├── LICENSE
├── README.md
├── Mapbox.VectorTile.nuspec
├── appveyor.yml
├── VectorTileCsPortable.sln
└── VectorTileCs.sln
/src/Bench/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/AssemblyInfoVersion.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | [assembly: AssemblyVersion( "1.0.2" )]
4 | [assembly: AssemblyFileVersion( "1.0.2" )]
5 | [assembly: AssemblyInformationalVersion( "1.0.2" )]
6 |
--------------------------------------------------------------------------------
/src/DemoConsoleApp/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/VerifyNetFrameworkVersion/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/VectorTiles.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "test/mvt-fixtures"]
2 | path = test/mvt-fixtures
3 | url = https://github.com/mapbox/mvt-fixtures.git
4 | [submodule "bench/mvt-bench-fixtures"]
5 | path = bench/mvt-bench-fixtures
6 | url = https://github.com/mapbox/mvt-bench-fixtures.git
7 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # https://docs.travis-ci.com/user/languages/csharp/
2 |
3 | language: csharp
4 | solution: VectorTileCs.sln
5 |
6 | matrix:
7 | include:
8 | - os: linux
9 | sudo: false
10 | mono: latest
11 |
12 | install:
13 | - nuget restore VectorTileCs.sln
14 | - nuget install NUnit.ConsoleRunner -Version 3.5.0 -OutputDirectory testrunner
15 |
16 | script:
17 | - xbuild /p:Configuration=Release VectorTileCs.sln
18 | - mono ./testrunner/NUnit.ConsoleRunner.3.5.0/tools/nunit3-console.exe ./bin/VectorTiles.Tests.dll
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Autosave files
2 | *~
3 |
4 | TestResult.xml
5 | openCoverCoverage.xml
6 |
7 | # build
8 | [Oo]bj/
9 | [Bb]in/
10 | packages/
11 | TestResults/
12 | StyleCop.Cache
13 | nuget.exe
14 | .vscode/
15 | .vs/
16 | tools/
17 |
18 | # globs
19 | Makefile.in
20 | *.DS_Store
21 | *.sln.cache
22 | *.suo
23 | *.cache
24 | *.pidb
25 | *.userprefs
26 | *.usertasks
27 | config.log
28 | config.make
29 | config.status
30 | aclocal.m4
31 | install-sh
32 | autom4te.cache/
33 | *.user
34 | *.tar.gz
35 | tarballs/
36 | test-results/
37 | Thumbs.db
38 |
39 | # Mac bundle stuff
40 | *.dmg
41 | *.app
42 |
43 | # resharper
44 | *_Resharper.*
45 | *.Resharper
46 |
47 | # dotCover
48 | *.dotCover
49 |
--------------------------------------------------------------------------------
/src/Bench/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Bench")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Bench")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("5fa56c72-348a-4b52-980c-ea8287e66422")]
24 |
25 |
--------------------------------------------------------------------------------
/src/ExtensionMethods/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("Util")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("Util")]
14 | [assembly: AssemblyCopyright("Copyright © 2016")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 | [assembly: NeutralResourcesLanguage("en-US")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | // The following GUID is for the ID of the typelib if this project is exposed to COM
25 | [assembly: Guid("55503403-0083-4ed8-b618-f8377610b225")]
26 |
27 |
--------------------------------------------------------------------------------
/src/Geometry/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("Geometry")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("Geometry")]
14 | [assembly: AssemblyCopyright("Copyright © 2016")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 | [assembly: NeutralResourcesLanguage("en-US")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | // The following GUID is for the ID of the typelib if this project is exposed to COM
25 | [assembly: Guid("f0967389-29c8-4d50-b397-9bb698f13ed6")]
26 |
27 |
--------------------------------------------------------------------------------
/src/PbfReader/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("PbfReader")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("PbfReader")]
14 | [assembly: AssemblyCopyright("Copyright © 2016")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 | [assembly: NeutralResourcesLanguage("en-US")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | // The following GUID is for the ID of the typelib if this project is exposed to COM
25 | [assembly: Guid("4bce42ee-c33f-4fa4-bfdd-86f3d45c647c")]
26 |
27 |
--------------------------------------------------------------------------------
/src/DemoConsoleApp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("VectorTilesCs")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("VectorTilesCs")]
14 | [assembly: AssemblyCopyright("Copyright © 2016")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 | [assembly: NeutralResourcesLanguage("en-US")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | // The following GUID is for the ID of the typelib if this project is exposed to COM
25 | [assembly: Guid("d01ba6cb-9a2b-4aa5-95e1-085d9b569309")]
26 |
27 |
--------------------------------------------------------------------------------
/src/VectorTileReader/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("VectorTileReader")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("VectorTileReader")]
14 | [assembly: AssemblyCopyright("Copyright © 2016")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 | [assembly: NeutralResourcesLanguage("en-US")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | // The following GUID is for the ID of the typelib if this project is exposed to COM
25 | [assembly: Guid("4656b308-1492-4a22-a73e-06bf6aa858f2")]
26 |
--------------------------------------------------------------------------------
/src/VectorTiles.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("VectorTiles.Tests")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("VectorTiles.Tests")]
14 | [assembly: AssemblyCopyright("Copyright © 2016")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 | [assembly: NeutralResourcesLanguage("en-US")]
18 |
19 |
20 | // Setting ComVisible to false makes the types in this assembly not visible
21 | // to COM components. If you need to access a type in this assembly from
22 | // COM, set the ComVisible attribute to true on that type.
23 | [assembly: ComVisible(false)]
24 |
25 | // The following GUID is for the ID of the typelib if this project is exposed to COM
26 | [assembly: Guid("067456c0-086c-46a8-b37f-1405717b7bfc")]
27 |
--------------------------------------------------------------------------------
/src/ExtensionMethods/Enums.cs:
--------------------------------------------------------------------------------
1 | using Mapbox.VectorTile.Geometry;
2 | using System;
3 | using System.ComponentModel;
4 |
5 | #if PORTABLE || WINDOWS_UWP
6 | using System.Reflection;
7 | using System.Linq;
8 | #endif
9 |
10 | #if NET20
11 |
12 | namespace System.Runtime.CompilerServices
13 | {
14 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class
15 | | AttributeTargets.Method)]
16 | public sealed class ExtensionAttribute : Attribute { }
17 | }
18 |
19 | #endif
20 |
21 |
22 | namespace Mapbox.VectorTile.ExtensionMethods
23 | {
24 |
25 | ///
26 | /// Extension method to extract the [Description] attribute from an Enum
27 | ///
28 | public static class EnumExtensions
29 | {
30 | public static string Description(this Enum value)
31 | {
32 | var enumType = value.GetType();
33 | #if PORTABLE || WINDOWS_UWP
34 | var field = enumType.GetRuntimeField(value.ToString());
35 | var attributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
36 | return attributes.Count() == 0 ? value.ToString() : ((DescriptionAttribute)attributes.First()).Description;
37 | #else
38 | var field = enumType.GetField(value.ToString());
39 | var attributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
40 | return attributes.Length == 0 ? value.ToString() : ((DescriptionAttribute)attributes[0]).Description;
41 | #endif
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/VectorTiles.Tests/TestMvtSingle.cs:
--------------------------------------------------------------------------------
1 | using Mapbox.VectorTile;
2 | using Mapbox.VectorTile.Geometry;
3 | using NUnit.Framework;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.IO;
7 |
8 | namespace VectorTiles.Tests
9 | {
10 |
11 |
12 | [TestFixture]
13 | public class SingleMvtTests
14 | {
15 |
16 | private string fixturesPath;
17 |
18 | [OneTimeSetUp]
19 | protected void SetUp()
20 | {
21 | fixturesPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "test", "mvt-fixtures", "fixtures", "valid");
22 | }
23 |
24 |
25 | [Test]
26 | public void FeatureSinglePoint()
27 | {
28 |
29 | byte[] data = File.ReadAllBytes(Path.Combine(fixturesPath, "Feature-single-point.mvt"));
30 | VectorTile vt = new VectorTile(data);
31 | Assert.AreEqual(1, vt.LayerNames().Count, "one layer");
32 | VectorTileLayer lyr = vt.GetLayer(vt.LayerNames()[0]);
33 | Assert.AreEqual("layer_name", lyr.Name, "Layer name");
34 | Assert.AreEqual(1, lyr.FeatureCount(), "Feature count");
35 | VectorTileFeature feat = lyr.GetFeature(0);
36 | Assert.AreEqual(GeomType.POINT, feat.GeometryType, "Geometry type");
37 | Assert.AreEqual(123, feat.Id, "id");
38 | Dictionary properties = feat.GetProperties();
39 | Assert.AreEqual("world", properties["hello"]);
40 | Assert.AreEqual("world", feat.GetValue("hello"));
41 | }
42 |
43 |
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/VectorTileReader/VectorTile.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Diagnostics;
3 | using System.Collections.ObjectModel;
4 |
5 |
6 | namespace Mapbox.VectorTile
7 | {
8 |
9 |
10 | ///
11 | /// Class to access the tile data
12 | ///
13 | [DebuggerDisplay("{Zoom}/{TileColumn}/{TileRow}")]
14 | public class VectorTile
15 | {
16 |
17 |
18 | ///
19 | /// Class to access the tile data
20 | ///
21 | /// Byte array containing the raw (already unzipped) tile data
22 | /// If true, run checks if the tile contains valid data. Decreases decoding speed.
23 | public VectorTile(byte[] data, bool validate = true)
24 | {
25 | _VTR = new VectorTileReader(data, validate);
26 | }
27 |
28 |
29 | private VectorTileReader _VTR;
30 |
31 |
32 | ///
33 | /// Collection of layers contained in the tile
34 | ///
35 | /// Collection of layer names
36 | public ReadOnlyCollection LayerNames()
37 | {
38 | return _VTR.LayerNames();
39 | }
40 |
41 |
42 | ///
43 | /// Get a tile layer by name
44 | ///
45 | /// Name of the layer to request
46 | /// Decoded
47 | public VectorTileLayer GetLayer(string layerName)
48 | {
49 | return _VTR.GetLayer(layerName);
50 | }
51 |
52 |
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2017, Mapbox
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/src/VerifyNetFrameworkVersion/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("VerifyNetFrameworkVersion")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("VerifyNetFrameworkVersion")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("1717cd14-720f-4373-81e1-3505fcb2cf03")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/ExtensionMethods/VectorTileFeature.cs:
--------------------------------------------------------------------------------
1 | using Mapbox.VectorTile.Geometry;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | #if !NET20
7 | using System.Linq;
8 | #endif
9 |
10 | namespace Mapbox.VectorTile.ExtensionMethods
11 | {
12 |
13 |
14 | public static class VectorTileFeatureExtensions
15 | {
16 |
17 |
18 | ///
19 | /// >Geometry in LatLng coordinates instead of internal tile coordinates
20 | ///
21 | ///
22 | /// Zoom level of the tile
23 | /// Column of the tile (OSM tile schema)
24 | /// Row of the tile (OSM tile schema)
25 | ///
26 | public static List> GeometryAsWgs84(
27 | this VectorTileFeature feature
28 | , ulong zoom
29 | , ulong tileColumn
30 | , ulong tileRow
31 | , uint? clipBuffer = null
32 | )
33 | {
34 |
35 | List> geometryAsWgs84 = new List>();
36 | foreach (var part in feature.Geometry(clipBuffer, 1.0f))
37 | {
38 | #if NET20
39 | List partAsWgs84 = new List();
40 | foreach (var partGeom in part)
41 | {
42 | partAsWgs84.Add(partGeom.ToLngLat(zoom, tileColumn, tileRow, feature.Layer.Extent));
43 | }
44 | geometryAsWgs84.Add(partAsWgs84);
45 | #else
46 | geometryAsWgs84.Add(
47 | part.Select(g => g.ToLngLat(zoom, tileColumn, tileRow, feature.Layer.Extent)).ToList()
48 | );
49 | #endif
50 | }
51 |
52 | return geometryAsWgs84;
53 | }
54 |
55 |
56 |
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/VerifyNetFrameworkVersion/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Reflection;
4 | #if NET462
5 | using System.Runtime.Versioning;
6 | #endif
7 |
8 | namespace VerifyNetFrameworkVersion
9 | {
10 |
11 | class Program
12 | {
13 |
14 |
15 | static int Main(string[] args)
16 | {
17 |
18 | string myName = "VerifyNetFrameworkVersion";
19 | string assemblyDir;
20 |
21 | if (args.Length < 1)
22 | {
23 | assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
24 | Console.Error.WriteLine($"{myName}: no directory passed, using current directory: '{assemblyDir}'");
25 | }
26 | else
27 | {
28 | assemblyDir = args[0];
29 | }
30 | if (!Directory.Exists(assemblyDir))
31 | {
32 | Console.Error.WriteLine($"{myName}: directory does not exist: {assemblyDir}");
33 | return 1;
34 | }
35 |
36 | string[] dlls = Directory.GetFiles(assemblyDir, "*.dll");
37 | if (dlls.Length < 1)
38 | {
39 | Console.Error.WriteLine($"{myName}: no dlls found in {assemblyDir}");
40 | return 1;
41 | }
42 |
43 | Console.WriteLine($"{myName} analyzing assemblies:");
44 | foreach (var dll in dlls)
45 | {
46 | Assembly assembly = Assembly.LoadFrom(dll);
47 | string frameworkName = "NA";
48 | string frameworkDisplayName = "NA";
49 | #if NET462
50 | TargetFrameworkAttribute targetFWA = assembly.GetCustomAttribute();
51 | frameworkName = targetFWA.FrameworkName;
52 | frameworkDisplayName = targetFWA.FrameworkDisplayName;
53 | #endif
54 | Console.WriteLine($"* {Path.GetFileName(dll)}, ImageRuntimeVersion:{assembly.ImageRuntimeVersion}, FrameworkName:{frameworkName}, FrameworkDisplayName:{frameworkDisplayName}");
55 | }
56 | return 0;
57 | }
58 |
59 |
60 |
61 |
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/VectorTiles.Tests/TestGeometry.cs:
--------------------------------------------------------------------------------
1 | using Mapbox.VectorTile;
2 | using Mapbox.VectorTile.Geometry;
3 | using System;
4 | using System.IO;
5 | #if WINDOWS_UWP
6 | using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
7 | using ATestClass = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
8 | using ATestMethod = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
9 | #else
10 | using NUnit.Framework;
11 | using ATestClass = NUnit.Framework.TestFixtureAttribute;
12 | using ATestMethod = NUnit.Framework.TestAttribute;
13 | #endif
14 |
15 | namespace VectorTiles.Tests
16 | {
17 |
18 |
19 | [ATestClass]
20 | public class GeometryTests
21 | {
22 |
23 |
24 | // [ATestMethod]
25 | // public void GeometryObjects() {
26 | // LatLng ll = new LatLng() { Lng = 15, Lat = 48 };
27 | // Assert.AreEqual("48.000000/15.000000", ll.ToString(), "LatLng.ToString()");
28 |
29 | // Point2d ptSE = new Point2d(4096, 4096);
30 | // Assert.AreEqual("4096/4096", ptSE.ToString(), "Point2d.ToString()");
31 |
32 | // LatLng fromPtSE = ptSE.ToLngLat(0, 0, 0, 4096);
33 | // Assert.AreEqual(180, fromPtSE.Lng, "correct longitude");
34 | // Assert.AreEqual(-85.051128779806589, fromPtSE.Lat, "correct latitude");
35 |
36 | // ptSE.X = 4210;
37 | // fromPtSE = ptSE.ToLngLat(0, 0, 0, 4096);
38 | // Assert.AreEqual(190, fromPtSE.Lng, 0.02, "correct longitude - out of bounds");
39 | //#if WINDOWS_UWP
40 | // Assert.ThrowsException(() => { ptSE.ToLngLat(0, 0, 0, 04096, true); });
41 | //#else
42 | // Assert.Throws(Is.InstanceOf(), () => { ptSE.ToLngLat(0, 0, 0, 04096, true); });
43 | //#endif
44 |
45 | // ptSE.X = 4096;
46 | // ptSE.Y = 4210;
47 | // fromPtSE = ptSE.ToLngLat(0, 0, 0, 4096);
48 | // Assert.AreEqual(-85.844, fromPtSE.Lat, 0.02, "correct latitude - out of bounds");
49 | //#if WINDOWS_UWP
50 | // Assert.ThrowsException(() => { ptSE.ToLngLat(0, 0, 0, 04096, true); });
51 | //#else
52 | // Assert.Throws(Is.InstanceOf(), () => { ptSE.ToLngLat(0, 0, 0, 04096, true); });
53 | //#endif
54 | // }
55 |
56 |
57 |
58 |
59 |
60 | }
61 |
62 | }
--------------------------------------------------------------------------------
/src/VectorTiles.Tests/TestPbfReader.cs:
--------------------------------------------------------------------------------
1 | using Mapbox.VectorTile.Contants;
2 | using NUnit.Framework;
3 |
4 |
5 | namespace VectorTiles.Tests
6 | {
7 |
8 |
9 | [TestFixture]
10 | public class PbfReaderTests
11 | {
12 |
13 | [Test]
14 | public void Constants()
15 | {
16 | Assert.AreEqual(0, (int)WireTypes.VARINT, "WireTypes.VARINT");
17 | Assert.AreEqual(1, (int)WireTypes.FIXED64, "WireTypes.FIXED64");
18 | Assert.AreEqual(2, (int)WireTypes.BYTES, "WireTypes.BYTES");
19 | Assert.AreEqual(5, (int)WireTypes.FIXED32, "WireTypes.FIXED32");
20 | Assert.AreEqual(99, (int)WireTypes.UNDEFINED, "WireTypes.UNDEFINED");
21 |
22 | Assert.AreEqual(1, (int)Commands.MoveTo, "Commands.MoveTo");
23 | Assert.AreEqual(2, (int)Commands.LineTo, "Commands.LineTo");
24 | Assert.AreEqual(7, (int)Commands.ClosePath, "Commands.ClosePath");
25 |
26 | Assert.AreEqual(3, (int)TileType.Layers, "TileType.Layers");
27 |
28 | Assert.AreEqual(15, (int)LayerType.Version, "LayerType.Version");
29 | Assert.AreEqual(1, (int)LayerType.Name, "LayerType.Name");
30 | Assert.AreEqual(2, (int)LayerType.Features, "LayerType.Features");
31 | Assert.AreEqual(3, (int)LayerType.Keys, "LayerType.Keys");
32 | Assert.AreEqual(4, (int)LayerType.Values, "LayerType.Values");
33 | Assert.AreEqual(5, (int)LayerType.Extent, "LayerType.Extent");
34 |
35 | Assert.AreEqual(1, (int)FeatureType.Id, "FeatureType.Id");
36 | Assert.AreEqual(2, (int)FeatureType.Tags, "FeatureType.Tags");
37 | Assert.AreEqual(3, (int)FeatureType.Type, "FeatureType.Type");
38 | Assert.AreEqual(4, (int)FeatureType.Geometry, "FeatureType.Geometry");
39 | Assert.AreEqual(5, (int)FeatureType.Raster, "FeatureType.Raster");
40 |
41 | Assert.AreEqual(1, (int)ValueType.String, "ValueType.String");
42 | Assert.AreEqual(2, (int)ValueType.Float, "ValueType.Float");
43 | Assert.AreEqual(3, (int)ValueType.Double, "ValueType.Double");
44 | Assert.AreEqual(4, (int)ValueType.Int, "ValueType.Int");
45 | Assert.AreEqual(5, (int)ValueType.UInt, "ValueType.UInt");
46 | Assert.AreEqual(6, (int)ValueType.SInt, "ValueType.SInt");
47 | Assert.AreEqual(7, (int)ValueType.Bool, "ValueType.Bool");
48 | }
49 |
50 |
51 |
52 |
53 |
54 | }
55 |
56 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vector-tile-cs
2 |
3 | C# library for decoding [`Mapbox Vector Tiles @ v2.x`](https://www.mapbox.com/vector-tiles/) ([vector tile specification](https://github.com/mapbox/vector-tile-spec)).
4 |
5 | _**Decoding tiles created according to `Mapbox Vector Tile Specification @ v1.x` is not supported!**_
6 |
7 | Available as nuget package: [](https://www.nuget.org/packages/Mapbox.VectorTile)
8 |
9 | Vector tile parsers in other languages:
10 | * JavaScript: https://github.com/mapbox/vector-tile-js
11 | * C++: https://github.com/mapbox/vector-tile
12 |
13 | # Build status
14 | master branch:
15 | * Travis: [](https://travis-ci.com/mapbox/vector-tile-cs)
16 | * AppVeyor: [](https://ci.appveyor.com/project/Mapbox/vector-tile-cs/branch/master)
17 | * Coveralls: [](https://coveralls.io/github/mapbox/vector-tile-cs?branch=master)
18 |
19 | # Depends
20 |
21 | Native C# implementation - no dependencies.
22 | `NUnit` and `NUnit3TestAdapter` for running tests - will get restored automatically when building the solution.
23 |
24 | #Example
25 |
26 | ```c#
27 | byte[] data = //raw unzipped vectortile
28 | VectorTile vt = new VectorTile(data);
29 | //get available layer names
30 | foreach(var lyrName in vt.LayerNames()) {
31 | //get layer by name
32 | VectorTileLayer lyr = vt.GetLayer(lyrName);
33 | //iterate through all features
34 | for(int i = 0; i < lyr.FeatureCount(); i++) {
35 | Debug.WriteLine("{0} lyr:{1} feat:{2}", fileName, lyr.Name, i);
36 | //get the feature
37 | VectorTileFeature feat = lyr.GetFeature(i);
38 | //get feature properties
39 | var properties = feat.GetProperties();
40 | foreach(var prop in properties) {
41 | Debug.WriteLine("key:{0} value:{1}", prop.Key, prop.Value);
42 | }
43 | //or get property value if you already know the key
44 | //object value = feat.GetValue(prop.Key);
45 | //iterate through all geometry parts
46 | //requesting coordinates as ints
47 | foreach(var part in feat.Geometry()) {
48 | //iterate through coordinates of the part
49 | foreach(var geom in part) {
50 | Debug.WriteLine("geom.X:{0} geom.Y:{1}", geom.X, geom.Y);
51 | }
52 | }
53 | }
54 | }
55 |
56 | ```
57 |
--------------------------------------------------------------------------------
/src/PbfReader/PbfReaderPortable.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 10.0
6 | Debug
7 | AnyCPU
8 | {E3ED95C9-42D9-4480-90E5-87F4FE60B8E2}
9 | Library
10 | Properties
11 | PbfReader
12 | Mapbox.VectorTile.PbfReader
13 | en-US
14 | 512
15 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
16 | Profile7
17 | v4.5
18 |
19 |
20 | true
21 | full
22 | false
23 | ..\..\bin\PortableDebug\portable-net45+uap10\
24 | TRACE;DEBUG;PORTABLE;WINDOWS_UWP
25 | prompt
26 | 4
27 |
28 |
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
49 |
--------------------------------------------------------------------------------
/src/VectorTiles.Tests/TestInvalidMvtInBulk.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using Mapbox.VectorTile;
4 | using System.Collections;
5 | #if WINDOWS_UWP
6 | using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
7 | using ATestClass = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
8 | using ATestMethod = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
9 | using ATestClassSetup = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.ClassInitializeAttribute; //run once per class
10 | using ATestSetup = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestInitializeAttribute; //run before every test
11 | using ATestDataSource = Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute;
12 | #else
13 | using NUnit.Framework;
14 | using ATestClass = NUnit.Framework.TestFixtureAttribute;
15 | using ATestMethod = NUnit.Framework.TestAttribute;
16 | using ATestClassSetup = NUnit.Framework.OneTimeSetUpAttribute;
17 | using ATestDataSource = NUnit.Framework.TestCaseSourceAttribute;
18 | #endif
19 |
20 |
21 | namespace VectorTiles.Tests
22 | {
23 |
24 |
25 | [ATestClass]
26 | public class BulkInvalidMvtTests
27 | {
28 |
29 | private string _fixturesPath;
30 | public static string _executingFolder = AppDomain.CurrentDomain.BaseDirectory;
31 |
32 |
33 | [ATestClassSetup]
34 | protected void SetUp()
35 | {
36 | _fixturesPath = Path.Combine(_executingFolder, "..", "..", "..", "test", "mvt-fixtures", "fixtures", "invalid");
37 | }
38 |
39 | [ATestMethod, Order(1)]
40 | public void FixturesPathExists()
41 | {
42 | Assert.True(Directory.Exists(_fixturesPath), "MVT fixtures directory exists");
43 | }
44 |
45 |
46 | [ATestMethod, ATestDataSource(typeof(GetMVTs), "GetInValidFixtureFileName")]
47 | public void Validate(string fileName)
48 | {
49 | string fullFileName = Path.Combine(_fixturesPath, fileName);
50 | Assert.True(File.Exists(fullFileName), "Vector tile exists");
51 | byte[] data = File.ReadAllBytes(fullFileName);
52 | Assert.Throws(Is.InstanceOf(), () =>
53 | {
54 | VectorTile vt = new VectorTile(data);
55 | foreach (var layerName in vt.LayerNames())
56 | {
57 | var layer = vt.GetLayer(layerName);
58 | for (int i = 0; i < layer.FeatureCount(); i++)
59 | {
60 | var feat = layer.GetFeature(i);
61 | feat.GetProperties();
62 | }
63 | }
64 | });
65 | }
66 | }
67 |
68 | public partial class GetMVTs
69 | {
70 | public static IEnumerable GetInValidFixtureFileName()
71 | {
72 | string path = Path.Combine(BulkInvalidMvtTests._executingFolder, "..", "..", "..", "test", "mvt-fixtures", "fixtures", "invalid");
73 |
74 | foreach (var file in Directory.GetFiles(path))
75 | {
76 | //return file basename only to make test description more readable
77 | yield return new TestCaseData(Path.GetFileName(file));
78 | }
79 | }
80 | }
81 |
82 |
83 |
84 |
85 |
86 | }
--------------------------------------------------------------------------------
/Mapbox.VectorTile.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mapbox.VectorTile
5 | 1.0.4-alpha2
6 | Mapbox
7 | Mapbox
8 | https://github.com/mapbox/vector-tile-cs
9 | https://github.com/mapbox/vector-tile-cs
10 | false
11 | Mapbox VectorTileReader CSharp
12 | Republish of 1.0.4-alpha2, nupkg seem to have been corrupted
13 | Copyright 2017
14 | vector tiles c# mapbox
15 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/src/Geometry/GeometryPortable.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 10.0
6 | Debug
7 | AnyCPU
8 | {B6044F02-10A3-4637-962E-8B2F882DCD59}
9 | Library
10 | Properties
11 | Geometry
12 | Mapbox.VectorTile.Geometry
13 | en-US
14 | 512
15 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
16 | Profile7
17 | v4.5
18 |
19 |
20 | true
21 | full
22 | false
23 | ..\..\bin\PortableDebug\portable-net45+uap10\
24 | TRACE;DEBUG;PORTABLE;WINDOWS_UWP
25 | prompt
26 | 4
27 |
28 |
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 |
39 | {e3ed95c9-42d9-4480-90e5-87f4fe60b8e2}
40 | PbfReaderPortable
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
58 |
--------------------------------------------------------------------------------
/src/VectorTileReader/VectorTileLayer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 |
5 | namespace Mapbox.VectorTile
6 | {
7 |
8 |
9 | ///
10 | /// Class to access a vector tile layer
11 | ///
12 | [DebuggerDisplay("Layer {Name}")]
13 | public class VectorTileLayer
14 | {
15 |
16 |
17 | ///
18 | /// Class to access a vector tile layer
19 | ///
20 | public VectorTileLayer()
21 | {
22 | _FeaturesData = new List();
23 | Keys = new List();
24 | Values = new List