A question about extract profile from grd file

Hello everyone, I want to use pygmt to draw the profile line and extract the coordinates and elevation of the profile from the GRD file. Is there any way to draw a figure like this.

You’ll need to draw the profile line using some GIS software (e.g. QGIS, ArcGIS, etc), but assuming you have the line (made up of x, y points) already, you can:

  1. Use pygmt.grdtrack to sample the grid at those x/y points. See https://www.pygmt.org/v0.3.1/gallery/images/track_sampling.html for an example.
  2. Plot the sampled points. You should have a series of x (longitude), y (latitude) and z (elevation) values from Step 1 that can be plotted using fig.plot, see https://www.pygmt.org/v0.3.1/projections/nongeo/cartesian_linear.html for an example.

I’m oversimplifying things a bit, but the above two steps should get you started. Try them out first and let us know if you get stuck on something specific. Good luck!

1 Like

If you refuse to use a GUI, I guess you could also create the profile line by using project.
E.g.

gmt project -C20/70 -E-8/78 -G10 -Q

where

  • -C is starting point
  • -E is end point
  • -G10 is sampling
  • -Q specifies that sampling is in kilometer

I think.

1 Like

Thank you, guys.