Skip to content

Commit fe38642

Browse files
committed
Make things less ambiguous + make them work
1 parent 024b84e commit fe38642

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

examples/raster_warping_masking.jl

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,26 @@ Cover = fig
66

77
using CairoMakie, GeoMakie
88
using Rasters, ArchGDAL,NaturalEarth, FileIO
9-
import GeoInterface as GI, GeometryOps as GO
109

10+
# ## Background setup
1111
# Set up the background. First, load the image,
12-
## blue_marble_image = FileIO.load(FileIO.query(download("https://eoimages.gsfc.nasa.gov/images/imagerecords/76000/76487/world.200406.3x5400x2700.jpg"))) |> rotr90 .|> RGBA{Makie.Colors.N0f8} # need to make sure this is RGBA
12+
blue_marble_image = FileIO.load(FileIO.query(download("https://eoimages.gsfc.nasa.gov/images/imagerecords/76000/76487/world.200406.3x5400x2700.jpg"))) |> rotr90 .|> RGBA{Makie.Colors.N0f8}
1313
# Your other choice is:
1414
blue_marble_image = GeoMakie.earth() |> rotr90 .|> RGBA{Makie.Colors.N0f8}
15-
16-
17-
# and wrap it as a Raster for easy masking.
18-
blue_marble_raster = Raster(blue_marble_image, (X(LinRange(-180, 180, size(blue_marble_image, 1))), Y(LinRange(-90, 90, size(blue_marble_image, 2)))))
15+
# For the purposes of this example, we'll use the Natural Earth background image,
16+
# since it's significantly smaller and the poor CI machine can't handle huge images.
17+
18+
# We wrap the image as a Raster for easy masking.
19+
blue_marble_raster = Raster(
20+
blue_marble_image, # the contents
21+
( # the dimensions go in this tuple. `X` and `Y` are defined by the Rasters ecosystem.
22+
X(LinRange(-180, 180, size(blue_marble_image, 1))),
23+
Y(LinRange(-90, 90, size(blue_marble_image, 2)))
24+
)
25+
)
1926
# Construct a mask of land using Natural Earth land polygons
2027
land_mask = Rasters.boolmask(NaturalEarth.naturalearth("land", 10); to = blue_marble_raster)
21-
28+
#
2229
land_raster = deepcopy(blue_marble_raster)
2330
land_raster[(!).(land_mask)] .= RGBA{Makie.Colors.N0f8}(0.0, 0.0, 0.0, 0.0)
2431
land_raster
@@ -27,6 +34,8 @@ sea_raster = deepcopy(blue_marble_raster)
2734
sea_raster[land_mask] .= RGBA{Makie.Colors.N0f8}(0.0, 0.0, 0.0, 0.0)
2835
sea_raster
2936

37+
# ## Constructing fake data
38+
3039
# Now, we construct fake data.
3140
field = [exp(cosd(x)) + 3(y/90) for x in -180:180, y in -90:90]
3241

@@ -49,6 +58,7 @@ transformed = Rasters.warp(
4958
)
5059
)
5160

61+
# ## Plotting the data
5262

5363
fig = Figure(size = (1000, 1000))
5464
ax = GeoAxis(fig[1, 1]; dest = "+proj=ortho +lon_0=0 +lat_0=0")
@@ -73,3 +83,28 @@ center_y = mean(last.(xy_matrix))
7383
ax.dest = "+proj=ortho +lon_0=$(center_x) +lat_0=$(center_y)"
7484

7585
fig
86+
87+
# ## Plotting on the 3D globe
88+
89+
# Super bonus points: plot the data on the globe
90+
91+
using Geodesy
92+
93+
fig = Figure(size = (1000, 1000));
94+
95+
ax = LScene(fig[1, 1])
96+
97+
sea_plot = meshimage!(ax, sea_raster; npoints = 300)
98+
99+
land_plot = meshimage!(ax, land_raster; npoints = 300)
100+
101+
data_plot = surface!(ax, transformed; shading = NoShading)
102+
103+
land_plot.z_level[] = 1
104+
data_plot[:depth_shift] = -0.00
105+
106+
sea_plot.transformation.transform_func[] = Geodesy.ECEFfromLLA(Geodesy.WGS84())
107+
land_plot.transformation.transform_func[] = Geodesy.ECEFfromLLA(Geodesy.WGS84())
108+
data_plot.transformation.transform_func[] = Geodesy.ECEFfromLLA(Geodesy.WGS84())
109+
110+
fig

0 commit comments

Comments
 (0)