Skip to content
Open
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
32 changes: 16 additions & 16 deletions SharpMap.Data.Providers.GeoPackage/Tiles/GpkgTileSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class GpkgTileSchema : ITileSchema
private const string SelectTileMatrix =
"SELECT * FROM \"gpkg_tile_matrix\" WHERE \"table_name\"=? ORDER by \"zoom_level\";";

private readonly Dictionary<string, Resolution> _resolutions;
private readonly Dictionary<int, Resolution> _resolutions;

private readonly string _name;

Expand All @@ -32,37 +32,37 @@ public GpkgTileSchema(GpkgContent content)
_resolutions = tms.ToResolutions();
}

public int GetTileWidth(string levelId)
public int GetTileWidth(int levelId)
{
return _resolutions[levelId].TileWidth;
}

public int GetTileHeight(string levelId)
public int GetTileHeight(int levelId)
{
return _resolutions[levelId].TileHeight;
}

public double GetOriginX(string levelId)
public double GetOriginX(int levelId)
{
return _resolutions[levelId].Left;
}

public double GetOriginY(string levelId)
public double GetOriginY(int levelId)
{
return _resolutions[levelId].Top;
}

public long GetMatrixWidth(string levelId)
public long GetMatrixWidth(int levelId)
{
return _resolutions[levelId].MatrixWidth;
}

public long GetMatrixHeight(string levelId)
public long GetMatrixHeight(int levelId)
{
return _resolutions[levelId].MatrixHeight;
}

public IEnumerable<TileInfo> GetTileInfos(Extent extent, string levelId)
public IEnumerable<TileInfo> GetTileInfos(Extent extent, int levelId)
{
// todo: move this method elsewhere.
var range = TileTransform.WorldToTile(extent, levelId, this);
Expand Down Expand Up @@ -92,17 +92,17 @@ public IEnumerable<TileInfo> GetTileInfos(Extent extent, double resolution)
return GetTileInfos(extent, level);
}

public Extent GetExtentOfTilesInView(Extent extent, string levelId)
public Extent GetExtentOfTilesInView(Extent extent, int levelId)
{
return TileSchema.GetExtentOfTilesInView(this, extent, levelId);
}

public int GetMatrixFirstCol(string levelId)
public int GetMatrixFirstCol(int levelId)
{
return 0;
}

public int GetMatrixFirstRow(string levelId)
public int GetMatrixFirstRow(int levelId)
{
return 0;
}
Expand All @@ -116,7 +116,7 @@ public string Name

public Extent Extent { get; private set; }

public IDictionary<string, Resolution> Resolutions
public IDictionary<int, Resolution> Resolutions
{
get { return _resolutions; }
}
Expand Down Expand Up @@ -181,17 +181,17 @@ public GpkgTileMatrixSet(IDataRecord tmsRecord)

public List<GpkgTileMatrix> TileMatrices { get; private set; }

public Dictionary<string, Resolution> ToResolutions()
public Dictionary<int, Resolution> ToResolutions()
{
var res = new Dictionary<string, Resolution>(TileMatrices.Count);
var res = new Dictionary<int, Resolution>(TileMatrices.Count);
foreach (var tileMatrix in TileMatrices)
{
var tmp = new Resolution(
tileMatrix.ZoomLevel.ToString(), tileMatrix.PixelXSize,
tileMatrix.ZoomLevel, tileMatrix.PixelXSize,
tileMatrix.TileWidth, tileMatrix.TileHeight,
MinX, MaxY,
tileMatrix.MatrixWidth, tileMatrix.MatrixHeight);
res.Add(tmp.Id, tmp);
res.Add(tmp.Level, tmp);
}
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion SharpMap.Data.Providers.GeoPackage/Tiles/GpkgTileSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public byte[] GetTile(TileInfo tileInfo)
using (var cn = new SQLiteConnection(_content.ConnectionString).OpenAndReturn())
{
var cmd = new SQLiteCommand(_selectSql, cn);
cmd.Parameters.AddRange(new object[] { int.Parse(tileInfo.Index.Level), tileInfo.Index.Col, tileInfo.Index.Row });
cmd.Parameters.AddRange(new object[] { tileInfo.Index.Level, tileInfo.Index.Col, tileInfo.Index.Row });
return (byte[]) cmd.ExecuteScalar();
}
}
Expand Down
2 changes: 1 addition & 1 deletion SharpMap.Layers.BruTile/Layers/TileAsyncLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public override void Render(Graphics graphics, MapViewport map)
{
var bbox = map.Envelope;
var extent = new Extent(bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY);
string level = BruTile.Utilities.GetNearestLevel(_source.Schema.Resolutions, Math.Max(map.PixelWidth, map.PixelHeight));
int level = BruTile.Utilities.GetNearestLevel(_source.Schema.Resolutions, Math.Max(map.PixelWidth, map.PixelHeight));
var tiles = new List<TileInfo>(_source.Schema.GetTileInfos(extent, level));

tiles.Sort(new DistanceComparison(map.CenterOfInterest));
Expand Down
4 changes: 2 additions & 2 deletions SharpMap.Layers.BruTile/SharpMap.Layers.BruTile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BruTile" Version="2.1.2" />
<PackageReference Include="BruTile.Desktop" Version="2.1.2" />
<PackageReference Include="BruTile" Version="3.0.0" />
<PackageReference Include="BruTile.Desktop" Version="3.0.0" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions SharpMap.Layers.BruTile/Utilities/ResolutionSurrogate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class ResolutionRef : IObjectReference, ISerializable
public ResolutionRef(SerializationInfo info, StreamingContext context)
{
_resolution = new Resolution(
info.GetString("id"), info.GetDouble("upp"),
info.GetInt32("level"), info.GetDouble("upp"),
info.GetInt32("th"), info.GetInt32("tw"),
info.GetDouble("t"), info.GetDouble("l"),
info.GetInt32("mw"), info.GetInt32("mh"),
Expand All @@ -46,7 +46,7 @@ public void GetObjectData(object obj, SerializationInfo info, StreamingContext c
{
var res = (Resolution)obj;
info.SetType(typeof(ResolutionRef));
info.AddValue("id", res.Id);
info.AddValue("level", res.Level);
info.AddValue("upp", res.UnitsPerPixel);
info.AddValue("th", res.TileHeight);
info.AddValue("tw", res.TileWidth);
Expand Down
5 changes: 3 additions & 2 deletions SharpMap.Layers.BruTile/Utilities/TileSchemaSurrogate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public virtual object SetObjectData(object obj, SerializationInfo info, Streamin
ts.Format = info.GetString("format");

var type = (Type) info.GetValue("resolutionsType", typeof (Type));
var list = (IDictionary<string, Resolution>) Activator.CreateInstance(type);
var tmp = Activator.CreateInstance(type);
IDictionary<int, Resolution> list = (IDictionary<int, Resolution>) Activator.CreateInstance(type);
var count = info.GetInt32("resolutionsCount");
for (var i = 0; i < count; i++)
{
var key = info.GetString(string.Format("rk{0}", i));
int key = i;//info.GetString(string.Format("rk{0}", i));
var valueRef = (IObjectReference)
info.GetValue(string.Format("rv{0}", i), typeof(ResolutionSurrogate.ResolutionRef));
var value = (Resolution) valueRef.GetRealObject(context);
Expand Down
45 changes: 23 additions & 22 deletions UnitTests/Serialization/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public void TestExtent()
[Test]
public void TestResolution()
{
var r1 = new Resolution("XXX", 1245, 999,999, 5, 5, 4, 4, 0.1);
var r1 = new Resolution(0, 1245, 999,999, 5, 5, 4, 4, 0.1);
var r2 = SandD(r1);
Assert.AreEqual(r1.Id, r2.Id);
Assert.AreEqual(r1.Level, r2.Level);
Assert.AreEqual(r1.UnitsPerPixel, r2.UnitsPerPixel);
Assert.AreEqual(r1.TileWidth, r2.TileWidth);
Assert.AreEqual(r1.TileHeight, r2.TileHeight);
Expand All @@ -52,7 +52,7 @@ public void TestResolution()
public void TestGlobalMercatorSchema()
{
string message;
var s1 = new GlobalMercator("png", 2, 11);
var s1 = new GlobalMercator("png", 0, 11);
var s2 = SandD(s1);
var equal = EqualTileSchemas(s1, s2, out message);
Assert.IsTrue(equal, message);
Expand All @@ -62,7 +62,7 @@ public void TestGlobalMercatorSchema()
public void TestGlobalSphericalMercatorSchema()
{
string message;
var s1 = new GlobalSphericalMercator("png", YAxis.OSM, 2, 11);
var s1 = new GlobalSphericalMercator("png", YAxis.OSM, 0, 11);
var s2 = SandD(s1);
var equal = EqualTileSchemas(s1, s2, out message);
Assert.IsTrue(equal, message);
Expand Down Expand Up @@ -301,7 +301,7 @@ private static bool EqualTileProviders(ITileSchema schema, ITileProvider tp1, IT
var keys = schema.Resolutions.Keys.ToArray();
var minkey = GetIndex(keys[0]);
var maxKey = GetIndex(keys[keys.Length - 1]);
var prefix = GetPrefix(keys[0]);
var prefix = keys[0];
for (var i = 0; i < 3; i++)
{
TileInfo ti = null;
Expand Down Expand Up @@ -352,23 +352,24 @@ private static bool EqualTileProviders(ITileSchema schema, ITileProvider tp1, IT
return true;
}

private static int GetIndex(string s)
private static int GetIndex(int level)
{
var pos = s.LastIndexOf(":", StringComparison.Ordinal);
if (pos == 0)
return int.Parse(s, NumberFormatInfo.InvariantInfo);
return int.Parse(s.Substring(pos + 1), NumberFormatInfo.InvariantInfo);
return level;
//var pos = s.LastIndexOf(":", StringComparison.Ordinal);
//if (pos == 0)
// return int.Parse(s, NumberFormatInfo.InvariantInfo);
//return int.Parse(s.Substring(pos + 1), NumberFormatInfo.InvariantInfo);
}

private static string GetPrefix(string s)
{
var pos = s.LastIndexOf(":", StringComparison.Ordinal);
if (pos == -1)
return string.Empty;
//private static string GetPrefix(string s)
//{
// var pos = s.LastIndexOf(":", StringComparison.Ordinal);
// if (pos == -1)
// return string.Empty;

return s.Substring(0, pos+1);
// return s.Substring(0, pos+1);

}
//}

private static bool TilesEqual(IEnumerable<byte> t1, IList<byte> t2)
{
Expand Down Expand Up @@ -427,7 +428,7 @@ private static TileInfo RandomTileInfo(string format = "{0}", int minLevel = 3,
return new TileInfo
{
Extent = new Extent(),
Index = new TileIndex(Rnd.Next(0, max), Rnd.Next(0, max), string.Format(CultureInfo.InvariantCulture, format, level))
Index = new TileIndex(Rnd.Next(0, max), Rnd.Next(0, max), level)
};
}

Expand Down Expand Up @@ -481,14 +482,14 @@ private static bool EqualTileSchemas(ITileSchema ts1, ITileSchema ts2, out strin

foreach(var res1 in tts1.Resolutions.Values)
{
var res2 = tts2.Resolutions[res1.Id];
if (tts1.GetTileHeight(res1.Id) != tts2.GetTileHeight(res2.Id))
var res2 = tts2.Resolutions[res1.Level];
if (tts1.GetTileHeight(res1.Level) != tts2.GetTileHeight(res2.Level))
{
message = "Heights don't match";
return false;
}

if (tts1.GetTileWidth(res1.Id) != tts2.GetTileWidth(res2.Id))
if (tts1.GetTileWidth(res1.Level) != tts2.GetTileWidth(res2.Level))
{
message = "Widths don't match";
return false;
Expand Down Expand Up @@ -536,7 +537,7 @@ private static bool EqualTileSchemas(ITileSchema ts1, ITileSchema ts2, out strin

//!!! compare other resultion parameters.

if (r1.Id != r2.Id || r1.UnitsPerPixel != r2.UnitsPerPixel)
if (r1.Level != r2.Level || r1.UnitsPerPixel != r2.UnitsPerPixel)
{
message = string.Format("Resolution doesn't match at index {0}", key);
return false;
Expand Down
2 changes: 1 addition & 1 deletion UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BruTile.MbTiles" Version="2.1.2" />
<PackageReference Include="BruTile.MbTiles" Version="3.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Npgsql" Version="4.0.10" />
<PackageReference Include="NUnit" Version="3.12.0" />
Expand Down