Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Mapbox.VectorTile.1.0.2-alpha1.nupkg
Binary file not shown.
Binary file added Mapbox.VectorTile.1.0.2-alpha2.nupkg
Binary file not shown.
7 changes: 5 additions & 2 deletions Mapbox.VectorTile.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
<package >
<metadata>
<id>Mapbox.VectorTile</id>
<version>1.0.1-alpha3</version>
<version>1.0.2-alpha2</version>
<authors>Mapbox</authors>
<owners>Mapbox</owners>
<licenseUrl>https://github.com/mapbox/vector-tile-cs</licenseUrl>
<projectUrl>https://github.com/mapbox/vector-tile-cs</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Mapbox VectorTileReader CSharp</description>
<releaseNotes>Updates to VectorTileFeature.</releaseNotes>
<releaseNotes>Lazy loading.</releaseNotes>
<copyright>Copyright 2016</copyright>
<tags>vector tiles c# mapbox</tags>
<dependencies>
<dependency id="Mapbox.Geometry" version="[1.0.0-alpha1]" />
</dependencies>
</metadata>
<files>
<file src="bin\Mapbox.VectorTile.Geometry.dll" target="lib\net35\Mapbox.VectorTile.Geometry.dll"></file>
Expand Down
5 changes: 5 additions & 0 deletions src/AssemblyInfoVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System.Reflection;

[assembly: AssemblyVersion( "1.0.2" )]
[assembly: AssemblyFileVersion( "1.0.2" )]
[assembly: AssemblyInformationalVersion( "1.0.2" )]
3 changes: 3 additions & 0 deletions src/Bench/Bench.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\AssemblyInfoVersion.cs">
<Link>Properties\AssemblyInfoVersion.cs</Link>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
16 changes: 13 additions & 3 deletions src/Bench/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace ProfileDecoding
namespace Bench
{
class Program
{
Expand Down Expand Up @@ -47,7 +48,8 @@ static int Main(string[] args)
return 1;
} else
{
tiles.Add(new TileData() {
tiles.Add(new TileData()
{
zoom = zoom,
col = col,
row = row,
Expand All @@ -67,7 +69,14 @@ static int Main(string[] args)
stopWatch.Start();
foreach (var tile in tiles)
{
VectorTileReader.Decode(tile.zoom, tile.col, tile.row, tile.pbf);
VectorTile vt = VectorTile.DecodeFully(tile.pbf);
foreach (var lyr in vt.Layers)
{
foreach (var feat in lyr.Features)
{
var props = feat.GetProperties();
}
}
}
stopWatch.Stop();
//skip first run
Expand All @@ -76,6 +85,7 @@ static int Main(string[] args)
elapsed.Add(stopWatch.ElapsedMilliseconds);
}
stopWatch.Reset();
elapsed.Add(stopWatch.ElapsedMilliseconds);
}


Expand Down
12 changes: 0 additions & 12 deletions src/Bench/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,3 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5fa56c72-348a-4b52-980c-ea8287e66422")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
3 changes: 3 additions & 0 deletions src/DemoConsoleApp/DemoConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\AssemblyInfoVersion.cs">
<Link>Properties\AssemblyInfoVersion.cs</Link>
</Compile>
<Compile Include="program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
12 changes: 0 additions & 12 deletions src/DemoConsoleApp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,3 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d01ba6cb-9a2b-4aa5-95e1-085d9b569309")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
30 changes: 22 additions & 8 deletions src/DemoConsoleApp/program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ public static int Main(string[] args)
return 1;
}


var bufferedData = File.ReadAllBytes(vtIn);

VectorTileReader vtr = new VectorTileReader(bufferedData);
foreach (var lyrName in vtr.LayerNames())
{
Console.WriteLine(lyrName);
VectorTileLayer layer = vtr.GetLayer(lyrName);
Console.WriteLine("features: {0}", layer.FeatureCount());
for (int i = 0; i < layer.FeatureCount(); i++)
{
VectorTileFeature feat = layer.GetFeature(i);
Console.WriteLine(feat.Id);
foreach (var prop in feat.GetProperties())
{
Console.WriteLine("{0}: {1}", prop.Key, prop.Value);
}
}
}

ulong zoom;
ulong tileCol;
ulong tileRow;
Expand All @@ -31,16 +51,10 @@ public static int Main(string[] args)
return 1;
}

var bufferedData = File.ReadAllBytes(vtIn);

VectorTile tile = VectorTileReader.Decode(
(ulong)zoom
, (ulong)tileCol
, (ulong)tileRow
, (byte[])bufferedData
);
VectorTile tile = VectorTile.DecodeFully(bufferedData);

Console.WriteLine(tile.ToGeoJson());
Console.WriteLine(tile.ToGeoJson(zoom, tileCol, tileRow));

return 0;
}
Expand Down
52 changes: 37 additions & 15 deletions src/Geometry/DecodeGeometry.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using Mapbox.Geometry;

namespace Mapbox.VectorTile.Geometry
{
Expand All @@ -25,19 +23,14 @@ public static class DecodeGeometry
/// <para> Each child list contains the corrdinates of this part.</para>
/// </summary>
/// <param name="extent">Tile extent</param>
/// <param name="zoom">Zoom level</param>
/// <param name="tileColumn">Tile column</param>
/// <param name="tileRow">Tile row</param>
/// <param name="geomType">Geometry type</param>
/// <param name="geometry"></param>
/// <param name="geometryCommands"></param>
/// <returns>List<List<Point2d>></returns>
public static List<List<Point2d>> GetGeometry(
ulong extent
, ulong zoom
, ulong tileColumn
, ulong tileRow
, GeomType geomType
, List<uint> geometry
, List<uint> geometryCommands
, float scale = 1.0f
)
{

Expand All @@ -46,18 +39,18 @@ ulong extent
long cursorX = 0;
long cursorY = 0;

for (int i = 0; i < geometry.Count; i++)
for (int i = 0; i < geometryCommands.Count; i++)
{

uint g = geometry[i];
uint g = geometryCommands[i];
Commands cmd = (Commands)(g & 0x7);
uint cmdCount = g >> 3;

if (cmd == Commands.MoveTo || cmd == Commands.LineTo)
{
for (int j = 0; j < cmdCount; j++)
{
Point2d delta = zigzagDecode(geometry[i + 1], geometry[i + 2]);
Point2d delta = zigzagDecode(geometryCommands[i + 1], geometryCommands[i + 2]);
cursorX += delta.X;
cursorY += delta.Y;
i += 2;
Expand Down Expand Up @@ -85,6 +78,35 @@ ulong extent
geomOut.Add(geomTmp);
}

//IGeometryBase geomOut2;
//switch (geomType)
//{
// case GeomType.UNKNOWN:
// throw new System.Exception("Geometry type unknown");
// case GeomType.POINT:
// if (geomOut.Count == 1)
// {
// geomOut2 = new Point<float>(geomOut[0][0].X, geomOut[0][0].Y);
// } else
// {
// geomOut2 = new MultiPoint<float>();
// foreach (var part in geomOut)
// {
// ((MultiPoint<float>)geomOut2).Add(new Point<float>(part[0].X, part[0].Y));
// }
// }
// break;
// case GeomType.LINESTRING:
// geomOut2 = new LinearRing<float>();
// break;
// case GeomType.POLYGON:
// geomOut2 = new Polygon<float>();
// break;
// default:
// throw new System.Exception("Geometry type invalid");
//}


return geomOut;
}

Expand Down
10 changes: 10 additions & 0 deletions src/Geometry/Geometry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mapbox.Geometry, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Mapbox.Geometry.1.0.0-alpha1\lib\net35\Mapbox.Geometry.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -62,6 +66,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\AssemblyInfoVersion.cs">
<Link>Properties\AssemblyInfoVersion.cs</Link>
</Compile>
<Compile Include="DecodeGeometry.cs" />
<Compile Include="Geometry.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -76,6 +83,9 @@
<Name>Util</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
12 changes: 0 additions & 12 deletions src/Geometry/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,3 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f0967389-29c8-4d50-b397-9bb698f13ed6")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
4 changes: 4 additions & 0 deletions src/Geometry/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Mapbox.Geometry" version="1.0.0-alpha1" targetFramework="net35" />
</packages>
35 changes: 22 additions & 13 deletions src/PbfReader/PbfReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
namespace Mapbox.VectorTile
{

public struct DataView
{
public ulong start;
public ulong end;
}


public class PbfReader
{
Expand Down Expand Up @@ -61,12 +67,14 @@ public byte[] View()
{
throw new Exception("not of type string, bytes or message");
}

ulong tmpPos = Pos;
ulong skipBytes = Varint();
SkipBytes(skipBytes);

byte[] buf = new byte[skipBytes];
Array.Copy(_buffer, (int)Pos - (int)skipBytes, buf, 0, (int)skipBytes);

return buf;
}

Expand Down Expand Up @@ -135,19 +143,20 @@ public bool NextByte()

public void SkipVarint()
{
while (0 == (_buffer[Pos] & 0x80))
{
Pos++;
if (Pos >= _length)
{
throw new Exception("Truncated message.");
}
}

if (Pos > _length)
{
throw new Exception("Truncated message.");
}
Varint();
//while (0 == (_buffer[Pos] & 0x80))
//{
// Pos++;
// if (Pos >= _length)
// {
// throw new Exception("Truncated message.");
// }
//}

//if (Pos > _length)
//{
// throw new Exception("Truncated message.");
//}
}


Expand Down
3 changes: 3 additions & 0 deletions src/PbfReader/PbfReader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\AssemblyInfoVersion.cs">
<Link>Properties\AssemblyInfoVersion.cs</Link>
</Compile>
<Compile Include="Constants.cs" />
<Compile Include="PbfReader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
Loading