-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add z_index function #24
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,26 @@ | |
return Tile(xtile, ytile, zoom) | ||
end | ||
|
||
""" | ||
z_index(extent::Extent, res::NamedTuple, crs::WebMercator) => Int | ||
|
||
Calculate a z value from `extent` and pixel resolution `res` for `crs`. | ||
The rounded mean calculated z-index for X and Y resolutions is returned. | ||
|
||
`res` should be `(X=xres, Y=yres)` to match the extent. | ||
|
||
We assume tiles are the standard 256*256 pixels. Note that this is not an | ||
enforced standard, and that retina tiles are 512*512. | ||
""" | ||
function z_index(extent::Extent, res::NamedTuple, crs::WebMercator) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this also accept tuples (x, y) as Makie does? In that case we can also make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should probably also be a catchall method to error when |
||
ntiles = map(r -> r / 256, res) | ||
tile_size_X = (extent.X[2] - extent.X[1]) / ntiles.X | ||
tile_size_Y = (extent.Y[2] - extent.Y[1]) / ntiles.Y | ||
tile_size = (tile_size_X + tile_size_Y) / 2 | ||
z = log2(CE / tile_size) | ||
return round(Int, z) | ||
end | ||
|
||
struct TileGrid | ||
grid::CartesianIndices{2, Tuple{UnitRange{Int}, UnitRange{Int}}} | ||
z::Int | ||
|
@@ -143,6 +163,7 @@ | |
|
||
Base.length(tilegrid::TileGrid) = length(tilegrid.grid) | ||
Base.size(tilegrid::TileGrid, dims...) = size(tilegrid.grid, dims...) | ||
Base.axes(tilegrid::TileGrid, dims...) = axes(tilegrid.grid, dims...) | ||
Base.getindex(tilegrid::TileGrid, i) = Tile(tilegrid.grid[i], tilegrid.z) | ||
Base.firstindex(tilegrid::TileGrid) = firstindex(tilegrid.grid) | ||
Base.lastindex(tilegrid::TileGrid) = lastindex(tilegrid.grid) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it's best to directly add the tile size as an argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I considered that too. I guess a keyword with default is best.