Sorry, it’s not option G it’s option L, which in GMT.jl is aliased to dist2line. (read the linked description of that option)
I know what you are after (I needed that operation several times before) and I’m sure GMT does it with ellipsoidal accuracy if needed. See this small example that is computing the closest point along the great circle line between [0 0] and [1 1] from point at [0.5 0.5]
julia> mapproject([0.5 0.5], dist2line=[0.0 0; 1 1])
1×5 GMTdataset{Float64, 2}
Row │ col.1 col.2 col.3 col.4 col.5
─────┼───────────────────────────────────────────
1 │ 0.5 0.5 4.46581 0.499972 0.500029
The results are in meters and col3=dist, col4=lon_along_line; col5=lat_along_line
In your real case the command should be
mapproject([lon lat], dist2line=D)
and since you have 542 segments, you’ll have 542 rows. You can test it with a single segment (the first) with
mapproject([lon lat], dist2line=D[1])