Skip to content
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

Template for GeoAxis #92

Closed
SimonDanisch opened this issue Oct 29, 2021 · 14 comments
Closed

Template for GeoAxis #92

SimonDanisch opened this issue Oct 29, 2021 · 14 comments
Labels
makiecon Issues to address at MakieCon

Comments

@SimonDanisch
Copy link
Member

Until MakieOrg/Makie.jl#1355 is merged, we can use something like this for a GeoAxis:

using GLMakie, GeoMakie
using GeoMakie.GeoInterface
using GeoMakie.GeoJSON
using Proj4

struct GeoAxis
    axis::LScene
    kw
end

function GeoAxis(args...; source = "+proj=longlat +datum=WGS84", dest = "+proj=natearth2", kw...)
    trans = Proj4.Transformation(source, dest, always_xy=true)
    ptrans = Makie.PointTrans{2}(trans)
    ax = LScene(args...; scenekw=(show_axis=false, camera=cam2d!))
    # TODO, pass this to scenekw?!
    ax.scene.transformation.transform_func[] = ptrans
    # here you can draw in any axis grids etc
    return GeoAxis(ax, kw)
end

function bb_transformed(plot::AbstractPlot)
    # Relies on Makie#master 
    # There's definitely also a way to make thise work on tagged Makie...
    bb_ref = Base.RefValue(Rect3f())
    points = Makie.point_iterator(plot)
    t = Makie.transformation(plot)
    model = Makie.model_transform(t)
    trans_func = t.transform_func[]
    Makie.foreach_transformed(points, model, trans_func) do point
        Makie.update_boundingbox!(bb_ref, point)
    end
    return bb_ref[]
end


function Makie.plot!(
        ta::GeoAxis, P::Makie.PlotFunc,
        attributes::Makie.Attributes, args...)
    # Do PlotFunc (Heatmap, Surface, etc) specific overloads here
    p = Makie.plot!(ta.axis.scene, P, attributes, args...)
    # Do custom, GeoAxis specific things like updating the transformed limits
    update_cam!(ta.axis.scene, bb_transformed(p))
    return p
end

# just part of overloading the pipeline... The above is the more generic one!
function Makie.plot!(P::Makie.PlotFunc, ax::GeoAxis, args...; kw_attributes...)
    Makie.plot!(ax, P, Attributes(kw_attributes), args...)
end

fig = Figure()
ax = GeoAxis(fig[1, 1])

lats = -90:10.0:90
lons = -180:10.0:180
lons = collect(lons)
lons[end] = prevfloat(lons[end])  # avoid PROJ wrapping 180 to -180
field = [exp(cosd(l)) + 3(y/90) for l in lons, y in lats]

p = wireframe!(ax, lons, lats, field, color=(:gray, 0.2), transparency=true)
fig
@Datseris
Copy link
Collaborator

can you [paste the figure this produces please?

@SimonDanisch
Copy link
Member Author

image

@Datseris
Copy link
Collaborator

Datseris commented Oct 29, 2021

@SimonDanisch is this GeoAxis layoutable? Can I write fig[5,5] = GeoAxis(fig, ...) and potentially have a 5x5 geoplots?

@SimonDanisch
Copy link
Member Author

With this setup you can write:

GeoAxis(fig[5,5], ...)

For a grid... It's not a layoutable itself, but that will be easy in the future once MakieOrg/Makie.jl#1355 is merged...

@Datseris
Copy link
Collaborator

Datseris commented Oct 29, 2021

also, how do we add actual ticks into this plot? This may be the critical part actually :D To make the wireframe is something one could do even before GeoAxis.

@SimonDanisch
Copy link
Member Author

with text!(ax.scene, ...) 🤷 maybe one can re-use lineaxis for that: https://github.com/JuliaPlots/Makie.jl/blob/master/src/makielayout/lineaxis.jl#L1

To make the wireframe is something one could do even before GeoAxis.

Yeah, I didn't say I have a finished GeoAxis, I only have a template for the correct overloads to make a new, axis like object ;)

@Datseris
Copy link
Collaborator

ooof, I'm really afraid now :D The source in the link is well beyond my level of familiarity which makes me skeptical if I'm able to "finish" this GeoAxis so that it has "automatic" ticks. My understanding is that the problem of just writing text!(ax.scene, ...) is that the ticks would dissapear if you zoomed into the axis, which isn't really what's supposed to happen with ticks :D

@SimonDanisch
Copy link
Member Author

We could also go for a solution hijacking Axis directly:

function GeoAxis(args...; source = "+proj=longlat +datum=WGS84", dest = "+proj=natearth2", kw...)
    trans = Proj4.Transformation(source, dest, always_xy=true)
    ptrans = Makie.PointTrans{2}(trans)
    # some ticks that work better for the projection
    xticks = ...
    yticks = ... 
    # interpolate_grid would need to be implemented in the axis code, but that should be fairly straightforward 
    # needed to make the grid warp correctly
    ax = Axis(args...; xticks=xticks, yticks=yticks, interpolate_grid=true)
    # TODO, pass this to scenekw?!
    ax.scene.transformation.transform_func[] = ptrans
    # here you can draw in any axis grids etc
    return ax
end

@Datseris
Copy link
Collaborator

that's exactly what I'm doing in #93 (but do not define GeoAxis but geosurface instead.

@SimonDanisch
Copy link
Member Author

geosurface isn't that a plotting function, and not something that creates an axis?

@Datseris
Copy link
Collaborator

Datseris commented Oct 29, 2021

yes it does exactly the code you pasted above and at the end calls surface!(ax, ...) just see the source in the pr it will become clear immediatelly

@Datseris
Copy link
Collaborator

i'll push the generation of GeoAxis and remove geosurface in like 10 minutes

@asinghvi17
Copy link
Member

Is there a way to make GeoAxis inherit Axis's attributes? That would make things a lot easier and more observable-friendly, too. Right now, for example, if you want to change the transformation post-axis creation, it's a pain.

@asinghvi17 asinghvi17 linked a pull request Feb 1, 2023 that will close this issue
5 tasks
@asinghvi17 asinghvi17 added the makiecon Issues to address at MakieCon label Mar 26, 2023
@asinghvi17
Copy link
Member

I think the basic structure of this is implemented in #207 and before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
makiecon Issues to address at MakieCon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants