Hi everyone!
I’d like to automize the following step in my workflow but I couldn’t find a solution in the documentation, so I am not even sure that’s something GMT can do.

I am currently using a Qgis plugin (QChainage) to sample my cross-section trace (shapefile) at a specified distance including the end point; i.e. I get a point object every 5km along the line and I force the algorithm to include the ending coordinates of the trace even if it’s not at a multiple of 5 km from the starting point. Then I export long/lat of the points to a .csv and feed it to my GMT script to sample several .grd files and plot the cross-section.

Can you point me to the right module(s) for this purpose or tell me if it’s just something currently unfeasible with GMT?

For readers interested in how I plot cross sections with GMT (click here)

Sample the z from several xyz.grd files at the coordinates in the .csv using grdtrack, then use mapproject to get incremental distances between points and finally plot the results on a cartesian graph to obtain the cross section.

In case you need to substitute commas in the .csv with white spaces:

cat csv-file | sed -e ‘s/,/ /g’ > coordinates-file

Thanks for that example but at a first glance I’d say no.
I actually need to sample at equidistant points a .gmt file that contains a single line (which may have several vertices) and to include the very last vertex in order to preserve the total lenght of my section.
Am I misunderstanding example 33? I didn’t get my solution in there…still looking the documentation to understand it better anyway.

edit:
what I call cross sections is not 90° from section trace, I may have used the wrong term.
I have 7 .grd files of the same area at different depths underground, which I need to sample at the same coordinates and I already have a script to plot my sections which is working just fine!
Example 33 plots cross profiles along a line, which is awesome, but it’s not what I need. I’m trying to obtain long and lat from a .shp file which I converted to .gmt in order to sample my 7 .grd files at the same location. I upload an example of section, where the black line is the topography and each of the colored lines refers to z values on my .grd files.

Thank you very much @Esteban82 !!!
I could have done it also with grdtrack parsing the output to get only long and lat (column 1 and 2) where column 3 was equal to zero but that would have slowed down operations a lot…

Solved with:

gmt sample1d line.gmt -T5k -AR

edit: Note that -AR adjust the spacing to fit exactly the line lenght, to instead use the exact spacing indicated by -T use -Ar

sample1d used to have an option to deal with the end points (-S in gmt5) but I don’t find that facility anymore. Anyway since options even after deprecation remain active you should still be able to use that -S in GMT6

The syntax should be -S0/total_dist. This assuming that your first column has the accumulated distance along the track and that first value is zero and last = total_dist

The old -S is deprecated but same effect is obtained via -T:

-Sstart[/stop] option is deprecated; use -Ttmin/tmax/tinc[+a|n] instead

If I udnerstand you correctly, you want to sample your input track every 5 km, plus output any final coordinate that did not fit into the 5-km stepping. So -Ar will do the first part but not the 2nd part, and -AR violates your 5 km spacing. Seems we would need a 3rd flavor of the -Ar|R schemes.

Yes you understood it correctly and it would be totally Awesome to have that option and useful as well! Just like -Ar but with the final coordinate pair appended to the list and maybe and [INFORMATION] message with the distance from the previous sample.

I can’t compute incremental distances without the equidistant sampling, can I?
Well, of course I could calculate the array measuring the total lenght of the trace and then dividing it by my desired spacing to get the number of rows needed…but then I still need to sample my coordinates adding the final one…I can’t really figure out what you meant there…

I can adjust my 5km rule anyway, this alone brings me out of GUI softwares! gmt sample1d saved me likely a thousand clicks today and who knows how many in the following years! In the end it is just sampling grids to get points to plot the frame for a stratigraphic section, so if the algorithm lowers the sampling rate to fit my lenght that’s not causing any problem at all to my research, anyway it is sampling an interpolated surface, real data is well more spaced than 5 km. It would be different if the spacing was really a strict requirement to the job, e.g. if someone was planning the placement of geophones or GCPs on a trace or systematic sampling on a route at sea. Then the new option proposed above could definitely come in very handy!

I struggled with what I think is a similar problem just last week (but did not find sample1d… ). In my case, I need to divide an upper and lower fault trace in to an equal number of segments of approximately 5 km (e.g.), retaining both end points but not caring about intermediate vertices. So if one trace is 26 km long and the other is 24 km, the first will be divided into 5 segments of 5.2 km and the second will be divided into 5 segments of 4.8 km, 6 points on both.

I figured out how to do it with gmt plot -SqD...+t (see figure below) and can now get very similar results using gmt sample1d -AR -Fl -T${step}k -fg (red Xs in the figure). I haven’t had time to investigate what might be causing the differences yet, and, at least for now, they are close enough for my needs. Both methods seem to stray from the specified step length around the vertex in the middle, and the total length differs in the end. I definitely do not yet understand the nuances of -j options and spherical vs. ellipsoidal calculations.

If you want to see a version of the script I'm using, click here.

@jaltekruse I’m glad this post has already been useful to someone! That’s an interesting application but I don’t get the difference between the two methods from the figure alone…maybe the linear interpolation you apply with -Fl is causing small differences only noticeable comparing numbers, I’d try using -Fn or just without the -F option if you haven’t yet!

Also make sure that the faults lenghts are exactly multiples of their relative spacing if you need it to be be maintained by -AR because:

@Esteban82 your blog is awesome! Thank you for the link, I’ll definitely learn a lot from it!
I made a similar script but I just set the y axis and calculate the x axis dimension to get my desired vertical exageration instead of setting the dimension of the figure to then calculate the v.e., that’s useful if you have to compare different sections from the same study (which is actually my case).