# Solving the direct geodesic problem with Proj.jl

**URL:** <https://discourse.julialang.org/t/solving-the-direct-geodesic-problem-with-proj-jl/91409>\
**Category:** Geo\
**Tags:** geodesy\
**Created:** [December 8, 2022, 6:12am UTC](https://discourse.julialang.org/t/solving-the-direct-geodesic-problem-with-proj-jl/91409 "2022-12-08T06:12:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcarion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tcarion/32/27830_2.png) [@tcarion](https://discourse.julialang.org/u/tcarion)\
**Post date:** [December 8, 2022, 6:12am UTC](https://discourse.julialang.org/t/solving-the-direct-geodesic-problem-with-proj-jl/91409/1 "2022-12-08T06:12:08Z")

</div>

Hi!  
I want to calculate the end point after moving some distance in some direction on an ellipsoid.  
I used to use the `Proj4.jl` function `geod_direct`. As this higher level function has disappeared in `Proj.jl`, I’m trying to deal with the lower level version. Taking inspiration from the `C` example in the `proj` docs, I end up with this code:

```julia
g = Ref{Proj.geod_geodesic}()
a = 6378137.; f = 1/298.257223563
Proj.geod_init(g, a, f)

lon, lat, distance, azimuth = 4., 50., 111321., 90.
outlon, outlat = Ref{Cdouble}(), Ref{Cdouble}()
Proj.geod_direct(g, lat, lon, distance, azimuth, outlat, outlon, Ref(0.))

```

And I get: `outlon[], outlat[] == 4.0024797121980935, 50.000253128588675`, which is wrong, I should get something like `5., 50.`.

I’m not used to interfacing `C` in Julia, so maybe I’m doing something stupid here. I also tried to get inspiration from the implementation in ´Proj4.jl´, but the `proj` API has changed since then.

Any hint where this wrong result could come from?

Thank you for your time!

---

<div class="post-metadata">

**Author:** ![anowacki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anowacki/32/17375_2.png) [@anowacki](https://discourse.julialang.org/u/anowacki)\
**Post date:** [December 8, 2022, 4:12pm UTC](https://discourse.julialang.org/t/solving-the-direct-geodesic-problem-with-proj-jl/91409/2 "2022-12-08T16:12:41Z")

</div>

My guess is your problem is that `distance` and `azimuth` are in the wrong order. At least if I calculate the endpoint from travelling 90 m along an azimuth of 111,321° == 81°, I get approximately the same result you obtain above.

It may be useful to you to note that [GeographicLib.jl](https://github.com/anowacki/GeographicLib.jl) provides a Julia implementation of Charles Karney’s algorithm (used by Proj), although it is an unregistered package.

The contents of GeographicLib.jl will be folded into [Geodesics.jl](https://github.com/anowacki/Geodesics.jl) fairly soon and then the latter will be registered.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [December 8, 2022, 4:33pm UTC](https://discourse.julialang.org/t/solving-the-direct-geodesic-problem-with-proj-jl/91409/3 "2022-12-08T16:33:32Z")

</div>

See the [geod](https://www.generic-mapping-tools.org/GMTjl_doc/documentation/gdalfuns/#geod) in GMT.jl  
And a cool application in the [Longest sail](https://www.generic-mapping-tools.org/GMTjl_doc/tutorials/longest_sail/longestsail/)

---

<div class="post-metadata">

**Author:** ![tcarion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tcarion/32/27830_2.png) [@tcarion](https://discourse.julialang.org/u/tcarion)\
**Post date:** [December 9, 2022, 7:47am UTC](https://discourse.julialang.org/t/solving-the-direct-geodesic-problem-with-proj-jl/91409/4 "2022-12-09T07:47:30Z")

</div>

@anowacki  
Wow, sorry, I thought I had really thought through the problem before posting, but apparently I didn’t sufficiently at all, I feel quite stupid 😶‍🌫️.

Yes I would prefer to use GeographicLib.jl but the main stumbling block to me is that it isn’t registered. I’m really happy to know that it will be taken care of soon, thank you!

@joa-quim  
Thank you for the suggestion. GMT.jl seems pretty cool, but I think that’s a quite heavy package, and I just want to use this function at the moment. But I’ll definitely consider using it if I need more of such features!
