MakieOrg / GeoMakie.jl

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

unexpected behavior for lines! in GeoAxis #251

Open LukasBarner opened 2 weeks ago

LukasBarner commented 2 weeks ago

Thanks so much for an amazing package :) Recently, I stumbled upon some unexpected behavior for the lines! plot in GeoAxis. See the following MWE, which intends to draw a simplified shipping route from Australia to Chile.

using GeoMakie, CairoMakie, GeometryOps, GeometryBasics

path = LineString(Point2f.([145, 170, -170, -70], [-38, -30, -20, -33]))
fig = Figure()
ga = GeoAxis(fig[1, 1])
lines!(ga, GeoMakie.coastlines())
lines!(ga, path, color = :red)
fig
image

However, based on how the easternmost parts of Russia are treated, I would expect the red line to cross the date line. Is this expected behavior, or is there a different function I could use to achieve the desired behavior?

asinghvi17 commented 2 weeks ago

Hey, glad GeoMakie was useful to you!

The "correct" solution is a bit involved for now, but basically involves using GeometryOps to interpolate the path along the globe, then cutting the resulting line at the antimeridian. I'm hoping to move this within GeoMakie at some stage, but that would need a refactor at the Makie level as well.

import GeometryOps as GO
using GeoMakie, CairoMakie, GeometryBasics

path = LineString(Point2f.([145, 170, -170, -70], [-38, -30, -20, -33]))
interpolated_path = GO.segmentize(GO.GeodesicSegments(; max_distance = 100_000), path) # 100km segments
split_path = Base.split(GeoMakie.geo2basic(interpolated_path), 180.0)

fig = Figure()
ga = GeoAxis(fig[1, 1])
lines!(ga, GeoMakie.coastlines())
lines!(ga, split_path, color = :red)
fig

iTerm2 wC0P3f