Plot -A and output

If I have a file with coordinates, I can plot it with gmt plot -Ap [..] to have it plot following a parallel, then a meridian (plot docs).

  • I would like to use this plot-processed data for further use; are there any tools in gmt that can create the output what plot -Ap plots…?

E.g. How can I get the coordinates of the red lines from the figure created with the script below?

cat<<eof > test1.gmt
>
376056 7911283
404413 7927573
441218 7924556
461128 7889562
359766 7911283
376056 7911283
eof

# convert to lat long
gmt mapproject -F -C -I -Ju+32/1:1 test1.gmt > test.gmt

gmt begin blocky-line
  gmt plot test.gmt -Ap -Wthick,red -l"blocky (-Ap)"+jTL
  gmt plot -B0 test.gmt -l"original"
gmt end show

rm test1.gmt test.gmt gmt.history

Using grdtrack -Ap ?

Interesting. Will test.

If the “grd” part is not ideal I think you can use the -E option as a workaround to just input start/stop coordinates. Which would, I guess, fit your purpose

Should work with sample1d -Ap -Isomemapincrement.

Since I don’t have any grids, I’m not sure if grdtrack is the right tool.

pwessel: sample1d looks like the thing, but I’m immediately bitten by the requirement to have a monotonically increasing or decreasing variable. So the yak shaving starts. Any golden tips on how to resample points that are arbitrarily sampled so I can use it with sample1d?

I think those terms only refers to time series. You are resampling an (lon,lat) line and the (guaranteed) monotonically increasing variable is the distance.

So this should work?

cat<<eof | gmt sample1d -Ap
5.53962564298   71.272033721
6.30984353357   71.4308039355
7.34727069584   71.4156247566
7.9243956509    71.1059801628
5.08609083753   71.2631386067
5.53962564298   71.272033721
eof
sample1d [ERROR]: x-values are not monotonically increasing/decreasing (at zero-based record 4)!
sample1d [ERROR]: Failure in gmt_intpol near row 5!

No, you need to use -I to give a sampling interval with a map distance unit, e.g. -I10k, to turn on spatial 2-D series resampling. Otherwise it is just a 1-D time series resampling.

1 Like

I see. Thank you paul.

Seems to work nicely!

Two things:

  • I got really confused since sample1d docs does not mention -I as an option.
  • Is there an easy way of ‘snapping’ (rounding down/up) the resampled coordinates to the nearest specified increment? E.g. snap to the nearest 15 arcseconds.

Sorry, I get confused with our own deprecation rate at times. The -I was replaced with -T since we use -T for any 1-D array creation (gmt math, makecpt etc).

As for snapping: Probably not, but please give a short example of what you get and what you would like to get.

Thanks again Paul. And sorry; I’m the one who should’ve studied the man page closer…

I’ll create an example of what I mean.

And… some other thing that turned up (and I’m confused)

  • gmt plot -Ap [..] gives the same result as sample1d -Am [..]

  • gmt plot -Am [..] gives the same result as sample1d -Ap [..]

  • -Am for both (plot and sample1d): follow meridian (along y) then parallel (along x)

  • -Ap for both: […] first follow parallel (along y) then meridian

Should not -Ap and -Am do the same in these cases? Maybe these got flipped somehow.

Example of this (recycling code from first post):

cat<<eof > test1.gmt
>
376056 7911283
404413 7927573
441218 7924556
461128 7889562
359766 7911283
376056 7911283
eof

# convert to lat long
gmt mapproject -F -C -I -Ju+32/1:1 test1.gmt > test.gmt

gmt begin blocky-line
  gmt plot test.gmt -Ap -Wthick,red -l"plot -Ap"+jTL
  gmt plot test.gmt -l"original"
  gmt sample1d -T10k -Am test.gmt | gmt plot -B0 -l"sample1d -Am" -Wblue
gmt end show

rm test1.gmt test.gmt gmt.history