Skip to content

Commit

Permalink
Fix all example errors
Browse files Browse the repository at this point in the history
  • Loading branch information
asinghvi17 committed Jun 7, 2024
1 parent 5f18baa commit 3bf0f0e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
3 changes: 2 additions & 1 deletion examples/gmt/antioquia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ f
# using GeometryOps.jl to calculate the centroid.
import GeometryOps as GO
cx, cy = GO.centroid(antioquia_geoms)
#
a.dest = "+proj=ortho +lon_0=$cx +lat_0=$cy"
f
# That looks a lot more like what the GMT example does!

#
# make cover image #jl
mkpath("covers") #hide
save("covers/$(splitext(basename(@__FILE__))[1]).png", fig) #hide
save("covers/$(splitext(basename(@__FILE__))[1]).png", f) #hide
nothing #hide
11 changes: 7 additions & 4 deletions examples/is_it_a_plane.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ f, a, p = lines(reverse(Proj.geod_path(geod, reverse(jfk)..., reverse(sin)...)).
# relative distances along the path, and altitudes of observation, as
# a function of time. This is done by using the Animations.jl library.

times = [0, 0.5, 17.5, 18]
times = [0, 0.5, 30.5, 31]
distances = [0, 0.05, 0.95, 1]
altitudes = [357860, 35786000/2, 35786000/2, 357860]
altitudes = [357860*2, 35786000/2, 35786000/2, 357860*2]
distance_animation = Animation(times, distances, linear())
altitude_animation = Animation(times, altitudes, sineio())

Expand All @@ -47,11 +47,14 @@ satview_projection = lift(sl.value) do alt
end
ga = GeoAxis(fig[1, 1]; dest = satview_projection)
meshimage!(ga, -180..180, -90..90, GeoMakie.earth(), shading = NoShading)
lines!(ga, GeoMakie.coastlines())
fig

#

record(fig, "plots/plane.mp4", LinRange(0, 1, 120)) do i
satview_projection[] = "+proj=geos +h=$(round(Int, at(altitude_animation, i*18))) +lon_0=$(Proj.geod_position_relative(inv_line, i)[2]) +lat_0=$(Proj.geod_position_relative(inv_line, i)[1])"
record(fig, "plane.mp4", LinRange(0, 1, 240)) do i
current_position = Proj.geod_position_relative(inv_line, i)
satview_projection[] = "+proj=geos +h=$(round(Int, at(altitude_animation, i*18))) +lon_0=$(current_position[2])"
yield()
end
# ![](plane.mp4)
Expand Down
14 changes: 7 additions & 7 deletions examples/multiple_crs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ using CairoMakie, GeoMakie
using Rasters, RasterDataSources, ArchGDAL
CairoMakie.activate!(px_per_unit = 4) # hide

worldclim_temp = Raster(WorldClim{Climate}, :tmax; month = 1)
# Let's simulate a new CRS, assuming this was an image taken from a satellite:
new_worldclim = Rasters.warp(
worldclim_temp,
ras = Raster(EarthEnv{HabitatHeterogeneity}, :homogeneity)
# Let's simulate a new CRS, assuming this was an image taken from a geostationary satellite, hovering above 72° E:
projected_ras = Rasters.warp(
ras,
Dict(
"s_srs" => convert(GeoFormatTypes.ProjString, Rasters.crs(worldclim_temp)).val, # source CRS
"s_srs" => convert(GeoFormatTypes.ProjString, Rasters.crs(ras)).val, # source CRS
"t_srs" => "+proj=geos +h=3578600 +lon_0=72" # the CRS to which this should be transformed
)
)
# This is what the raster would look like, if it were taken directly from a satellite image:
heatmap(new_worldclim; axis = (; aspect = DataAspect()))
heatmap(projected_ras; axis = (; aspect = DataAspect()))
# Now, we can create a GeoAxis with coastlines in the equal earth projection:
fig = Figure()
ga = GeoAxis(fig[1, 1])
Expand All @@ -24,7 +24,7 @@ fig
# The coastlines function returns points in the (lon, lat) coordinate reference system.

# We will now plot our image, from the geostationary coordinate system:
surface!(ga, new_worldclim; shading = NoShading, source = convert(GeoFormatTypes.ProjString, Rasters.crs(new_worldclim)).val)
surface!(ga, projected_ras; shading = NoShading, source = Rasters.crs(projected_ras))
fig
# Success! You can clearly see how the raster was adapted here.
#
Expand Down
10 changes: 6 additions & 4 deletions src/projection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,11 @@ end
# GeoFormatTypes integration #
########################################

const _GFTCRS = Union{GeoFormatTypes.CoordinateReferenceSystemFormat, GeoFormatTypes.WellKnownText{GeoFormatTypes.CRS}}
# Define methods for GeoFormatTypes CRS objects and all possible combinations thereof.
create_transform(dest::GeoFormatTypes.CoordinateReferenceSystemFormat, source::GeoFormatTypes.CoordinateReferenceSystemFormat) = create_transform(gft2str(dest), gft2str(source))
create_transform(dest::String, source::GeoFormatTypes.CoordinateReferenceSystemFormat) = create_transform(dest, gft2str(source))
create_transform(dest::GeoFormatTypes.CoordinateReferenceSystemFormat, source::String) = create_transform(gft2str(dest), source)
create_transform(dest::_GFTCRS, source::_GFTCRS) = create_transform(gft2str(dest), gft2str(source))
create_transform(dest::String, source::_GFTCRS) = create_transform(dest, gft2str(source))
create_transform(dest::_GFTCRS, source::String) = create_transform(gft2str(dest), source)

"""
gft2str(crs)::String
Expand All @@ -152,4 +153,5 @@ Return a PROJ-compatible string from a GeoFormatTypes CRS object.
"""
function gft2str end
gft2str(crs::GeoFormatTypes.EPSG{1}) = String("EPSG:$(GeoFormatTypes.val(crs))")
GeoFormatTypes2str(crs::GeoFormatTypes.CoordinateReferenceSystemFormat) = string(GeoFormatTypes.val(crs))
gft2str(crs::GeoFormatTypes.CoordinateReferenceSystemFormat) = string(GeoFormatTypes.val(crs))
gft2str(crs::GeoFormatTypes.WellKnownText{GeoFormatTypes.CRS}) = string(GeoFormatTypes.val(crs))

0 comments on commit 3bf0f0e

Please sign in to comment.