What is the quickest way to do a coordinate transformation in gmt 6

Hello! I often deal with point coordinates and wish I had a calculator that would quickly take me from EPSG:4230 to EPSG:4258 in 5 seconds. Is there a way to achieve such conversion from the terminal in one line? I’m reading the documentation on mapproject but there aren’t any conversion examples. Grass GIS has m.proj [coordinate] [proj_in] [proj_out] I’m sure GMT has something equivalent? Thanks in advance!

What units are your data in?

I think that you might be interested in the mapproject -T option? I tried to work out how to do it, but got stuck working out how to specify the datums. One thing to note is the EPSG:4258 uses the GRS-80 ellipsoid, whereas EPSG:4230 uses WGS-84. PROJ_ELLIPSOID (set using gmtset) is your friend here - I think.

I would just make a function which takes input coordinates (and optionally EPSG to/from) and use gdaltransform.

E.g.

echo 34.5 76.5 | gdaltransform -s_srs EPSG:4230 -t_srs EPSG:4258

Hi Tim - EPSG:4230 is essentially the old european datum (ED50). It used the Intl24 ellipsoid, which is basically Hayford 1909, it predates both GRS80 and WGS84. I often have coordinates from old reports that use that datum and it would be cool to just convert on the fly (from the terminal) rather than load into a GIS software. Coordinates can be in Decimal Degrees, DMS it could be anything.

Hi Andreas, unfortunately that returns nothing, not even an error. I tried prephasing with gmt and then says “no module named gdaltransform was found”. I’m running gmt 6 if that helps

On Windows you have a gdaltransform.exe but on *nix you need GDAL utilities installed as well. Anyway, no need here

echo 34.5 76.5 | gdaltransform -s_srs EPSG:4230 -t_srs EPSG:4258
34.4990350686626 76.5004446574769 0

echo 34.5 76.5 | mapproject -JEPSG:4230+toEPSG:4258
34.4990350687   76.5004446575

Hi Joaquim and thanks for the reply! Second method (mapproject) works fine, I’ll be using that! You’ve resolved my question, but curious why the first method, gdaltransform doesn’t return anything. I am currently running gmt6 on windows using GIT with Bash. Is gdaltransform.exe part of the regular install or is it additional?

What GMT version?

In GMT6.1.1 and GMT6.1.0 (I think), all GDAL executables are shipped in the installer, so you should have a gdaltranslate.exe in your GMT6/bin directory.

GMT 6.1.1 and I confirm that gdaltranslate.exe is in my GMT6 bin. Bizzare!

myname@LAPTOP-2HIQP1UT MINGW64 /c
$ echo 34.5 76.5 | gdaltransform -s_srs EPSG:4230 -t_srs EPSG:4258

myname@LAPTOP-2HIQP1UT MINGW64 /c
$ echo 3 50 | mapproject -JEPSG:4258+toEPSG:4230
3.00128973945 50.0008728489

Same if you run the gdaltrasform from a pure cmd window?

Wow, works from cmd, no issues

Sorry @RunningWild, gdaltransform is part of gdal, not GMT.

Anyway, if you do this command often, consider putting something like

coordtrans() {
echo ${1} ${2} | mapproject -JEPSG:4230+toEPSG:4258
}

in your .bashrc (or whatever git with bash is using). Then you simply have to do:

$ coordtrans 34.5 76.5
34.4987921573	76.5004822999

Strange. It works for me with the GIT bash too.