MakieOrg / GeoMakie.jl

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

WIP: support for a few `naturalearthdata` datasets #139

Closed haakon-e closed 1 year ago

haakon-e commented 1 year ago

WIP on support for plotting various datasetes from naturalearthdata.com.

The website provides a plethora of datasets that are very nice to use as background images / overlays on Earth-themed plots.

Some comments:

Personally, I'm most interested in plotting more accurate coastlines and ocean bottom, so will probably not work on too much support beyond this.

Note: Just before posting I saw that they may actually have .geojson-type data available for download via github [link], so the Shapefile support may not be needed (at least for these datasets). If the maintainers prefer people to individually download any datasets they may need, I may be happy with adding some info about this to the docs, for others to enjoy.


1. Higher-resolution coastlines()

For this example, I assume the relevant data exists in ~/Downloads/ne_10m_coastline/ne_10m_coastline.shp (download here)

julia> using GeoMakie, GLMakie

julia> fig = Figure(; resolution=(1800,1000))

julia> ga11 = GeoAxis(fig[1,1]; coastlines = false, dest = "+proj=longlat", title="World");

julia> ga12 = GeoAxis(fig[1,2]; coastlines = true, dest = "+proj=longlat", title="Norway", lonlims=(2.5, 20), latlims=(57, 65));

julia> ga21 = GeoAxis(fig[2,1]; coastlines = true, dest = "+proj=longlat", title="Greece", lonlims=(19, 32), latlims=(35, 42));

julia> ga22 = GeoAxis(fig[2,2]; coastlines = true, dest = "+proj=longlat", title="Hawaii", lonlims=(-161, -154), latlims=(20, 23));

julia> lines!.([ga11, ga12, ga21, ga22], Ref(GeoMakie.coastlines_10m()); color=:red);
image

2. Bathymetry contours

Assumes you have the folder ~/Downloads/ne_10m_bathymetry_all/ (download all here)

julia> fig = Figure(; resolution=(1800,1000))

julia> ga = GeoAxis(fig[1,1]; coastlines = true, dest = "+proj=longlat");

julia> bathyplot = lines!(GeoMakie.bathymetry(2000); color=(:red, 0.8));

julia> bathyplot = lines!(GeoMakie.bathymetry(3000); color=(:darkred, 0.8));
image

(Note: I'm not sure if the long straight-ish lines are due to one-off indexing errors on my part in how I read the raw data or if they're actually a part of the dataset).

3. Detailed ocean bottom

Assumes you have the file ~/Downloads/OB_50M/OB_50M.tif (download here)

julia> fig = Figure(; resolution=(1800,1800))

julia> ga = GeoAxis(fig[1,1]; coastlines = true, dest = "+proj=longlat", lonlims = (-180, -125), latlims=(-40,-15));

julia> ga2 = GeoAxis(fig[2,1]; coastlines = true, dest = "+proj=longlat", lonlims = (-180, -125), latlims=(-40,-15));

julia> img = image!(ga, -180..180, -90..90, rotr90(GeoMakie.earth()); interpolate = false);  # regular earth

julia> img = image!(ga2, -180..180, -90..90, rotr90(GeoMakie.oceanbottom_50m()); interpolate = false);

# Optionally, also add the high-res coastplot

julia> coastplot = lines!(ga2, GeoMakie.coastlines_10m(); color=:black);

julia> coastplot = lines!(ga, GeoMakie.coastlines_10m(); color=:black);
image

Here the combination of detailed bathymetry and detailed coastplot really shines, and it becomes apparent the regions where the bathymetry permeates the ocean surface as islands.

asinghvi17 commented 1 year ago

I wouldn't mind spinning this out to a NaturalEarth.jl, which downloads on request then caches using Artifacts, and we could depend on that from GeoMakie. What's your take on this idea @haakon-e? It could probably live in JuliaGeo.

haakon-e commented 1 year ago

I wouldn't mind spinning this out to a NaturalEarth.jl, which downloads on request then caches using Artifacts, and we could depend on that from GeoMakie. What's your take on this idea @haakon-e? It could probably live in JuliaGeo.

Yes, I think a separate repo makes more sense. I'll have to learn how to conditionally cache with Artifacts, but I think that'll be a really nice contribution to the ecosystem. I'll see if I get time to think more about this in the next few weeks. Thanks for your feedback!

asinghvi17 commented 1 year ago

Yeah the Artifacts bit shouldn't be too bad - you just have to mark the artifact which you don't want to pre-download as lazy. Presumably we could also specify some to be auto-downloaded.

Natural Earth has a github repo with all their vector files up as GeoJSON or Shapefile...theoretically, we should be able to retrieve that GeoJSON by downloading the raw files from Github, which would be a pretty clean solution to our artifact problem. People could retrieve the dataset they want by name directly (artifact"ne_10m_coastline") or by some easy accessor function in the same vein as what you wrote in this PR.

haakon-e commented 1 year ago

Thanks @asinghvi17 I added some initial commits here: https://github.com/asinghvi17/NaturalEarth.jl/