Calculate distances from table with XY data?

With gmt mapproject file -G+a I can calculate the accumulated distance from a file with long and lat data.

How can I do the same if my file has XY data (in UTM)?
Is it possible to do it with mapproject? Should I use gmt math?

Here is a small script:

cat > utm.txt <<- END
467463.700000 4212342.200000 -236.325
467451.100000 4212363.590000 -236.25
END

cat > geo.txt <<- END
-63.4764771668 -52.2383691325 -236.325
-63.4766596202 -52.2381760854 -236.25
END

gmt mapproject geo.txt -G+a
gmt mapproject utm.txt -G+a

Output:

-63.4764771668  -52.2383691325  -236.325        0
-63.4766596202  -52.2381760854  -236.25 24.840041207
mapproject [ERROR]: Bad latitude outside valid range at input line 1 - skipped
mapproject [ERROR]: Bad latitude outside valid range at input line 2 - skipped

Does it help adding -fc ? Also, do you want Cartesian distances in meters?

Nop, nothing. It seems that mapproject only works with long and lat because I even try -fc for the geographic table.

gmt mapproject geo.txt -G+a -fc
-63.4764771668  -52.2383691325  -236.325        0
-63.4766596202  -52.2381760854  -236.25 24.840041207

Yes, meters would be great.

Well, assuming your input is meters that is what a Cartesian calculation will do since it knows nothing of units.

Did -fc do anything?

Nop, nothing. I run gmt mapproject utm.txt -G+a -fc -Vd

And I got:

gmt [DEBUG]: GMT_Create_Session: Terminal width = 135
gmt [DEBUG]: Obtained the ppid from parent: 92977
gmt [DEBUG]: Enter: gmtinit_new_GMT_ctrl
gmt [DEBUG]: GMT->session.SHAREDIR = /usr/local/share
gmt [DEBUG]: GMT->session.HOMEDIR = /home/thor
gmt [DEBUG]: GMT->session.USERDIR = /home/thor/.gmt [created]
gmt [DEBUG]: GMT->session.CACHEDIR = /home/thor/.gmt/cache [created]
gmt [DEBUG]: GMT: 0. Will try to find subdir=postscriptlight stem = PSL_custom_fonts suffix=.txt
gmt [DEBUG]: GMT: 1. gmt_getsharepath trying current dir
gmt [DEBUG]: GMT: 2. gmt_getsharepath trying USERDIR /home/thor/.gmt
gmt [DEBUG]: GMT: 3. gmt_getsharepath trying USERDIR subdir /home/thor/.gmt/postscriptlight
gmt [DEBUG]: GMT: 4. gmt_getsharepath trying SHAREDIR subdir /usr/local/share/postscriptlight
gmt [DEBUG]: GMT: 5. gmt_getsharepath trying SHAREDIR /usr/local/share
gmt [DEBUG]: GMT: 6. gmt_getsharepath failed
gmt [DEBUG]: Map distance calculation will be Cartesian
gmt [DEBUG]: Exit:  gmtinit_new_GMT_ctrl
gmt [DEBUG]: Enter: New_PSL_Ctrl
gmt [DEBUG]: Exit:  New_PSL_Ctrl
gmt [DEBUG]: Enter: gmt_manage_workflow
gmt [DEBUG]: Exit : gmt_manage_workflow
gmt [DEBUG]: Enter: PSL_beginsession
gmt [DEBUG]: Exit : PSL_beginsession
gmt [DEBUG]: Enter: PSL_setdefaults
gmt [DEBUG]: Exit : PSL_setdefaults
gmt [DEBUG]: Enter: gmtlib_io_init
gmt [DEBUG]: Exit : gmtlib_io_init
gmt [DEBUG]: Enter: gmt_hash_init
gmt [DEBUG]: Exit:  gmt_hash_init
gmt [DEBUG]: Enter: gmt_hash_init
gmt [DEBUG]: Exit:  gmt_hash_init
gmt [DEBUG]: Enter: gmt_reload_settings
gmt [DEBUG]: The PROJ_GEODESIC set to Vincenty
gmt [DEBUG]: Look for file /home/thor/gmt.conf
gmt [DEBUG]: Look for file /home/thor/.gmt/gmt.conf
gmt [DEBUG]: Look for file /home/thor/.gmt/server/gmt.conf
gmt [DEBUG]: Look for file /home/thor/.gmt/cache/gmt.conf
gmt [DEBUG]: Could not find file gmt.conf
gmt [DEBUG]: Exit:  gmt_reload_settings
gmt [DEBUG]: Enter: gmtlib_plot_C_format
gmt [DEBUG]: Exit:  gmtlib_plot_C_format
gmt [DEBUG]: Enter: gmtinit_get_history
gmt [DEBUG]: Initialize FFTW with 8 threads.
gmt [DEBUG]: GMT_Create_Session initialized GMT structure
gmt [DEBUG]: Loading core GMT shared library: libgmt.so
gmt [DEBUG]: Shared Library # 0 (core). Path = libgmt.so
gmt [DEBUG]: Loading GMT plugins from: /usr/local/lib/gmt/plugins
gmt [DEBUG]: Shared Library # 1 (supplements). Path = /usr/local/lib/gmt/plugins/supplements.so
gmt [DEBUG]: Revised options: utm.txt -G+a -fc -Vd
mapproject [DEBUG]: Found readable file utm.txt
mapproject [DEBUG]: Replace file utm.txt with path utm.txt
mapproject [DEBUG]: Replace file utm.txt with utm.txt
mapproject [DEBUG]: Map distance calculation will be using great circle approximation with authalic auxiliary latitudes and authalic (R_2) radius = 6371007.1809 m, in meter.
mapproject [INFORMATION]: Processing input table data
mapproject [DEBUG]: Map distance calculation will be using great circle approximation with authalic auxiliary latitudes and authalic (R_2) radius = 6371007.1809 m, in meter.
mapproject [DEBUG]: Reset MAP_ANNOT_OBLIQUE to anywhere
mapproject [DEBUG]: Projected values in meters: -180 180 -90 90
mapproject [INFORMATION]: Override -fog for normal operation
mapproject [DEBUG]: gmtapi_init_import: Passed family = Data Table and geometry = Point
mapproject [DEBUG]: Found readable file utm.txt
mapproject [DEBUG]: Replace file utm.txt with path utm.txt
mapproject [DEBUG]: Found readable file utm.txt
mapproject [DEBUG]: Object ID 0 : Registered Data Table File utm.txt as an Input resource with geometry Point [n_objects = 1]
mapproject [DEBUG]: gmtapi_init_import: Added 1 new sources
mapproject [DEBUG]: GMT_Init_IO: Returned first Input object ID = 0
mapproject [DEBUG]: GMT_Begin_IO: Mode value 1 not considered (ignored)
mapproject [DEBUG]: GMT_Begin_IO: Initialize record-by-record access for Input
mapproject [DEBUG]: gmtapi_next_io_source: Selected object 0
mapproject [DEBUG]: Found readable file utm.txt
mapproject [DEBUG]: Replace file utm.txt with path utm.txt
mapproject [DEBUG]: Found readable file utm.txt
mapproject [DEBUG]: Calling nc_open on utm.txt, ncid = 0, err = -51
mapproject [DEBUG]: Found readable file utm.txt
mapproject [INFORMATION]: Reading Data Table from file utm.txt
mapproject [DEBUG]: GMT_Begin_IO: Input resource access is now enabled [record-by-record]
mapproject [DEBUG]: gmtapi_init_export: Passed family = Data Table and geometry = Point
mapproject [DEBUG]: Object ID 1 : Registered Data Table Stream 7f37635f7780 as an Output resource with geometry Point [n_objects = 2]
mapproject [DEBUG]: gmtapi_init_export: Added stdout to registered destinations
mapproject [DEBUG]: GMT_Init_IO: Returned first Output object ID = 1
mapproject [DEBUG]: GMT_Begin_IO: Mode value 1 not considered (ignored)
mapproject [DEBUG]: GMT_Begin_IO: Initialize record-by-record access for Output
mapproject [DEBUG]: gmtapi_next_io_source: Selected object 1
mapproject [INFORMATION]: Writing Data Table to Standard Output stream
mapproject [DEBUG]: GMT_Begin_IO: Output resource access is now enabled [record-by-record]
mapproject [DEBUG]: Source col types: (Number,Number,Number)
mapproject [DEBUG]: ASCII source scanned: Numerical columns: 3, Trailing text: N, Record type: Numerical only
mapproject [ERROR]: Bad latitude outside valid range at input line 1 - skipped
mapproject [ERROR]: Bad latitude outside valid range at input line 2 - skipped
mapproject [DEBUG]: GMT_End_IO: Input resource access is now disabled
mapproject [DEBUG]: GMT_End_IO: Output resource access is now disabled
mapproject [DEBUG]: gmtlib_unregister_io: Unregistering object no 0 [n_objects = 1]
mapproject [DEBUG]: gmtlib_unregister_io: Unregistering object no 1 [n_objects = 0]
gmt [DEBUG]: Entering GMT_Destroy_Session

try also adding -fp or -fpm? just a check.

No. The same output.

gmt mapproject utm.txt -G+a+uc

Think your only option is to invert the coordinates back to degrees and then do -G on that.

That’s what I did. But I have the original data in UTM and then I process it with x2sys (which I understand is better to use flat coordinates). So the ideal would be always to work with UTM,

I think you forgot to add +uc:

gmt mapproject utm.txt -G+a+uc
467463.7 4212342.2 -236.325 0
467451.1 4212363.59 -236.25 24.8252311165

See -G docs on +u.