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

[WIP] Globe axis #278

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ jobs:
Pkg.add([
PackageSpec(path = pwd()),
PackageSpec(name = "DocumenterVitepress", rev = "master"),
# PackageSpec(name = "Makie", rev = "master"),
# PackageSpec(name = "MakieCore", rev = "master"),
# PackageSpec(name = "CairoMakie", rev = "master"),
PackageSpec(name = "Makie", rev = "master"),
PackageSpec(name = "MakieCore", rev = "master"),
PackageSpec(name = "CairoMakie", rev = "master"),
PackageSpec(name = "GLMakie", rev = "master"),
PackageSpec(name = "Rasters", rev = "main"),
PackageSpec(name = "ArchGDAL", rev = "master"),
PackageSpec(url = "https://github.com/asinghvi17/OhMyCards.jl", rev = "main"),
Expand Down
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.7.9"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
GeoFormatTypes = "68eda718-8dee-11e9-39e7-89f7f65f511f"
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
Expand All @@ -24,17 +25,18 @@ StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"

[compat]
Colors = "0.12"
CoordinateTransformations = "0.6.3"
Downloads = "1"
GeoFormatTypes = "0.4"
GeoInterface = "0.5, 1.0"
GeoInterfaceMakie = "0.1.6"
GeoJSON = "0.6, 0.7, 0.8"
Geodesy = "1.1.0"
GeometryBasics = "0.4.11"
GeometryBasics = "0.4.11, 0.5"
GeometryOps = "0.1.6"
ImageIO = "0.6"
LinearAlgebra = "1"
Makie = "0.21.6"
Makie = "0.21.6, 0.22"
NaturalEarth = "0.1"
Proj = "1"
Reexport = "1"
Expand Down
30 changes: 30 additions & 0 deletions examples/earth3d.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using GLMakie, GeoMakie, Geodesy

transf = Geodesy.ECEFfromLLA(Geodesy.WGS84())

f, a, p = meshimage(-180..180, -90..90, GeoMakie.earth(); npoints = 100, z_level = 0, axis = (; type = LScene));
lp = lines!(a, Point3f.(1:10, 1:10, 110); color = :red, linewidth = 2)
cc = cameracontrols(a.scene)
cc.settings.mouse_translationspeed[] = 0.0
cc.settings.zoom_shift_lookat[] = false
Makie.update_cam!(a.scene, cc)
p.transformation.transform_func[] = transf
lp.transformation.transform_func[] = transf
f

# Now, you can scroll around the globe, and the axis will not zoom at all!


# Create a white background to obscure some lines you're plotting on the globe:

random_latlong_points = Point2f.(rand(12) .* 360 .- 180, rand(12) .* 180 .- 90)

f, a, bg_plot = meshimage(-180..180, -90..90, GeoMakie.earth(); npoints = 100, z_level = -20_000, axis = (; type = LScene))
bg_plot.transformation.transform_func[] = transf

# Now, plot some lines on the globe:

lineplot = lines!(a, GO.segmentize(GO.GeodesicSegments(; max_distance = 100_000), random_latlong_points); color = :black, linewidth = 2)
lineplot.transformation.transform_func[] = transf

f
File renamed without changes.
100 changes: 100 additions & 0 deletions examples/piracy_at_sea.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using Makie, GeoMakie

using GeoJSON, QuackIO, DataFrames
using Downloads

import GeometryOps as GO, GeoInterface as GI, Proj

shipping_routes_file = download("https://raw.githubusercontent.com/newzealandpaul/Shipping-Lanes/refs/tags/v1.3.1/data/Shipping_Lanes_v1.geojson", "Shipping_Lanes_v1.geojson")
pirate_attacks_file = download("https://raw.githubusercontent.com/newzealandpaul/Maritime-Pirate-Attacks/refs/heads/main/data/csv/pirate_attacks.csv", "pirate_attacks.csv")

shipping_routes = GeoJSON.read(shipping_routes_file)
pirate_attacks = QuackIO.read_csv(DataFrame, pirate_attacks_file)

major = shipping_routes.geometry[findfirst(==("Major"), shipping_routes.Type)]
middle = shipping_routes.geometry[findfirst(==("Middle"), shipping_routes.Type)]
minor = shipping_routes.geometry[findfirst(==("Minor"), shipping_routes.Type)]

pirate_attacks = DataFrame(CSV.File(pirate_attacks_file; dateformat = "YYYY-MM-DD"))

using Rasters
using Dates

pirate_attacks.pre2015 = year.(pirate_attacks.date) .<= 2015

groups = groupby(pirate_attacks, :pre2015; sort = true)

r1 = rasterize(sum, tuple.(groups[1].longitude, groups[1].latitude); fill = 1, res = 0.5, crs = Rasters.EPSG(4326))
r2 = rasterize(sum, tuple.(groups[2].longitude, groups[2].latitude); fill = 1, res = 0.5, crs = Rasters.EPSG(4326))

pts = DimIndices(r1)[(!ismissing).(r1)]
attrs

dt = DimTable(r1; mergedims = (X, Y)) |> DataFrame |> x -> dropmissing(x, :sum)
dt.XY |> x -> reinterpret(Float64, x)



fig = Figure(; size = (1000, 750))
ax = GeoAxis(fig[1, 1]; dest = "+proj=wintri")
# ax = Axis(fig[1, 1]; aspect = DataAspect())
background_plot = meshimage!(ax, -180..180, -90..90, reshape([RGBf(231/255, 255/255, 255/255)], 1, 1))

using NaturalEarth
country_plot = poly!(ax, naturalearth("admin_0_countries", 110).geometry; color = RGBf(221/255, 234/255, 214/255), strokewidth = 1, strokecolor = :white)


major_plot = lines!(ax, major)
middle_plot = lines!(ax, middle)
minor_plot = lines!(ax, minor)

major_plot.linewidth = 4
middle_plot.linewidth = 2

minor_plot.visible = false

major_plot.color = RGBAf(165/255, 223/255, 246/255, 1);
middle_plot.color = RGBAf(165/255, 234/255, 255/255, 1);


using Clustering
columns_as_points = permutedims(hcat(groups[1].longitude, groups[1].latitude))
res = Clustering.kmeans(columns_as_points, 30)
centers = splat(tuple).(eachcol(res.centers))
markersizes = res.counts

sp1 = scatter!(ax, centers; markersize = sqrt.(markersizes) .* 1.5, color = color = RGBf(156/255, 96/255, 178/255))


columns_as_points = permutedims(hcat(groups[2].longitude, groups[2].latitude))
res = Clustering.kmeans(columns_as_points, 110)
centers = splat(tuple).(eachcol(res.centers))
markersizes = res.counts

sp2 = scatter!(ax, centers; markersize = sqrt.(markersizes) .* 1.5, color = RGBf(65/255, 183/255, 153/255))

sp2.alpha = 0.6

# ylims!(ax, -60, 84)

translate!(sp1, 0, 0, 1)
# ax.aspect[] = 360 #= degrees longitude =# / (84 + 60) #= degrees latitude =#


leg_gl = GridLayout(fig[2, 1])

leg1 = Legend(
leg_gl[1,1],
[MarkerElement(; marker = sp2.marker, color = sp1.color, markersize) for markersize in sqrt.([5, 15, 30, 60]) .* 1.5],
["1-10", "11-20", "21-40", "41-80"],
"Pirate Attacks 2015-2020"
)

leg2 = Legend(
leg_gl[2,1],
[MarkerElement(; marker = sp2.marker, color = sp2.color, markersize) for markersize in sqrt.([5, 15, 30, 60]) .* 1.5],
["1-10", "11-20", "21-40", "41-80"],
"Pirate Attacks 2010-2015"
)

fig
13 changes: 0 additions & 13 deletions examples/specialized/earth3d.jl

This file was deleted.

Loading
Loading