pyGMT find optimal path between two geographic coordinates with elevation gain/loss

I’m new to pyGMT here, but as an experienced Python developer, I’m struggling with the plethora of awesome features available. I’ve created a map of ~60 points along a mountain range. These points represent known locations on journey by foot. I’m trying to connect them with the optimal path and would like to implement A* or similar which would penalize paths taken over long distances and high elevation deltas while also going around obstacles which travelers would reasonably go around.

  • Does pyGMT offer something like this out of the box?
  • can pyGMT generate a transect along the “optimal” line instead of a straight line between A&B (as in the below example)?

I’ve based my code off of this example: Cross-section along a transect — PyGMT

my data frame of points is very simple and looks like: df[['name', 'latitude', 'longitude']]
I’ve only added this snippet below to map each location on the map

fig.text(
    text="  "+df['name'],
    x=df['longitude'],
    y=df['latitude'],
    font="2p,Helvetica-Bold",
    justify="lm"
)

Hi Su,

As far as I know there are no opimization algorithms of this nature in pygmt. Greenspline is the closest thing I can think of but isn’t quite what you’re looking for and it doesn’t look like it’s wrapped by pygmt yet. greenspline — GMT 6.6.0 documentation

Pygmt can solve the forward problem. Grdtrack can generate an elevation profile along a track composed of line segments (not just a straight line), and can find critical points along the profile. But implementing the inverse problem from this would be quite the task.

I wonder if you’d have luck plugging in to the API of an application that specialises in routing, like Komoot or Strava.