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
1 change: 1 addition & 0 deletions .github/workflows/Documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- master
- AddInterpolations
tags: '*'
pull_request:

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- master
- AddInterpolations
tags: '*'
pull_request:

Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DocumenterMarkdown = "997ab1e6-3595-5248-9280-8efb232c3433"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
LightOSM = "d1922b25-af4e-4ba3-84af-fe9bea896051"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
MapTiles = "fea52e5a-b371-463b-85f5-81770daa2737"
Expand Down
32 changes: 32 additions & 0 deletions docs/examples/UserGuide/interpolation.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# # Using Interpolation On The Fly

using Tyler, GLMakie
using Interpolations: interpolate, Gridded, Linear

f(lon,lat)=cosd(16*lon)+sind(16*lat)

f_in_0_1_range(lon,lat)=0.5+0.25*f(lon,lat)

nodes=(-180.0:180.0, -90.0:90.0)
array=[f(lon,lat) for lon in nodes[1], lat in nodes[2]]
array=(array.-minimum(array))./(maximum(array)-minimum(array))
itp = interpolate(nodes, array, Gridded(Linear()))
cols=Makie.to_colormap(:viridis)
col(i)=RGBAf(Makie.interpolated_getindex(cols,i))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't these be part of Interpolator? It seems like some unnecessary work to set it up.

They could be keywords if people did need to customise?

fun(x,y) = col(itp(x,y))

options = Dict(:min_zoom => 1,:max_zoom => 19)
p1=Tyler.Interpolator(f_in_0_1_range,options)
p2=Tyler.Interpolator(fun,options)

b = Rect2f(-20.0, -20.0, 40.0, 40.0)
m = Tyler.Map(b, provider=p1)

# !!! info
# Sine Waves

# !!! tip
# Try `b = Rect2f(-180.0, -89.9, 360.0, 179.8)`

# !!! tip
# `interpolated_getindex` requires input `i` to be in the 0-1 range
3 changes: 2 additions & 1 deletion docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ nav:
- "Ice loss animation" : "examples/generated/UserGuide/iceloss_ex.md"
- "Map Tile providers" : "examples/generated/UserGuide/providers.md"
- "OSMMakie integration" : "examples/generated/UserGuide/osmmakie.md"
- "On The Fly Interpolation" : "examples/generated/UserGuide/interpolation.md"
- "Contributors":
- "Contribute to Documentation" : "examples/generated/Contributors/Howto.md"
- "Contribute to Documentation" : "examples/generated/Contributors/Howto.md"
29 changes: 26 additions & 3 deletions src/Tyler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ using OrderedCollections
using HTTP
using ImageMagick

include("for_interpolations.jl")
using Tyler.ForInterpolations: tile2positions, Interpolator

const TileImage = Matrix{RGB{N0f8}}

struct Map
Expand Down Expand Up @@ -211,14 +214,34 @@ function create_tile_plot!(tyler::Map, tile::Tile, image::TileImage)
place_tile!(tile, mplot, tyler.coordinate_system)
end

##

function fetch_tile(tyler::Map, tile::Tile)
return get!(tyler.fetched_tiles, tile) do
url = TileProviders.geturl(tyler.provider, tile.x, tile.y, tile.z)
result = HTTP.get(url; retry=false, readtimeout=4, connect_timeout=4)
return ImageMagick.readblob(result.body)
fetch_tile(tyler.provider,tile)
end
end

function fetch_tile(provider::AbstractProvider, tile::Tile)
url = TileProviders.geturl(provider, tile.x, tile.y, tile.z)
result = HTTP.get(url; retry=false, readtimeout=4, connect_timeout=4)
return ImageMagick.readblob(result.body)
end

cols=Makie.to_colormap(:thermal)
col(i)=RGBAf(Makie.interpolated_getindex(cols,i))
col(i::RGBAf)=i

function fetch_tile(provider::Interpolator, tile::Tile)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could go in the interpolator module

itp=provider.url
(lon,lat) = tile2positions(tile)
z = permutedims(itp.(lon,lat))
return [col(i) for i in z]
end


##

function queue_tile!(tyler::Map, tile)
queue = tyler.tiles_being_added
# NO need to start a need task!
Expand Down
28 changes: 28 additions & 0 deletions src/for_interpolations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module ForInterpolations

using MapTiles
using TileProviders: AbstractProvider
export tile2positions, Interpolator

lng2tile(lng, zoom) = floor((lng+180)/360*2^zoom)
lat2tile(lat, zoom) = floor((1-log(tan(lat*pi/180)+1/cos(lat*pi/180))/pi)/2*2^zoom)

tile2lng(x, z) = (x/2^z*360)-180
tile2lat(y, z) = - 180/pi*atan(0.5*(exp(pi-2*pi*y/2^z)-exp(2*pi*y/2^z-pi)))

tile2positions(tile::Tile) = tile2positions(tile.x,tile.y,tile.z)

function tile2positions(x,y,z)
rng=range(0.5/232,231.5/232,232)
lons=[tile2lng(x+i,z) for i in rng, j in rng]
lats=[tile2lat(y+j,z) for i in rng, j in rng]
(lons,lats)
end

struct Interpolator <: AbstractProvider
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could do with some docs? I know the rest of the package is pretty short on docs, but it would be good to know what url and options are

url::Function
options::Dict{Symbol,Any}
end

end