Skip to content

Commit

Permalink
Added C# method TileIdsForBoundingBox
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudbeatsch committed Jun 13, 2016
1 parent 07bfc15 commit aea9ee3
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion csharp/Tile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@

namespace GeoTile
{
class Tile
public class BoundingBox
{
public double LatitudeNorth { get; set; }
public double LatitudeSouth { get; set; }
public double LongitudeWest { get; set; }
public double LongitudeEast { get; set; }
}
public class Tile
{
public string TileId { get; set; }
public UInt64 Row { get; set; }
Expand Down Expand Up @@ -72,5 +79,31 @@ public static String IdFromRowColumn(UInt64 row, UInt64 column, UInt16 zoom)
{
return zoom + "_" + row + "_" + column;
}

public static List<Tile> TileIdsForBoundingBox(BoundingBox bBox, UInt16 zoom)
{
var tileNWId = Tile.IdFromLatLong(bBox.LatitudeNorth, bBox.LongitudeWest, zoom);
var tileSEId = Tile.IdFromLatLong(bBox.LatitudeSouth, bBox.LongitudeEast, zoom);

var tileNW = Tile.FromTileId(tileNWId);
var tileSE = Tile.FromTileId(tileSEId);

ulong rowDelta = tileSE.Row - tileNW.Row;
ulong columnDelta = tileSE.Column - tileNW.Column;

List<Tile> spanningTileIds = new List<Tile>();
for (ulong rowIdx = 0; rowIdx <= rowDelta; rowIdx++)
{
for (ulong columnIdx = 0; columnIdx <= columnDelta; columnIdx++)
{
spanningTileIds.Add(
FromTileId(
IdFromRowColumn(tileNW.Row + rowIdx, tileNW.Column + columnIdx, zoom)
)
);
}
}
return spanningTileIds;
}
}
}

0 comments on commit aea9ee3

Please sign in to comment.