MakieOrg / GeoMakie.jl

Geographical plotting utilities for Makie.jl
https://geo.makie.org
MIT License
161 stars 23 forks source link

Cutout of Projection / Correct handling of limits #254

Open yum-yab opened 1 week ago

yum-yab commented 1 week ago

For my thesis I wanted to use Albers Equal Area Projection or Orthographic projection, but unfortunately im not able to cut out my area of interest (Europe). I tried following along the Documentation provided here.

My code is the following:

using GLMakie, GeoMakie

fig = Figure()
ga1 = GeoAxis(fig[1, 1]; dest = "+proj=aea +lat_1=20 +lat_2=80 +lat_0=90 +lon_0=-25 +x_0=0 +y_0=0", limits=((-90, 40), (20, 80)))
ga2 = GeoAxis(fig[1, 2]; dest = "+proj=merc", limits=((-90, 40), (20, 80)))

ga3 = GeoAxis(fig[2, 1]; dest = "+proj=ortho +lat_0=50 +lon_0=-25", limits=((-90, 40), (20, 80)))
ga4 = GeoAxis(fig[2, 2]; dest = "+proj=ortho +lat_0=50 +lon_0=-25")

lines!(ga1, GeoMakie.coastlines())
lines!(ga2, GeoMakie.coastlines())
lines!(ga3, GeoMakie.coastlines())
lines!(ga4, GeoMakie.coastlines())

fig

And the result looks like: weird_cutouts

I expected the orthographic and aea projection to cut out along lon/lat lines simiar to the merc projection in the top right, but the behaviour is pretty strange. Without the limits the center and everything looks right to me (bottom right).

I'm also not able to fix the limits afterward because using xlims!(ga4, (-90, 40)) yields:

InexactError: trunc(Int64, Inf)

Stacktrace:
  [1] trunc
    @ ./float.jl:905 [inlined]
  [2] round
    @ ./float.jl:385 [inlined]
  [3] macro expansion
    @ ~/.julia/packages/StaticArrays/YN0oL/src/broadcast.jl:135 [inlined]
  [4] __broadcast
    @ ~/.julia/packages/StaticArrays/YN0oL/src/broadcast.jl:123 [inlined]
  [5] _broadcast
    @ ~/.julia/packages/StaticArrays/YN0oL/src/broadcast.jl:119 [inlined]
  [6] copy
    @ ~/.julia/packages/StaticArrays/YN0oL/src/broadcast.jl:60 [inlined]
  [7] materialize
    @ ./broadcast.jl:903 [inlined]
  [8] round_to_IRect2D(r::GeometryBasics.HyperRectangle{2, Float32})
    @ Makie ~/.julia/packages/Makie/iRM0c/src/makielayout/helpers.jl:7
  [9] (::Makie.var"#1456#1457")(bbox::GeometryBasics.HyperRectangle{2, Float32}, limits::GeometryBasics.HyperRectangle{2, Float64}, aspect::DataAspect)
    @ Makie ~/.julia/packages/Makie/iRM0c/src/makielayout/helpers.jl:49
 [10] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base ./essentials.jl:892
 [11] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base ./essentials.jl:889
...
    @ ~/.julia/packages/GeoMakie/DMLIe/src/makie-axis.jl:44 [inlined]
 [28] xlims!(ax::GeoAxis, xlims::Tuple{Int64, Int64})
    @ GeoMakie ~/.julia/packages/GeoMakie/DMLIe/src/makie-axis.jl:449

Am I doing something wrong? Or how could I achieve my goal?

Thanks for the help in advance!

yum-yab commented 1 week ago

I also tried to find how I could configure the GeoAxis for my needs but the corresponding page looks very weird, is that a bug? https://geo.makie.org/v0.7.2/examples/axis_config

asinghvi17 commented 1 week ago

Ah yeah, there are quite a few bugs and issues surrounding limits :D

I could possibly add a polygon that just "clips" everything outside certain lat/lon boundaries. That would probably solve your first issue but not the second.

Am a bit tied up right now but will write a full response later today!

yum-yab commented 4 days ago

Hi, thanks a lot for the help! Are there any updates on a workaround @asinghvi17 ?